(t *testing.T)
| 46 | } |
| 47 | |
| 48 | func TestNodeIDsUnmarshalJSON(t *testing.T) { |
| 49 | cmpNodeIDs := func(a, b NodeIDs) bool { |
| 50 | if len(a) != len(b) { |
| 51 | return false |
| 52 | } |
| 53 | for i, id := range a { |
| 54 | if id != b[i] { |
| 55 | return false |
| 56 | } |
| 57 | } |
| 58 | return true |
| 59 | } |
| 60 | |
| 61 | testCases := map[string]struct { |
| 62 | json string |
| 63 | exp NodeIDs |
| 64 | }{ |
| 65 | "Empty list": {`""`, NodeIDs([]int{})}, |
| 66 | "One": {`"123"`, NodeIDs([]int{123})}, |
| 67 | "Many": {`"1,2,3"`, NodeIDs([]int{1, 2, 3})}, |
| 68 | } |
| 69 | for name, tc := range testCases { |
| 70 | t.Run(name, func(t *testing.T) { |
| 71 | var got NodeIDs |
| 72 | if err := json.Unmarshal([]byte(tc.json), &got); err != nil { |
| 73 | t.Fatalf("expected nil; got %v", err) |
| 74 | } |
| 75 | if !cmpNodeIDs(got, tc.exp) { |
| 76 | t.Fatalf("expected %v; got %v", tc.exp, got) |
| 77 | } |
| 78 | }) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | func TestLatency(t *testing.T) { |
| 83 | ctx := context.Background() |
nothing calls this directly
no test coverage detected