MCPcopy
hub / github.com/caddyserver/caddy / TestParseLinkHeader

Function TestParseLinkHeader

modules/caddyhttp/push/link_test.go:21–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestParseLinkHeader(t *testing.T) {
22 testCases := []struct {
23 header string
24 expectedResources []linkResource
25 }{
26 {
27 header: "</resource>; as=script",
28 expectedResources: []linkResource{{uri: "/resource", params: map[string]string{"as": "script"}}},
29 },
30 {
31 header: "</resource>",
32 expectedResources: []linkResource{{uri: "/resource", params: map[string]string{}}},
33 },
34 {
35 header: "</resource>; nopush",
36 expectedResources: []linkResource{{uri: "/resource", params: map[string]string{"nopush": "nopush"}}},
37 },
38 {
39 header: "</resource>;nopush;rel=next",
40 expectedResources: []linkResource{{uri: "/resource", params: map[string]string{"nopush": "nopush", "rel": "next"}}},
41 },
42 {
43 header: "</resource>;nopush;rel=next,</resource2>;nopush",
44 expectedResources: []linkResource{
45 {uri: "/resource", params: map[string]string{"nopush": "nopush", "rel": "next"}},
46 {uri: "/resource2", params: map[string]string{"nopush": "nopush"}},
47 },
48 },
49 {
50 header: "</resource>,</resource2>",
51 expectedResources: []linkResource{
52 {uri: "/resource", params: map[string]string{}},
53 {uri: "/resource2", params: map[string]string{}},
54 },
55 },
56 {
57 header: "malformed",
58 expectedResources: []linkResource{},
59 },
60 {
61 header: "<malformed",
62 expectedResources: []linkResource{},
63 },
64 {
65 header: ",",
66 expectedResources: []linkResource{},
67 },
68 {
69 header: ";",
70 expectedResources: []linkResource{},
71 },
72 {
73 header: "</resource> ; ",
74 expectedResources: []linkResource{{uri: "/resource", params: map[string]string{}}},
75 },
76 }
77
78 for i, test := range testCases {

Callers

nothing calls this directly

Calls 1

parseLinkHeaderFunction · 0.85

Tested by

no test coverage detected