-
Notifications
You must be signed in to change notification settings - Fork 662
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
Use ids.GenerateTestID
helper in tests
#3165
base: master
Are you sure you want to change the base?
Conversation
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.
Approving with requested changes (use fmt.Sprintf()
instead of strings.Replace()
) as I don't need to re-review them, but please address before merging.
@@ -1262,7 +1262,7 @@ func TestStateSyncIsStoppedIfEnoughVotesAreCastedWithNoClearMajority(t *testing. | |||
context.Background(), | |||
voterID, | |||
reqID, | |||
set.Of(ids.ID{'u', 'n', 'k', 'n', 'o', 'w', 'n', 'I', 'D'}), | |||
set.Of(ids.GenerateTestID()), |
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.
Was it ever useful in debugging to have these kinds of "labelled" ids? If so, you could add ids.GenerateLabelledTestID(tb testing.TB, lbl string)
that then calls tb.Logf("test ID %q: %v", lbl, id)
before returning the value.
The only problem I see with this would be introducing the testing
package into prod code.
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.
This is completely optional and dependent on the answer to my opening question.
@@ -142,20 +145,23 @@ func TestBanffProposalBlockJSON(t *testing.T) { | |||
simpleBanffProposalBlockBytes, err := json.MarshalIndent(simpleBanffProposalBlock, "", "\t") | |||
require.NoError(err) | |||
|
|||
require.Equal(`{ | |||
expectedSimpleBanffProposalBlockString := `{ |
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.
This would be clearer if it used fmt.Sprintf()
instead of strings.Replace()
.
(optional, subjective) You could use explicit arg indices if it makes it more readable, but I'm not sure that it will.
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.
TIL about explicit arg indicies
@@ -186,7 +192,7 @@ func TestBanffProposalBlockJSON(t *testing.T) { | |||
complexBanffProposalBlockBytes, err := json.MarshalIndent(complexBanffProposalBlock, "", "\t") | |||
require.NoError(err) | |||
|
|||
require.Equal(`{ | |||
expectedComplexBanffProposalBlockString := `{ |
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.
As above re fmt.Sprintf()
.
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.
Are there any cases here where this introduces a weird dependency on the sorted-ness of IDs returned by ids.GenerateTestID()
?
@@ -142,20 +145,23 @@ func TestBanffProposalBlockJSON(t *testing.T) { | |||
simpleBanffProposalBlockBytes, err := json.MarshalIndent(simpleBanffProposalBlock, "", "\t") | |||
require.NoError(err) | |||
|
|||
require.Equal(`{ | |||
expectedSimpleBanffProposalBlockString := `{ |
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.
TIL about explicit arg indicies
Converting to draft for now, there seems to be dependencies in the codebase already that rely on the sorted-ness of the IDs returned. Will investigate further. |
Why this should be merged
We hardcode random byte slices in a lot of the tests. Let's use the helper we have already instead :)
How this works
Replace hard-coded byte slices with
ids.GenerateTestID()
How this was tested
CI