File: mux_internal_test.go

package info (click to toggle)
golang-github-grpc-ecosystem-grpc-gateway.v2 2.11.3-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 6,148 kB
  • sloc: javascript: 352; makefile: 136; sh: 26
file content (58 lines) | stat: -rw-r--r-- 1,015 bytes parent folder | download | duplicates (2)
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)
		}
	}
}