-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
when passing a single, bare value to logger functions…
if the bare value is an error, use the key “error”
- Loading branch information
Showing
2 changed files
with
26 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package flume | ||
|
||
import ( | ||
"errors" | ||
"github.com/stretchr/testify/assert" | ||
"go.uber.org/zap" | ||
"testing" | ||
) | ||
|
||
func TestSweetenFields(t *testing.T) { | ||
|
||
// single value, instead of key/value pairs | ||
c := NewCore("asdf") | ||
fields := c.sweetenFields([]interface{}{1}) | ||
|
||
assert.Equal(t, []zap.Field{zap.Int("", 1)}, fields) | ||
|
||
// if the bare value is an error, use the key "error" | ||
err := errors.New("blue") | ||
fields = c.sweetenFields([]interface{}{err}) | ||
assert.Equal(t, []zap.Field{zap.NamedError("error", err)}, fields) | ||
} |