~egtann/lanhttp

d302634e5095f1c3c4af6d6960fdfa032e1263a7 — Evan Tann 1 year, 2 months ago cee9e04
add diff test, remove unneeded check
2 files changed, 70 insertions(+), 8 deletions(-)

M lanhttp.go
A lanhttp_test.go
M lanhttp.go => lanhttp.go +0 -8
@@ 255,13 255,5 @@ func diff(a, b Routes) bool {
			}
		}
	}

	// We also need to check that there are no keys in b which don't exist
	// in a, which aren't checked in the range loop above
	for key := range b {
		if _, ok := a[key]; !ok {
			return true
		}
	}
	return false
}

A lanhttp_test.go => lanhttp_test.go +70 -0
@@ 0,0 1,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)
			}
		})
	}
}