tobogganSe connecter

packages

The Louise packages, each released on its own

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

63 lignes · 1967 octetsBrut · Historique
1import assets
2import requests.{header, text}
3import std/http.{type Response}
4import std/string
5import std/test.{assert, assert_equal}
6
7fn served :: segments: List<String> -> Response / <io>
8{
9 assets.serve "test/static" vendored segments
10}
11
12fn vendored :: segments: List<String> -> String
13{
14 match segments { ["vendor", ..] -> "public, max-age=86400", _ -> "no-cache" }
15}
16
17@test
18fn a_stylesheet_is_served_with_its_type :: -> () / <io>
19{
20 let resp = served ["app.css"]
21 assert_equal resp.status 200
22 assert_equal (header resp "Content-Type") "text/css; charset=utf-8"
23 assert (string.contains (text resp) ":root") "the stylesheet"
24}
25
26@test
27fn the_caching_rule_is_the_callers :: -> () / <io>
28{
29 let resp = served ["vendor", "lib.js"]
30 assert_equal resp.status 200
31 assert_equal (header resp "Content-Type") "text/javascript; charset=utf-8"
32 assert_equal (header resp "Cache-Control") "public, max-age=86400"
33 assert_equal (header (served ["app.css"]) "Cache-Control") "no-cache"
34}
35
36@test
37fn a_missing_file_is_not_found :: -> () / <io>
38{
39 assert_equal ((served ["nope.css"]).status) 404
40}
41
42@test
43fn paths_cannot_leave_the_root :: -> () / <io>
44{
45 assert_equal ((served ["..", "assets_test.lse"]).status) 404
46 assert_equal ((served ["vendor", "..", "..", "assets_test.lse"]).status) 404
47 assert_equal ((served ["../assets_test.lse"]).status) 404
48 assert_equal ((served [".hidden"]).status) 404
49 assert_equal ((served []).status) 404
50}
51
52@test
53fn images_manifests_and_json_are_served_with_their_types :: -> () / <io>
54{
55 let typed = fn file { header (served [file]) "Content-Type" }
56 assert_equal (typed "avatar.webp") "image/webp"
57 assert_equal (typed "photo.jpg") "image/jpeg"
58 assert_equal (typed "photo.jpeg") "image/jpeg"
59 assert_equal (typed "photo.avif") "image/avif"
60 assert_equal (typed "moving.gif") "image/gif"
61 assert_equal (typed "manifest.webmanifest") "application/manifest+json"
62 assert_equal (typed "data.json") "application/json"
63}