forked from ortuman/jackal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger_test.go
49 lines (38 loc) · 1.12 KB
/
logger_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (c) 2018 Miguel Ángel Ortuño.
* See the LICENSE file for more information.
*/
package config
import (
"testing"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
)
func TestLoggerConfig(t *testing.T) {
l := Logger{}
err := yaml.Unmarshal([]byte("{level: debug}"), &l)
require.Nil(t, err)
require.Equal(t, DebugLevel, l.Level)
err = yaml.Unmarshal([]byte("{level: info}"), &l)
require.Nil(t, err)
require.Equal(t, InfoLevel, l.Level)
err = yaml.Unmarshal([]byte("{level: warning}"), &l)
require.Nil(t, err)
require.Equal(t, WarningLevel, l.Level)
err = yaml.Unmarshal([]byte("{level: error}"), &l)
require.Nil(t, err)
require.Equal(t, ErrorLevel, l.Level)
err = yaml.Unmarshal([]byte("{level: fatal}"), &l)
require.Nil(t, err)
require.Equal(t, FatalLevel, l.Level)
err = yaml.Unmarshal([]byte("{level: invalid}"), &l)
require.NotNil(t, err)
err = yaml.Unmarshal([]byte("{log_path: jackal.log}"), &l)
require.Nil(t, err)
require.Equal(t, "jackal.log", l.LogPath)
}
func TestLoggerBadConfig(t *testing.T) {
l := Logger{}
err := yaml.Unmarshal([]byte("level"), &l)
require.NotNil(t, err)
}