diff options
author | Ondrej Fabry <ofabry@cisco.com> | 2017-11-28 16:28:48 +0100 |
---|---|---|
committer | Ondrej Fabry <ofabry@cisco.com> | 2017-11-28 16:29:42 +0100 |
commit | ac6019137d5b10d02c7acac4f63fa22091b9933d (patch) | |
tree | 6b7cc4ecd56fce967bf5665292503459582a58ac /vendor/github.com/Sirupsen/logrus/json_formatter_test.go | |
parent | 3f1edad4e6ba0a7876750aea55507fae14d8badf (diff) |
Fix imports for github.com/sirupsen/logrus
Change-Id: I84f2e45e5ff188a2a7a80cf69f607b44486c1754
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'vendor/github.com/Sirupsen/logrus/json_formatter_test.go')
-rw-r--r-- | vendor/github.com/Sirupsen/logrus/json_formatter_test.go | 199 |
1 files changed, 0 insertions, 199 deletions
diff --git a/vendor/github.com/Sirupsen/logrus/json_formatter_test.go b/vendor/github.com/Sirupsen/logrus/json_formatter_test.go deleted file mode 100644 index 51093a7..0000000 --- a/vendor/github.com/Sirupsen/logrus/json_formatter_test.go +++ /dev/null @@ -1,199 +0,0 @@ -package logrus - -import ( - "encoding/json" - "errors" - "strings" - "testing" -) - -func TestErrorNotLost(t *testing.T) { - formatter := &JSONFormatter{} - - b, err := formatter.Format(WithField("error", errors.New("wild walrus"))) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - - entry := make(map[string]interface{}) - err = json.Unmarshal(b, &entry) - if err != nil { - t.Fatal("Unable to unmarshal formatted entry: ", err) - } - - if entry["error"] != "wild walrus" { - t.Fatal("Error field not set") - } -} - -func TestErrorNotLostOnFieldNotNamedError(t *testing.T) { - formatter := &JSONFormatter{} - - b, err := formatter.Format(WithField("omg", errors.New("wild walrus"))) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - - entry := make(map[string]interface{}) - err = json.Unmarshal(b, &entry) - if err != nil { - t.Fatal("Unable to unmarshal formatted entry: ", err) - } - - if entry["omg"] != "wild walrus" { - t.Fatal("Error field not set") - } -} - -func TestFieldClashWithTime(t *testing.T) { - formatter := &JSONFormatter{} - - b, err := formatter.Format(WithField("time", "right now!")) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - - entry := make(map[string]interface{}) - err = json.Unmarshal(b, &entry) - if err != nil { - t.Fatal("Unable to unmarshal formatted entry: ", err) - } - - if entry["fields.time"] != "right now!" { - t.Fatal("fields.time not set to original time field") - } - - if entry["time"] != "0001-01-01T00:00:00Z" { - t.Fatal("time field not set to current time, was: ", entry["time"]) - } -} - -func TestFieldClashWithMsg(t *testing.T) { - formatter := &JSONFormatter{} - - b, err := formatter.Format(WithField("msg", "something")) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - - entry := make(map[string]interface{}) - err = json.Unmarshal(b, &entry) - if err != nil { - t.Fatal("Unable to unmarshal formatted entry: ", err) - } - - if entry["fields.msg"] != "something" { - t.Fatal("fields.msg not set to original msg field") - } -} - -func TestFieldClashWithLevel(t *testing.T) { - formatter := &JSONFormatter{} - - b, err := formatter.Format(WithField("level", "something")) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - - entry := make(map[string]interface{}) - err = json.Unmarshal(b, &entry) - if err != nil { - t.Fatal("Unable to unmarshal formatted entry: ", err) - } - - if entry["fields.level"] != "something" { - t.Fatal("fields.level not set to original level field") - } -} - -func TestJSONEntryEndsWithNewline(t *testing.T) { - formatter := &JSONFormatter{} - - b, err := formatter.Format(WithField("level", "something")) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - - if b[len(b)-1] != '\n' { - t.Fatal("Expected JSON log entry to end with a newline") - } -} - -func TestJSONMessageKey(t *testing.T) { - formatter := &JSONFormatter{ - FieldMap: FieldMap{ - FieldKeyMsg: "message", - }, - } - - b, err := formatter.Format(&Entry{Message: "oh hai"}) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - s := string(b) - if !(strings.Contains(s, "message") && strings.Contains(s, "oh hai")) { - t.Fatal("Expected JSON to format message key") - } -} - -func TestJSONLevelKey(t *testing.T) { - formatter := &JSONFormatter{ - FieldMap: FieldMap{ - FieldKeyLevel: "somelevel", - }, - } - - b, err := formatter.Format(WithField("level", "something")) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - s := string(b) - if !strings.Contains(s, "somelevel") { - t.Fatal("Expected JSON to format level key") - } -} - -func TestJSONTimeKey(t *testing.T) { - formatter := &JSONFormatter{ - FieldMap: FieldMap{ - FieldKeyTime: "timeywimey", - }, - } - - b, err := formatter.Format(WithField("level", "something")) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - s := string(b) - if !strings.Contains(s, "timeywimey") { - t.Fatal("Expected JSON to format time key") - } -} - -func TestJSONDisableTimestamp(t *testing.T) { - formatter := &JSONFormatter{ - DisableTimestamp: true, - } - - b, err := formatter.Format(WithField("level", "something")) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - s := string(b) - if strings.Contains(s, FieldKeyTime) { - t.Error("Did not prevent timestamp", s) - } -} - -func TestJSONEnableTimestamp(t *testing.T) { - formatter := &JSONFormatter{} - - b, err := formatter.Format(WithField("level", "something")) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - s := string(b) - if !strings.Contains(s, FieldKeyTime) { - t.Error("Timestamp not present", s) - } -} |