2
0

add tests for yaml and toml in addition to the existing json test

This commit is contained in:
Nate Finch
2014-06-18 14:16:12 -04:00
parent 72cc861377
commit 9b971d9efa
+45 -1
View File
@@ -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.