Skip to content

Commit

Permalink
Tests: refactor tests expecting for panic
Browse files Browse the repository at this point in the history
  • Loading branch information
hovsep committed Sep 17, 2024
1 parent 9471ba6 commit 3078b5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 27 deletions.
19 changes: 7 additions & 12 deletions signal/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,13 @@ func TestGroup_FirstPayload(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer func() {
r := recover()
if tt.wantPanic && r == nil {
t.Errorf("The code did not panic")
}

if !tt.wantPanic && r != nil {
t.Errorf("The code unexpectedly paniced")
}
}()

assert.Equal(t, tt.want, tt.group.FirstPayload())
if tt.wantPanic {
assert.Panics(t, func() {
tt.group.FirstPayload()
})
} else {
assert.Equal(t, tt.want, tt.group.FirstPayload())
}
})
}
}
Expand Down
18 changes: 3 additions & 15 deletions signal/signal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ func TestNew(t *testing.T) {

func TestSignal_Payload(t *testing.T) {
tests := []struct {
name string
signal *Signal
want any
wantPanic bool
name string
signal *Signal
want any
}{
{
name: "nil payload is valid",
Expand All @@ -60,17 +59,6 @@ func TestSignal_Payload(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer func() {
r := recover()
if tt.wantPanic && r == nil {
t.Errorf("The code did not panic")
}

if !tt.wantPanic && r != nil {
t.Errorf("The code unexpectedly paniced")
}
}()

assert.Equal(t, tt.want, tt.signal.Payload())
})
}
Expand Down

0 comments on commit 3078b5c

Please sign in to comment.