-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
105 lines (94 loc) · 1.97 KB
/
utils_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package cipherPayload
import (
"bytes"
"os"
"testing"
"github.com/rs/zerolog/log"
"github.com/stretchr/testify/require"
)
func captureOutput(f func()) string {
var buf bytes.Buffer
log.Logger = log.Output(&buf)
defer func() {
log.Logger = log.Output(os.Stderr)
}()
f()
return buf.String()
}
type testCaseIsExist struct {
name string
inputArr []string
inputStr string
expected bool
}
func TestIsExist(t *testing.T) {
tests := []testCaseIsExist{
{
name: "Empty Case",
inputArr: []string{},
inputStr: "",
expected: false,
},
{
name: "Valid Case",
inputArr: []string{"1", "2", "3"},
inputStr: "1",
expected: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
inputArr := test.inputArr
inputStr := test.inputStr
expected := test.expected
actual := isExist(inputArr, inputStr)
require.Equal(t, expected, actual)
})
}
}
type testCaseLogger struct {
name string
inputLogType string
inputLogMessage string
expected string
}
func TestLogger(t *testing.T) {
tests := []testCaseLogger{
{
name: "Default Case",
inputLogType: "",
inputLogMessage: "",
expected: "",
},
{
name: "Log Error Case",
inputLogType: "error",
inputLogMessage: "test error",
expected: "test error",
},
{
name: "Log Info Case",
inputLogType: "info",
inputLogMessage: "test info",
expected: "test info",
},
{
name: "Log Debug Case",
inputLogType: "debug",
inputLogMessage: "test debug",
expected: "test debug",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
inputLogType := test.inputLogType
inputLogMessage := test.inputLogMessage
expected := test.expected
actual := captureOutput(func() {
logger := newLogger(true)
logger.printf(inputLogType, inputLogMessage)
})
require.Contains(t, actual, expected)
})
}
}