MCPcopy Create free account
hub / github.com/WICG/webpackage / TestIndexSectionWithVariants

Function TestIndexSectionWithVariants

go/bundle/encoder_test.go:59–100  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

57}
58
59func TestIndexSectionWithVariants(t *testing.T) {
60 url := urlMustParse("https://example.com/")
61 variants := []string{"Accept-Encoding;gzip;br, Accept-Language;en;fr"}
62 is := &indexSection{}
63 is.addExchange(
64 &Exchange{
65 Request{URL: url},
66 Response{Header: http.Header{
67 "Variants": variants,
68 "Variant-Key": []string{"gzip;fr, br;en"},
69 }},
70 }, 20, 2)
71 is.addExchange(
72 &Exchange{
73 Request{URL: url},
74 Response{Header: http.Header{
75 "Variants": variants,
76 "Variant-Key": []string{"gzip;en"},
77 }},
78 }, 10, 1)
79 is.addExchange(
80 &Exchange{
81 Request{URL: url},
82 Response{Header: http.Header{
83 "Variants": variants,
84 "Variant-Key": []string{"br;fr"},
85 }},
86 }, 30, 3)
87 if err := is.Finalize(version.VersionB1); err != nil {
88 t.Fatal(err)
89 }
90
91 want := `map["https://example.com/":["Accept-Encoding;gzip;br, Accept-Language;en;fr" 10 1 20 2 20 2 30 3]]`
92
93 got, err := testhelper.CborBinaryToReadableString(is.bytes)
94 if err != nil {
95 t.Fatal(err)
96 }
97 if got != want {
98 t.Errorf("got: %s\nwant: %s", got, want)
99 }
100}
101
102func TestIndexSectionMultipleResourcesPerURL(t *testing.T) {
103 url := urlMustParse("https://example.com/")

Callers

nothing calls this directly

Calls 4

addExchangeMethod · 0.95
FinalizeMethod · 0.95
urlMustParseFunction · 0.70

Tested by

no test coverage detected