diff options
Diffstat (limited to 'weed/shell/command_ec_common_test.go')
| -rw-r--r-- | weed/shell/command_ec_common_test.go | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/weed/shell/command_ec_common_test.go b/weed/shell/command_ec_common_test.go index 08e4a41c7..76609c89d 100644 --- a/weed/shell/command_ec_common_test.go +++ b/weed/shell/command_ec_common_test.go @@ -32,6 +32,40 @@ func errorCheck(got error, want string) error { } return nil } +func TestParseReplicaPlacementArg(t *testing.T) { + getDefaultReplicaPlacementOrig := getDefaultReplicaPlacement + getDefaultReplicaPlacement = func(commandEnv *CommandEnv) (*super_block.ReplicaPlacement, error) { + return super_block.NewReplicaPlacementFromString("123") + } + defer func() { + getDefaultReplicaPlacement = getDefaultReplicaPlacementOrig + }() + + testCases := []struct { + argument string + want string + wantErr string + }{ + {"lalala", "lal", "unexpected replication type"}, + {"", "123", ""}, + {"021", "021", ""}, + } + + for _, tc := range testCases { + commandEnv := &CommandEnv{} + got, gotErr := parseReplicaPlacementArg(commandEnv, tc.argument) + + if err := errorCheck(gotErr, tc.wantErr); err != nil { + t.Errorf("argument %q: %s", tc.argument, err.Error()) + continue + } + + want, _ := super_block.NewReplicaPlacementFromString(tc.want) + if !got.Equals(want) { + t.Errorf("got replica placement %q, want %q", got.String(), want.String()) + } + } +} func TestEcDistribution(t *testing.T) { @@ -55,26 +89,35 @@ func TestEcDistribution(t *testing.T) { } func TestVolumeIdToReplicaPlacement(t *testing.T) { + ecReplicaPlacement, _ := super_block.NewReplicaPlacementFromString("123") + testCases := []struct { topology *master_pb.TopologyInfo vid string want string wantErr string }{ - {topology1, "", "", "failed to resolve replica placement for volume ID 0"}, - {topology1, "0", "", "failed to resolve replica placement for volume ID 0"}, + {topology1, "", "", "failed to resolve replica placement"}, + {topology1, "0", "", "failed to resolve replica placement"}, {topology1, "1", "100", ""}, {topology1, "296", "100", ""}, - {topology2, "", "", "failed to resolve replica placement for volume ID 0"}, - {topology2, "19012", "", "failed to resolve replica placement for volume ID 19012"}, + {topology2, "", "", "failed to resolve replica placement"}, + {topology2, "19012", "", "failed to resolve replica placement"}, {topology2, "6271", "002", ""}, {topology2, "17932", "002", ""}, + {topologyEc, "", "", "failed to resolve replica placement"}, + {topologyEc, "0", "", "failed to resolve replica placement"}, + {topologyEc, "6225", "002", ""}, + {topologyEc, "6241", "002", ""}, + {topologyEc, "9577", "123", ""}, // EC volume + {topologyEc, "12737", "123", ""}, // EC volume } for _, tc := range testCases { + commandEnv := &CommandEnv{} vid, _ := needle.NewVolumeId(tc.vid) ecNodes, _ := collectEcVolumeServersByDc(tc.topology, "") - got, gotErr := volumeIdToReplicaPlacement(vid, ecNodes) + got, gotErr := volumeIdToReplicaPlacement(commandEnv, vid, ecNodes, ecReplicaPlacement) if err := errorCheck(gotErr, tc.wantErr); err != nil { t.Errorf("volume %q: %s", tc.vid, err.Error()) |
