vtctl.generateShardRanges -> key.GenerateShardRanges#8134
vtctl.generateShardRanges -> key.GenerateShardRanges#8134ajm188 merged 3 commits intovitessio:masterfrom
Conversation
Signed-off-by: Guido Iaquinti <giaquinti@slack-corp.com>
| format = "%04x" | ||
| maxShards = 65536 | ||
| default: | ||
| return nil, errors.New("this function does not support more than 65336 shards in a single keyspace") |
There was a problem hiding this comment.
The error has been renamed
| t.Run(tt.name, func(t *testing.T) { | ||
| got, err := GenerateShardRanges(tt.args.shards) | ||
| if tt.wantErr { | ||
| assert.Error(t, err) |
There was a problem hiding this comment.
Before it was require.Error(t, err) but I don't think this was really needed (and we can avoid importing require)
There was a problem hiding this comment.
We actually want the behavior of require in the cases where tt.wantErr=false in that it will stop execution of the test if the assertion fails (this is the main difference between the assert and require packages. It makes the intent of the test assertion much clearer in my view
There was a problem hiding this comment.
Package require implements the same assertions as the
assertpackage but stops test execution when a test fails.
I don't see a big difference between the two but if you think it's cleaner I revert my change (see next commit).
go/vt/key/key_test.go
Outdated
| if tt.wantErr { | ||
| assert.Error(t, err) | ||
| } else { | ||
| assert.NoError(t, err) |
ajm188
left a comment
There was a problem hiding this comment.
Just the one comment about require and then lgtm
| t.Run(tt.name, func(t *testing.T) { | ||
| got, err := GenerateShardRanges(tt.args.shards) | ||
| if tt.wantErr { | ||
| assert.Error(t, err) |
There was a problem hiding this comment.
We actually want the behavior of require in the cases where tt.wantErr=false in that it will stop execution of the test if the assertion fails (this is the main difference between the assert and require packages. It makes the intent of the test assertion much clearer in my view
Signed-off-by: Guido Iaquinti <giaquinti@slack-corp.com>
go/vt/key/key_test.go
Outdated
| if tt.wantErr { | ||
| assert.Error(t, err) | ||
| require.Error(t, err) | ||
| } else { |
There was a problem hiding this comment.
you no longer need the else here (this is the benefit of require)
this should read:
if tt.wantErr {
assert.Error(t, err)
return
}
require.NoError(t, err)
assert.Equal(t, got, tt.want)There was a problem hiding this comment.
Fair but I've blindly copy pasted what was there before:
vitess/go/vt/vtctl/vtctl_test.go
Lines 59 to 70 in 7c532a5
There was a problem hiding this comment.
🤦 haha sorry, and thank you for cleaning up my original mistake
Signed-off-by: Guido Iaquinti <giaquinti@slack-corp.com>
vtctl.generateShardRanges -> key.GenerateShardRanges
vtctl.generateShardRanges -> key.GenerateShardRanges
Signed-off-by: Guido Iaquinti giaquinti@slack-corp.com
Description
Export
vtctl.generateShardRangestokey.GenerateShardRangesso it can be used also in other places (I'm not surekeyis the best package where to put it but I didn't find a better one).Checklist
Deployment Notes