-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger_test.go
More file actions
52 lines (38 loc) · 1.22 KB
/
logger_test.go
File metadata and controls
52 lines (38 loc) · 1.22 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
package main
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLogger_InfoDryRun(t *testing.T) {
t.Parallel()
var buf bytes.Buffer
logger := NewLogger(false)
logger.SetOutput(&buf)
logger.InfoDryRun("Would update (%d):", 5)
output := buf.String()
assert.Contains(t, output, "→", "Should contain arrow icon")
assert.Contains(t, output, "Would update (5)", "Should contain message")
}
func TestLogger_InfoDryRunWithColor(t *testing.T) {
t.Parallel()
var buf bytes.Buffer
logger := NewLogger(true)
logger.SetOutput(&buf)
logger.InfoDryRun("Test message")
output := buf.String()
assert.Contains(t, output, "→", "Should contain arrow icon")
assert.Contains(t, output, "Test message", "Should contain message")
}
func TestLogger_InfoDryRunBelowLevel(t *testing.T) {
t.Parallel()
var buf bytes.Buffer
logger := NewLogger(false) // LogLevelInfo
logger.SetOutput(&buf)
// Set level to LogLevelError - InfoDryRun should not output
logger.level = LogLevelError
logger.InfoDryRun("Should not appear")
output := buf.String()
assert.NotContains(t, output, "Should not appear", "Should not log when below level")
assert.NotContains(t, output, "→", "Should not contain arrow when below level")
}