forked from kreuzwerker/envplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_test.go
62 lines (44 loc) · 1.3 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
50
51
52
53
54
55
56
57
58
59
60
61
62
package envplate
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLog(t *testing.T) {
reset := func(v bool) {
Logger.Verbose = v
}
defer reset(Logger.Verbose)
reset(false)
_redirect_logs(func(logs func() string, raw func() string) {
assert := assert.New(t)
err := Log(RAW, "Hello raw world")
assert.NoError(err)
assert.Empty(logs())
assert.Equal(raw(), "Hello raw world")
err = Log(DEBUG, "Hello debug world")
assert.NoError(err)
assert.Empty(logs())
err = Log(INFO, "Hello info world")
assert.NoError(err)
assert.NotEmpty(logs())
err = Log(ERROR, "Hello error world")
assert.Error(err)
assert.Equal(errors.New("Hello error world"), err)
assert.NotEmpty(logs())
Logger.Verbose = true
err = Log(DEBUG, "Hello debug world")
assert.NoError(err)
assert.Regexp(".+ \\[ DEBUG \\] Hello debug world", logs())
err = Log(DEBUG, "Hello %s %s", "debug", "world")
assert.NoError(err)
assert.Regexp(".+ \\[ DEBUG \\] Hello debug world", logs())
err = Log(INFO, "Hello info world")
assert.NoError(err)
assert.Regexp(".+ \\[ INFO \\] Hello info world", logs())
err = Log(ERROR, "Hello error world")
assert.Error(err)
assert.Equal(errors.New("Hello error world"), err)
assert.Regexp(".+ \\[ ERROR \\] Hello error world", logs())
})
}