-
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
chore: modernize tests #15244
chore: modernize tests #15244
Conversation
Signed-off-by: Manik Rana <manikrana54@gmail.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #15244 +/- ##
==========================================
+ Coverage 67.46% 67.54% +0.07%
==========================================
Files 1560 1561 +1
Lines 193186 193387 +201
==========================================
+ Hits 130333 130618 +285
+ Misses 62853 62769 -84 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Manik Rana <manikrana54@gmail.com>
hey @ajm188 I tried to add the new range in some of the testfiles but on commiting, the linter's complaining with this output:
not sure if the issue's with CI or with my machine as I've been having some issues setting up go1.22 |
if you aren't on at least 1.22 this syntax is invalid, so that is probably the issue. what is the issue you are having setting up on your machine? i'm happy to help! |
I did install go1.22 and it's now the default go version on my machine. These errors don't show up in vscode. Only shows up when I try to commit via my terminal 🤔 As for my setup I'm having issues with the Go lsp on vscode but I think that's unrelated. |
I just tried applying that change and didn't have a problem:
maybe you need to update golangci-lint after the go upgrade? |
sync with main
@Maniktherana i think you've overlapped with some work i did here: #15194 you might want to rebase on that |
Signed-off-by: Manik Rana <manikrana54@gmail.com>
Signed-off-by: Manik Rana <manikrana54@gmail.com>
Signed-off-by: Manik Rana <manikrana54@gmail.com>
done |
Signed-off-by: Manik Rana <Manikrana54@gmail.com>
go/cache/lru_cache_test.go
Outdated
assert.Equal(t, 0, l, "length = %v, want 0", l) | ||
assert.Equal(t, int64(0), sz, "size = %v, want 0", sz) | ||
assert.Equal(t, int64(5), c, "capacity = %v, want 5", c) |
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.
When using the asset
I don't think it is useful to add the expectations in the message field. The method already prints the wanted value and the received value:
Error: Not equal:
expected: 1
actual : 0
Test: TestInitialState
Messages: size = 0, want 1
This apply to all the files you modified in this PR
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.
done, I'll wait on the the CI checks tho
Signed-off-by: Manik Rana <Manikrana54@gmail.com>
Signed-off-by: Manik Rana <manikrana54@gmail.com>
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.
looking good, pending previous review
go/cache/theine/singleflight_test.go
Outdated
@@ -45,6 +45,7 @@ func TestDo(t *testing.T) { | |||
|
|||
assert.Equal(t, "bar (string)", fmt.Sprintf("%v (%T)", v, v), "incorrect Do value") | |||
assert.NoError(t, err, "got Do error") | |||
|
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.
on your next pass you should ditch this extra line
Signed-off-by: Manik Rana <manikrana54@gmail.com>
Signed-off-by: Manik Rana <manikrana54@gmail.com>
go/cache/theine/singleflight_test.go
Outdated
@@ -54,8 +54,8 @@ func TestDoErr(t *testing.T) { | |||
return "", someErr | |||
}) | |||
|
|||
assert.ErrorIs(t, err, someErr, "incorrect Do error") | |||
assert.Empty(t, v, "unexpected non-empty value") | |||
assert.Equal(t, someErr, 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.
why did we change from ErrorIs
to Equal
here?
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 may have been due to me using the test-rewriter and then resolving merge conflicts when rebasing. I'll revert this
go/cache/theine/singleflight_test.go
Outdated
assert.ErrorIs(t, err, someErr, "incorrect Do error") | ||
assert.Empty(t, v, "unexpected non-empty value") | ||
assert.Equal(t, someErr, err) | ||
assert.Equal(t, "", v) |
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.
why not assert.Empty
?
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.
I'll revert this one too
go/cache/theine/singleflight_test.go
Outdated
@@ -98,7 +98,7 @@ func TestDoDupSuppress(t *testing.T) { | |||
c <- "bar" | |||
wg2.Wait() | |||
got := atomic.LoadInt32(&calls) | |||
assert.True(t, got > 0 && got < n, "number of calls not between 0 and %d", n) | |||
assert.True(t, got > 0 && got < n) |
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.
assert.Greater
and assert.Lesser
might produce more useful error messages
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.
ah, these are mostly from using test writer tool you mentioned. I'll go back and fix the tests
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.
yeah that tool isn't perfect but it's definitely a start over doing this all by hand! just needs some touching up after
go/event/event_test.go
Outdated
if !triggered { | ||
t.Errorf("static listener failed to trigger") | ||
} | ||
assert.True(t, triggered) |
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 will read just as expected true, got false
, so we might want a more descriptive message here (i.e. "expected static listener to trigger")
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.
same applies to other assert.True
and assert.False
instances
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.
Agree with @ajm188 on this. If you are up to doing a PR against the test rewriter tool, it will be good to try and preserve the custom messages.
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.
Nice work. I can approve once the current set of comments are addressed. I didn't see anything else that needs to change.
go/event/event_test.go
Outdated
if !triggered { | ||
t.Errorf("static listener failed to trigger") | ||
} | ||
assert.True(t, triggered) |
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.
Agree with @ajm188 on this. If you are up to doing a PR against the test rewriter tool, it will be good to try and preserve the custom messages.
@@ -315,7 +315,6 @@ func TestShouldEmitLog(t *testing.T) { | |||
} | |||
|
|||
for _, tt := range tests { | |||
tt := tt |
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.
👍
Signed-off-by: Manik Rana <manikrana54@gmail.com>
Signed-off-by: Manik Rana <manikrana54@gmail.com>
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.
I found a couple of small things that still need to fixed. Will give final approval after that.
go/event/event_test.go
Outdated
@@ -245,10 +227,8 @@ func TestDispatchUpdate(t *testing.T) { | |||
|
|||
ev := &testUpdateEvent{} | |||
DispatchUpdate(ev, "hello") | |||
assert.True(t, triggered) |
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 missed this one, it should have a message passed in.
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.
done
go/mysql/decimal/decimal_test.go
Outdated
assert. | ||
// rule 1: d = d2*q +r | ||
True(t, d.Equal(d2.mul(q).Add(r))) |
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.
Should fix the formatting. Comment should go on the line above the assertion.
Signed-off-by: Manik Rana <manikrana54@gmail.com>
go/cache/lru_cache_test.go
Outdated
t.Errorf("misses = %v, want 0", c) | ||
} | ||
assert.Equal(t, 0, l) | ||
assert.Equal(t, int64(0), sz) |
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.
nitpick: you can use assert.EqualValue
to avoid casting the literals to int64
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.
done
go/mysql/decimal/decimal_test.go
Outdated
if Zero.Sign() != 0 { | ||
t.Errorf("%q should have sign 0", Zero) | ||
} | ||
assert.Equal(t, 0, Zero.Sign()) |
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.
nitpick: assert.Zero
go/mysql/decimal/decimal_test.go
Outdated
if c.Cmp(a) == 0 { | ||
t.Errorf("error") | ||
} | ||
assert.NotEqual(t, 0, c.Cmp(a)) |
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.
nitpick: assert.NotZero
Signed-off-by: Manik Rana <manikrana54@gmail.com>
Signed-off-by: Manik Rana <manikrana54@gmail.com>
Signed-off-by: Manik Rana <manikrana54@gmail.com>
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.
i'm on-board with the assert.True
messages and the Greater/Less, but i have questions about the Zero and EqualValues
assert.Zero(t, l) | ||
assert.EqualValues(t, 0, sz) | ||
assert.EqualValues(t, 5, c) | ||
assert.EqualValues(t, 0, e) | ||
assert.EqualValues(t, 0, h) | ||
assert.EqualValues(t, 0, m) |
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.
why did we make these changes?
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.
I received a review earlier to use EqualValues to avoid typecasting and Zero/NotZero. I thought it would apply to other portions of the PR such as here
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.
Sorry @Maniktherana I completely missed those review comments. I'm good to merge!
Description
Used test writer to convert
t.errorf
toassert
Related Issue(s)
addresses #15183
partially covers #15182
Checklist
Deployment Notes