-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathui_test.go
More file actions
53 lines (45 loc) · 1.25 KB
/
ui_test.go
File metadata and controls
53 lines (45 loc) · 1.25 KB
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
package log
import (
"testing"
"github.com/stretchr/testify/assert"
"golang.org/x/xerrors"
)
func TestMain(m *testing.M) {
OutputToBuf()
MainTest(m)
}
func TestInfo(t *testing.T) {
SetDebugVisible(FormatPython)
Info("Python")
assert.True(t, containsStdOut("[+] Python\n"))
SetDebugVisible(FormatNone)
Info("None")
assert.True(t, containsStdOut("None\n"))
Info("None", "Python")
assert.True(t, containsStdOut("None Python\n"))
SetDebugVisible(1)
}
func TestError(t *testing.T) {
SetDebugVisible(1)
Error(xerrors.New("error with stack"))
assert.Contains(t, GetStdErr(), "/log/ui_test.go:")
Error(xerrors.New("test"), "and another message")
assert.NotContains(t, GetStdErr(), "/log/ui_test.go:")
}
func TestLvl(t *testing.T) {
SetDebugVisible(1)
Info("TestLvl")
assert.Contains(t, GetStdOut(), "I : fake_name.go:0 (log.TestLvl) - TestLvl\n")
Print("TestLvl")
assert.Contains(t, GetStdOut(), "I : fake_name.go:0 (log.TestLvl) - TestLvl\n")
Warn("TestLvl")
assert.Contains(t, GetStdErr(), "W : fake_name.go:0 (log.TestLvl) - TestLvl\n")
}
func TestPanic(t *testing.T) {
assert.PanicsWithValue(t, "", func() {
Panic()
})
assert.PanicsWithValue(t, "the number is 1", func() {
Panic("the number is ", 1)
})
}