-
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
Merged
Merged
chore: modernize tests #15244
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
06ba65a
chore: remove loopclosure captures from tests
Maniktherana 3b4b428
chore: convert errorf to assert
Maniktherana ebcd8b9
Merge pull request #3 from vitessio/main
Maniktherana 56e4628
chore: remove loopclosure captures from tests
Maniktherana 790243f
chore: convert errorf to assert
Maniktherana 292e9c5
Merge changes from origin/modernize-tests
Maniktherana aff9e49
chore: replace errof with assert using test-rewrite tool
Maniktherana 3ccab1e
Merge branch 'main' into modernize-tests
Maniktherana fec218e
chore: replace with assert using test-rewriter + fix failing test
Maniktherana 8f9426a
chore: remove unneeded assert messages
Maniktherana b8f5b3e
chore: continue remove unneeded assert messages
Maniktherana fed3dbc
lint
Maniktherana c7de6a8
chore: readd messages on test failure
Maniktherana d9d6bda
refac: use proper assertion methods
Maniktherana bc8b48c
chore: format tests
Maniktherana 3e9e55a
refac: use assert.EqualValues instead of equal
Maniktherana 303c47e
refac: use assert.Zero/NotZero
Maniktherana faadfce
refac: replace assert.equal with appropriate assertions
Maniktherana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ import ( | |
"reflect" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type testInterface1 interface { | ||
|
@@ -56,10 +58,7 @@ func TestStaticListener(t *testing.T) { | |
AddListener(func(testEvent1) { triggered = true }) | ||
AddListener(func(testEvent2) { t.Errorf("wrong listener type triggered") }) | ||
Dispatch(testEvent1{}) | ||
|
||
if !triggered { | ||
t.Errorf("static listener failed to trigger") | ||
} | ||
assert.True(t, triggered, "static listener failed to trigger") | ||
} | ||
|
||
func TestPointerListener(t *testing.T) { | ||
|
@@ -69,10 +68,7 @@ func TestPointerListener(t *testing.T) { | |
AddListener(func(ev *testEvent2) { ev.triggered = true }) | ||
AddListener(func(testEvent2) { t.Errorf("non-pointer listener triggered on pointer type") }) | ||
Dispatch(testEvent) | ||
|
||
if !testEvent.triggered { | ||
t.Errorf("pointer listener failed to trigger") | ||
} | ||
assert.True(t, testEvent.triggered, "pointer listener failed to trigger") | ||
} | ||
|
||
func TestInterfaceListener(t *testing.T) { | ||
|
@@ -82,10 +78,7 @@ func TestInterfaceListener(t *testing.T) { | |
AddListener(func(testInterface1) { triggered = true }) | ||
AddListener(func(testInterface2) { t.Errorf("interface listener triggered on non-matching type") }) | ||
Dispatch(testEvent1{}) | ||
|
||
if !triggered { | ||
t.Errorf("interface listener failed to trigger") | ||
} | ||
assert.True(t, triggered, "interface listener failed to trigger") | ||
} | ||
|
||
func TestEmptyInterfaceListener(t *testing.T) { | ||
|
@@ -94,10 +87,7 @@ func TestEmptyInterfaceListener(t *testing.T) { | |
triggered := false | ||
AddListener(func(any) { triggered = true }) | ||
Dispatch("this should match any") | ||
|
||
if !triggered { | ||
t.Errorf("any listener failed to trigger") | ||
} | ||
assert.True(t, triggered, "empty listener failed to trigger") | ||
} | ||
|
||
func TestMultipleListeners(t *testing.T) { | ||
|
@@ -144,7 +134,6 @@ func TestBadListenerWrongType(t *testing.T) { | |
|
||
defer func() { | ||
err := recover() | ||
|
||
if err == nil { | ||
t.Errorf("bad listener type (not a func) failed to trigger panic") | ||
} | ||
|
@@ -186,10 +175,8 @@ func TestDispatchPointerToValueInterfaceListener(t *testing.T) { | |
triggered = true | ||
}) | ||
Dispatch(&testEvent1{}) | ||
assert.True(t, triggered, "Dispatch by pointer failed to trigger interface listener") | ||
|
||
if !triggered { | ||
t.Errorf("Dispatch by pointer failed to trigger interface listener") | ||
} | ||
} | ||
|
||
func TestDispatchValueToValueInterfaceListener(t *testing.T) { | ||
|
@@ -200,10 +187,7 @@ func TestDispatchValueToValueInterfaceListener(t *testing.T) { | |
triggered = true | ||
}) | ||
Dispatch(testEvent1{}) | ||
|
||
if !triggered { | ||
t.Errorf("Dispatch by value failed to trigger interface listener") | ||
} | ||
assert.True(t, triggered, "Dispatch by value failed to trigger interface listener") | ||
} | ||
|
||
func TestDispatchPointerToPointerInterfaceListener(t *testing.T) { | ||
|
@@ -212,10 +196,8 @@ func TestDispatchPointerToPointerInterfaceListener(t *testing.T) { | |
triggered := false | ||
AddListener(func(testInterface2) { triggered = true }) | ||
Dispatch(&testEvent2{}) | ||
assert.True(t, triggered, "interface listener failed to trigger for pointer") | ||
|
||
if !triggered { | ||
t.Errorf("interface listener failed to trigger for pointer") | ||
} | ||
} | ||
|
||
func TestDispatchValueToPointerInterfaceListener(t *testing.T) { | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
if !triggered { | ||
t.Errorf("listener failed to trigger on DispatchUpdate()") | ||
} | ||
want := "hello" | ||
if got := ev.update.(string); got != want { | ||
t.Errorf("ev.update = %#v, want %#v", got, want) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 toint64
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