From 9b971d9efa56df2d97ca06d46db9bac9519bc2d1 Mon Sep 17 00:00:00 2001 From: Nate Finch Date: Wed, 18 Jun 2014 14:16:12 -0400 Subject: [PATCH] add tests for yaml and toml in addition to the existing json test --- lumberjack_test.go | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/lumberjack_test.go b/lumberjack_test.go index 1e706b6..7ba1e44 100644 --- a/lumberjack_test.go +++ b/lumberjack_test.go @@ -8,6 +8,9 @@ import ( "path/filepath" "testing" "time" + + "github.com/BurntSushi/toml" + "gopkg.in/yaml.v1" ) // !!!NOTE!!! @@ -495,7 +498,7 @@ func TestRotate(t *testing.T) { existsWithLen(filename3, n, t) } -func TestUnmarshal(t *testing.T) { +func TestJson(t *testing.T) { data := []byte(` { "dir": "foo", @@ -517,6 +520,47 @@ func TestUnmarshal(t *testing.T) { equals(true, l.LocalTime, t) } +func TestYaml(t *testing.T) { + data := []byte(` +dir: foo +nameformat: bar +maxsize: 5 +maxage: 10 +maxbackups: 3 +localtime: true`[1:]) + + l := Logger{} + err := yaml.Unmarshal(data, &l) + isNil(err, t) + equals("foo", l.Dir, t) + equals("bar", l.NameFormat, t) + equals(int64(5), l.MaxSize, t) + equals(10, l.MaxAge, t) + equals(3, l.MaxBackups, t) + equals(true, l.LocalTime, t) +} + +func TestToml(t *testing.T) { + data := ` +dir = "foo" +nameformat = "bar" +maxsize = 5 +maxage = 10 +maxbackups = 3 +localtime = true`[1:] + + l := Logger{} + md, err := toml.Decode(data, &l) + isNil(err, t) + equals("foo", l.Dir, t) + equals("bar", l.NameFormat, t) + equals(int64(5), l.MaxSize, t) + equals(10, l.MaxAge, t) + equals(3, l.MaxBackups, t) + equals(true, l.LocalTime, t) + equals(0, len(md.Undecoded()), t) +} + // makeTempDir creates a file with a semi-unique name in the OS temp directory. // It should be based on the name of the test, to keep parallel tests from // colliding, and must be cleaned up after the test is finished.