~egtann/lanhttp

ref: d302634e5095f1c3c4af6d6960fdfa032e1263a7 lanhttp/lanhttp_test.go -rw-r--r-- 1.7 KiB
d302634e — Evan Tann add diff test, remove unneeded check 1 year, 9 months ago
                                                                                
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
59
60
61
62
63
64
65
66
67
68
69
70
package lanhttp

import "testing"

func TestDiff(t *testing.T) {
	t.Parallel()

	type testcase struct {
		haveA map[string][]string
		haveB map[string][]string
		want  bool
	}
	tcs := map[string]testcase{
		"same empty": testcase{
			haveA: map[string][]string{},
			haveB: map[string][]string{},
			want:  false,
		},
		"same content": testcase{
			haveA: map[string][]string{"a": []string{"a"}},
			haveB: map[string][]string{"a": []string{"a"}},
			want:  false,
		},
		"sort": testcase{
			haveA: map[string][]string{"a": []string{"a", "b"}},
			haveB: map[string][]string{"a": []string{"b", "a"}},
			want:  false,
		},
		"a > b": testcase{
			haveA: map[string][]string{"a": []string{"a"}},
			haveB: map[string][]string{},
			want:  true,
		},
		"b > a": testcase{
			haveA: map[string][]string{},
			haveB: map[string][]string{"a": []string{"a"}},
			want:  true,
		},
		"a > b ips": testcase{
			haveA: map[string][]string{"a": []string{"a", "b", "c"}},
			haveB: map[string][]string{"a": []string{"a", "c"}},
			want:  true,
		},
		"b > a ips": testcase{
			haveA: map[string][]string{"a": []string{"a"}},
			haveB: map[string][]string{"a": []string{"a", "b"}},
			want:  true,
		},
		"a != b": testcase{
			haveA: map[string][]string{"a": []string{"a"}},
			haveB: map[string][]string{"b": []string{"a"}},
			want:  true,
		},
		"a != b ips": testcase{
			haveA: map[string][]string{"a": []string{"a"}},
			haveB: map[string][]string{"a": []string{"b"}},
			want:  true,
		},
	}
	for name, tc := range tcs {
		tc := tc // capture reference
		t.Run(name, func(t *testing.T) {
			t.Parallel()

			if diff(tc.haveA, tc.haveB) != tc.want {
				t.Fatal(name, tc.haveA, tc.haveB)
			}
		})
	}
}