add tests for yaml and toml in addition to the existing json test
This commit is contained in:
+45
-1
@@ -8,6 +8,9 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/BurntSushi/toml"
|
||||||
|
"gopkg.in/yaml.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// !!!NOTE!!!
|
// !!!NOTE!!!
|
||||||
@@ -495,7 +498,7 @@ func TestRotate(t *testing.T) {
|
|||||||
existsWithLen(filename3, n, t)
|
existsWithLen(filename3, n, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnmarshal(t *testing.T) {
|
func TestJson(t *testing.T) {
|
||||||
data := []byte(`
|
data := []byte(`
|
||||||
{
|
{
|
||||||
"dir": "foo",
|
"dir": "foo",
|
||||||
@@ -517,6 +520,47 @@ func TestUnmarshal(t *testing.T) {
|
|||||||
equals(true, l.LocalTime, 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.
|
// 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
|
// 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.
|
// colliding, and must be cleaned up after the test is finished.
|
||||||
|
|||||||
Reference in New Issue
Block a user