(t *testing.T)
| 57 | } |
| 58 | |
| 59 | func 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 | |
| 102 | func TestIndexSectionMultipleResourcesPerURL(t *testing.T) { |
| 103 | url := urlMustParse("https://example.com/") |
nothing calls this directly
no test coverage detected