Skip to content
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

Merged
merged 3 commits into from
May 18, 2021

Conversation

guidoiaquinti
Copy link
Member

Signed-off-by: Guido Iaquinti giaquinti@slack-corp.com

Description

Export vtctl.generateShardRanges to key.GenerateShardRanges so it can be used also in other places (I'm not sure key is the best package where to put it but I didn't find a better one).

Checklist

  • Tests were added or are not required
  • Documentation was added or is not required

Deployment Notes

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")
Copy link
Member Author

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)
Copy link
Member Author

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)

Copy link
Contributor

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

Copy link
Member Author

@guidoiaquinti guidoiaquinti May 17, 2021

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).

if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Copy link
Contributor

@ajm188 ajm188 left a 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)
Copy link
Contributor

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>
@@ -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 {
Copy link
Contributor

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)

Copy link
Member Author

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:

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)
})
}

Copy link
Contributor

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>
@ajm188 ajm188 merged commit 48f22aa into vitessio:master May 18, 2021
@guidoiaquinti guidoiaquinti deleted the GenerateShardRanges branch May 18, 2021 15:45
@askdba askdba added Component: Cluster management Type: Enhancement Logical improvement (somewhere between a bug and feature) labels Jun 10, 2021
ajm188 added a commit to tinyspeck/vitess that referenced this pull request Jul 7, 2021
vtctl.generateShardRanges -> key.GenerateShardRanges
ajm188 added a commit to tinyspeck/vitess that referenced this pull request Sep 28, 2021
vtctl.generateShardRanges -> key.GenerateShardRanges
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Cluster management Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants