MCPcopy
hub / github.com/willnorris/imageproxy / TestCopyHeader

Function TestCopyHeader

imageproxy_test.go:47–93  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

45}
46
47func TestCopyHeader(t *testing.T) {
48 tests := []struct {
49 dst, src http.Header
50 keys []string
51 want http.Header
52 }{
53 // empty
54 {http.Header{}, http.Header{}, nil, http.Header{}},
55 {http.Header{}, http.Header{}, []string{}, http.Header{}},
56 {http.Header{}, http.Header{}, []string{"A"}, http.Header{}},
57
58 // nothing to copy
59 {
60 dst: http.Header{"A": []string{"a1"}},
61 src: http.Header{},
62 keys: nil,
63 want: http.Header{"A": []string{"a1"}},
64 },
65 {
66 dst: http.Header{},
67 src: http.Header{"A": []string{"a"}},
68 keys: []string{"B"},
69 want: http.Header{},
70 },
71
72 // copy headers
73 {
74 dst: http.Header{"A": []string{"a"}},
75 src: http.Header{"B": []string{"b"}, "C": []string{"c"}},
76 keys: []string{"B"},
77 want: http.Header{"A": []string{"a"}, "B": []string{"b"}},
78 },
79 }
80
81 for _, tt := range tests {
82 // copy dst map
83 got := make(http.Header)
84 for k, v := range tt.dst {
85 got[k] = v
86 }
87
88 copyHeader(got, tt.src, tt.keys...)
89 if !reflect.DeepEqual(got, tt.want) {
90 t.Errorf("copyHeader(%v, %v, %v) returned %v, want %v", tt.dst, tt.src, tt.keys, got, tt.want)
91 }
92 }
93}
94
95func TestAllowed(t *testing.T) {
96 allowHosts := []string{"good"}

Callers

nothing calls this directly

Calls 1

copyHeaderFunction · 0.85

Tested by

no test coverage detected