Skip to content

Commit

Permalink
add tests for yaml and toml in addition to the existing json test
Browse files Browse the repository at this point in the history
  • Loading branch information
natefinch committed Jun 18, 2014
1 parent 72cc861 commit 9b971d9
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion lumberjack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"path/filepath"
"testing"
"time"

"github.com/BurntSushi/toml"
"gopkg.in/yaml.v1"
)

// !!!NOTE!!!
Expand Down Expand Up @@ -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",
Expand All @@ -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.
Expand Down

0 comments on commit 9b971d9

Please sign in to comment.