Skip to content

Commit

Permalink
Use subtests for Combine tests (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav authored Jun 27, 2017
1 parent a100c98 commit 87edb7a
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ func newMultiErr(errors ...error) error {

func TestCombine(t *testing.T) {
tests := []struct {
giveErrors []error
wantError error
// Input
giveErrors []error

// Resulting error
wantError error

// %+v and %v string representations
wantMultiline string
wantSingleline string
}{
Expand Down Expand Up @@ -232,15 +237,25 @@ func TestCombine(t *testing.T) {
require.Equal(t, tt.wantError, err)

if tt.wantMultiline != "" {
assert.Equal(t, tt.wantMultiline, fmt.Sprintf("%+v", err))
t.Run("Sprintf/multiline", func(t *testing.T) {
assert.Equal(t, tt.wantMultiline, fmt.Sprintf("%+v", err))
})
}

if tt.wantSingleline != "" {
assert.Equal(t, tt.wantSingleline, err.Error())
t.Run("Sprintf/singleline", func(t *testing.T) {
assert.Equal(t, tt.wantSingleline, fmt.Sprintf("%v", err))
})

t.Run("Error()", func(t *testing.T) {
assert.Equal(t, tt.wantSingleline, err.Error())
})

if s, ok := err.(fmt.Stringer); ok {
assert.Equal(t, tt.wantSingleline, s.String())
t.Run("String()", func(t *testing.T) {
assert.Equal(t, tt.wantSingleline, s.String())
})
}
assert.Equal(t, tt.wantSingleline, fmt.Sprintf("%v", err))
}
})
}
Expand Down

0 comments on commit 87edb7a

Please sign in to comment.