Skip to content

Commit

Permalink
test: Minor nits
Browse files Browse the repository at this point in the history
- We can use backticks to avoid having to escape quotes
- Prefer to have the error and non-error paths branch
  so that we're not asserting the value of level in the error case
  (since that's specifically not part of the contract)
  • Loading branch information
abhinav committed Jan 13, 2022
1 parent 6dca8e8 commit b45b8a9
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions zapcore/level_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package zapcore
import (
"bytes"
"flag"
"fmt"
"strings"
"testing"

Expand Down Expand Up @@ -81,16 +80,21 @@ func TestParseLevel(t *testing.T) {
tests := []struct {
text string
level Level
err error
err string
}{
{"info", InfoLevel, nil},
{"DEBUG", DebugLevel, nil},
{"FOO", 0, fmt.Errorf("unrecognized level: \"FOO\"")},
{"info", InfoLevel, ""},
{"DEBUG", DebugLevel, ""},
{"FOO", 0, `unrecognized level: "FOO"`},
}
for _, tt := range tests {
parsedLevel, err := ParseLevel(tt.text)
assert.Equal(t, tt.level, parsedLevel)
assert.Equal(t, tt.err, err)
if len(tt.err) == 0 {
assert.NoError(t, err)
assert.Equal(t, tt.level, parsedLevel)
} else {
assert.Error(t, err)
assert.Contains(t, err.Error(), tt.err)
}
}
}

Expand Down

0 comments on commit b45b8a9

Please sign in to comment.