-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vtctl.generateShardRanges -> key.GenerateShardRanges #8134
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Package require implements the same assertions as the
assert
package 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -633,9 +634,9 @@ func TestGenerateShardRanges(t *testing.T) { | |||
t.Run(tt.name, func(t *testing.T) { | |||
got, err := GenerateShardRanges(tt.args.shards) | |||
if tt.wantErr { | |||
assert.Error(t, err) | |||
require.Error(t, err) | |||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair but I've blindly copy pasted what was there before:
vitess/go/vt/vtctl/vtctl_test.go
Lines 59 to 70 in 7c532a5
for _, tt := range tests { | |
t.Run(tt.name, func(t *testing.T) { | |
got, err := generateShardRanges(tt.args.shards) | |
if tt.wantErr { | |
require.Error(t, err) | |
} else { | |
require.NoError(t, err) | |
} | |
assert.Equal(t, got, tt.want) | |
}) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦 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.generateShardRanges
tokey.GenerateShardRanges
so it can be used also in other places (I'm not surekey
is the best package where to put it but I didn't find a better one).Checklist
Deployment Notes