This repository has been archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from RaduBerinde/field-stuff
Add convenience methods to log.Field
- Loading branch information
Showing
2 changed files
with
78 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,35 @@ | ||
package log | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestFieldString(t *testing.T) { | ||
testCases := []struct { | ||
field Field | ||
expected string | ||
}{ | ||
{ | ||
field: String("key", "value"), | ||
expected: "key:value", | ||
}, | ||
{ | ||
field: Bool("key", true), | ||
expected: "key:true", | ||
}, | ||
{ | ||
field: Int("key", 5), | ||
expected: "key:5", | ||
}, | ||
{ | ||
field: Error(fmt.Errorf("err msg")), | ||
expected: "error:err msg", | ||
}, | ||
} | ||
for i, tc := range testCases { | ||
if str := tc.field.String(); str != tc.expected { | ||
t.Errorf("%d: expected '%s', got '%s'", i, tc.expected, str) | ||
} | ||
} | ||
} |