netcheck: use reflect in sortRegions test.

Signed-off-by: Denton Gentry <dgentry@tailscale.com>
This commit is contained in:
Denton Gentry 2021-01-12 04:15:43 -08:00 committed by Denton Gentry
parent 43e060b0e5
commit ac42757cd7

View File

@ -603,14 +603,16 @@ func TestSortRegions(t *testing.T) {
report.RegionLatency[3] = time.Second * time.Duration(6)
report.RegionLatency[4] = time.Second * time.Duration(0)
report.RegionLatency[5] = time.Second * time.Duration(2)
got := sortRegions(unsortedMap, report)
sortedMap := sortRegions(unsortedMap, report)
// Sorting by latency this should result in rid: 5, 2, 1, 3
// rid 4 with latency 0 should be at the end
expected := []int{5, 2, 1, 3, 4}
for idx, want := range expected {
if got[idx].RegionID != want {
t.Errorf("idx:%v got:%v want:%v\n", idx, got[idx].RegionID, want)
}
want := []int{5, 2, 1, 3, 4}
got := make([]int, len(sortedMap))
for i, r := range sortedMap {
got[i] = r.RegionID
}
if !reflect.DeepEqual(got, want) {
t.Errorf("got %v; want %v", got, want)
}
}