Skip to content

vtctl.generateShardRanges -> key.GenerateShardRanges#8134

Merged
ajm188 merged 3 commits intovitessio:masterfrom
guidoiaquinti:GenerateShardRanges
May 18, 2021
Merged

vtctl.generateShardRanges -> key.GenerateShardRanges#8134
ajm188 merged 3 commits intovitessio:masterfrom
guidoiaquinti:GenerateShardRanges

Conversation

@guidoiaquinti
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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>
if tt.wantErr {
assert.Error(t, err)
require.Error(t, err)
} else {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 pushed a commit to tinyspeck/vitess that referenced this pull request Jul 7, 2021
vtctl.generateShardRanges -> key.GenerateShardRanges
ajm188 pushed 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