MCPcopy Create free account
hub / github.com/prometheus/common / TestServeHttp

Function TestServeHttp

server/static_file_server_test.go:28–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26}
27
28func TestServeHttp(t *testing.T) {
29 cases := []struct {
30 name string
31 path string
32 contentType string
33 }{
34 {
35 name: "normal file",
36 path: "index.html",
37 contentType: "",
38 },
39 {
40 name: "javascript",
41 path: "test.js",
42 contentType: "application/javascript",
43 },
44 {
45 name: "css",
46 path: "test.css",
47 contentType: "text/css",
48 },
49 {
50 name: "png",
51 path: "test.png",
52 contentType: "image/png",
53 },
54 {
55 name: "jpg",
56 path: "test.jpg",
57 contentType: "image/jpeg",
58 },
59 {
60 name: "gif",
61 path: "test.gif",
62 contentType: "image/gif",
63 },
64 }
65
66 for _, c := range cases {
67 t.Run(c.name, func(t *testing.T) {
68 rr := httptest.NewRecorder()
69 req, err := http.NewRequest("GET", "http://localhost/"+c.path, nil)
70 if err != nil {
71 t.Fatal(err)
72 }
73
74 s := StaticFileServer(dummyFileSystem{})
75 s.ServeHTTP(rr, req)
76
77 if rr.Header().Get("Content-Type") != c.contentType {
78 t.Fatalf("Unexpected Content-Type: %s", rr.Header().Get("Content-Type"))
79 }
80 })
81 }
82}

Callers

nothing calls this directly

Calls 3

StaticFileServerFunction · 0.85
ServeHTTPMethod · 0.80
GetMethod · 0.80

Tested by

no test coverage detected