-
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
Changes from 9 commits
06ba65a
3b4b428
ebcd8b9
56e4628
790243f
292e9c5
aff9e49
3ccab1e
fec218e
8f9426a
b8f5b3e
fed3dbc
c7de6a8
d9d6bda
bc8b48c
3e9e55a
303c47e
faadfce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. on your next pass you should ditch this extra line |
||
} | ||
|
||
func TestDoErr(t *testing.T) { | ||
|
@@ -54,8 +55,9 @@ 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 commentThe reason will be displayed to describe this comment to others. Learn more. why did we change from 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. this may have been due to me using the test-rewriter and then resolving merge conflicts when rebasing. I'll revert this |
||
assert.Equal(t, "", v) | ||
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. why not 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. I'll revert this one too |
||
|
||
} | ||
|
||
func TestDoDupSuppress(t *testing.T) { | ||
|
@@ -152,6 +154,7 @@ func TestGoexitDo(t *testing.T) { | |
var err error | ||
defer func() { | ||
assert.NoError(t, err) | ||
|
||
if atomic.AddInt32(&waited, -1) == 0 { | ||
close(done) | ||
} | ||
|
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,8 @@ func TestStaticListener(t *testing.T) { | |
AddListener(func(testEvent1) { triggered = true }) | ||
AddListener(func(testEvent2) { t.Errorf("wrong listener type triggered") }) | ||
Dispatch(testEvent1{}) | ||
assert.True(t, triggered, "static listener failed to trigger") | ||
|
||
if !triggered { | ||
t.Errorf("static listener failed to trigger") | ||
} | ||
} | ||
|
||
func TestPointerListener(t *testing.T) { | ||
|
@@ -69,10 +69,8 @@ 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) | ||
assert.True(t, testEvent.triggered, "pointer listener failed to trigger") | ||
|
||
if !testEvent.triggered { | ||
t.Errorf("pointer listener failed to trigger") | ||
} | ||
} | ||
|
||
func TestInterfaceListener(t *testing.T) { | ||
|
@@ -82,10 +80,8 @@ func TestInterfaceListener(t *testing.T) { | |
AddListener(func(testInterface1) { triggered = true }) | ||
AddListener(func(testInterface2) { t.Errorf("interface listener triggered on non-matching type") }) | ||
Dispatch(testEvent1{}) | ||
assert.True(t, triggered, "interface listener failed to trigger") | ||
|
||
if !triggered { | ||
t.Errorf("interface listener failed to trigger") | ||
} | ||
} | ||
|
||
func TestEmptyInterfaceListener(t *testing.T) { | ||
|
@@ -94,10 +90,8 @@ func TestEmptyInterfaceListener(t *testing.T) { | |
triggered := false | ||
AddListener(func(any) { triggered = true }) | ||
Dispatch("this should match any") | ||
assert.True(t, triggered, "any listener failed to trigger") | ||
|
||
if !triggered { | ||
t.Errorf("any listener failed to trigger") | ||
} | ||
} | ||
|
||
func TestMultipleListeners(t *testing.T) { | ||
|
@@ -144,7 +138,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 +179,8 @@ func TestDispatchPointerToValueInterfaceListener(t *testing.T) { | |
triggered = true | ||
}) | ||
Dispatch(&testEvent1{}) | ||
assert.True(t, triggered) | ||
|
||
if !triggered { | ||
t.Errorf("Dispatch by pointer failed to trigger interface listener") | ||
} | ||
} | ||
|
||
func TestDispatchValueToValueInterfaceListener(t *testing.T) { | ||
|
@@ -200,10 +191,8 @@ func TestDispatchValueToValueInterfaceListener(t *testing.T) { | |
triggered = true | ||
}) | ||
Dispatch(testEvent1{}) | ||
assert.True(t, triggered) | ||
|
||
if !triggered { | ||
t.Errorf("Dispatch by value failed to trigger interface listener") | ||
} | ||
} | ||
|
||
func TestDispatchPointerToPointerInterfaceListener(t *testing.T) { | ||
|
@@ -212,10 +201,8 @@ func TestDispatchPointerToPointerInterfaceListener(t *testing.T) { | |
triggered := false | ||
AddListener(func(testInterface2) { triggered = true }) | ||
Dispatch(&testEvent2{}) | ||
assert.True(t, triggered) | ||
|
||
if !triggered { | ||
t.Errorf("interface listener failed to trigger for pointer") | ||
} | ||
} | ||
|
||
func TestDispatchValueToPointerInterfaceListener(t *testing.T) { | ||
|
@@ -245,10 +232,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) | ||
|
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