MCPcopy
hub / github.com/TecharoHQ/anubis / TestHTTPHeaders

Function TestHTTPHeaders

lib/policy/expressions/http_headers_test.go:10–52  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestHTTPHeaders(t *testing.T) {
11 headers := HTTPHeaders{
12 Header: http.Header{
13 "Content-Type": {"application/json"},
14 "Cf-Worker": {"true"},
15 "User-Agent": {"Go-http-client/2"},
16 },
17 }
18
19 t.Run("contains-existing-header", func(t *testing.T) {
20 resp := headers.Contains(types.String("User-Agent"))
21 if !resp.(types.Bool) {
22 t.Fatal("headers does not contain User-Agent")
23 }
24 })
25
26 t.Run("not-contains-missing-header", func(t *testing.T) {
27 resp := headers.Contains(types.String("Xxx-Random-Header"))
28 if resp.(types.Bool) {
29 t.Fatal("headers does not contain User-Agent")
30 }
31 })
32
33 t.Run("get-existing-header", func(t *testing.T) {
34 val := headers.Get(types.String("User-Agent"))
35 switch val.(type) {
36 case types.String:
37 // ok
38 default:
39 t.Fatalf("result was wrong type %T", val)
40 }
41 })
42
43 t.Run("not-get-missing-header", func(t *testing.T) {
44 val := headers.Get(types.String("Xxx-Random-Header"))
45 switch val.(type) {
46 case *types.Err:
47 // ok
48 default:
49 t.Fatalf("result was wrong type %T", val)
50 }
51 })
52}

Callers

nothing calls this directly

Calls 3

ContainsMethod · 0.95
GetMethod · 0.95
StringMethod · 0.45

Tested by

no test coverage detected