-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
65 lines (63 loc) · 1.18 KB
/
config_test.go
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
package main
import (
"reflect"
"testing"
)
func Test_derivedShards(t *testing.T) {
type args struct {
clusterIndex int
totalClusters int
numShards int
}
tests := []struct {
name string
args args
wantShardIDs []int
wantErr bool
}{
{
name: "unclustered",
args: args{
0, 1, 6,
},
wantShardIDs: []int{0, 1, 2, 3, 4, 5},
wantErr: false,
},
{
name: "cluster 0,2",
args: args{
0, 2, 6,
},
wantShardIDs: []int{0, 2, 4},
wantErr: false,
},
{
name: "cluster 1,3",
args: args{
1, 3, 6,
},
wantShardIDs: []int{1, 4},
wantErr: false,
},
{
name: "invalid",
args: args{
0, 2, 7,
},
wantShardIDs: nil,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotShardIDs, err := deriveClusterShards(tt.args.clusterIndex, tt.args.totalClusters, tt.args.numShards)
if (err != nil) != tt.wantErr {
t.Errorf("derivedShards() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(gotShardIDs, tt.wantShardIDs) {
t.Errorf("derivedShards() = %v, want %v", gotShardIDs, tt.wantShardIDs)
}
})
}
}