1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
package runtime
import (
"sort"
"testing"
)
func TestWithIncomingHeaderMatcher_matchedMalformedHeaders(t *testing.T) {
tests := []struct {
name string
matcher HeaderMatcherFunc
want []string
}{
{
"nil matcher returns nothing",
nil,
nil,
},
{
"default matcher returns nothing",
DefaultHeaderMatcher,
nil,
},
{
"passthrough matcher returns all malformed headers",
func(s string) (string, bool) {
return s, true
},
[]string{"connection"},
},
}
sliceEqual := func(a, b []string) bool {
if len(a) != len(b) {
return false
}
sort.Slice(a, func(i, j int) bool {
return a[i] < a[j]
})
sort.Slice(b, func(i, j int) bool {
return a[i] < a[j]
})
for idx := range a {
if a[idx] != b[idx] {
return false
}
}
return true
}
for _, tt := range tests {
out := tt.matcher.matchedMalformedHeaders()
if !sliceEqual(tt.want, out) {
t.Errorf("matchedMalformedHeaders not match; Want %v; got %v",
tt.want, out)
}
}
}
|