-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
91 lines (77 loc) · 2.45 KB
/
main_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
package main
import (
"bytes"
"fmt"
"testing"
"github.com/senzing-garage/go-logging/logger"
"github.com/senzing-garage/go-logging/logging"
"github.com/stretchr/testify/assert"
)
var (
componentIdentifier = 9999
idMessagesTest = map[int]string{
0001: "Info for %s",
1000: "Warning for %s",
2000: "Error for %s",
}
outputString = new(bytes.Buffer) // *bytes.Buffer
)
func TestMain(test *testing.T) {
_ = test
main()
}
// ----------------------------------------------------------------------------
// Test interface functions for New
// ----------------------------------------------------------------------------
func TestNew(test *testing.T) {
_ = test
expected := `{"level":"INFO","id":"2000"}` + "\n"
outputString.Reset()
logger, _ := logging.New(optionOutput(), optionTimeHidden())
logger.Log(1, "Mary")
logger.Log(1000, "Jane")
logger.Log(2000, "Bob")
assert.Equal(test, expected, outputString.String())
}
// ----------------------------------------------------------------------------
// Test interface functions for NewSenzingLogger
// ----------------------------------------------------------------------------
func TestNewSenzingLogger(test *testing.T) {
_ = test
expected := `{"level":"INFO","id":"SZTL99992000"}` + "\n"
outputString.Reset()
logger, _ := logging.NewSenzingLogger(componentIdentifier, idMessagesTest, optionOutput(), optionTimeHidden())
logger.Log(1, "Mary")
logger.Log(1000, "Jane")
logger.Log(2000, "Bob")
assert.Equal(test, expected, outputString.String())
}
func TestNewSenzingLoggerAtErrorLevel(test *testing.T) {
_ = test
expected := ""
outputString.Reset()
loggerOptions := []interface{}{
logging.OptionLogLevel{Value: logger.LevelErrorName},
logging.OptionOutput{Value: outputString},
logging.OptionTimeHidden{Value: true},
}
logger, _ := logging.NewSenzingLogger(componentIdentifier, idMessagesTest, loggerOptions...)
logger.Log(1, "Mary")
logger.Log(1000, "Jane")
logger.Log(2000, "Bob")
assert.Equal(test, expected, outputString.String())
fmt.Println(">>>> ", outputString)
}
// ----------------------------------------------------------------------------
// Internal functions - names begin with lowercase letter
// ----------------------------------------------------------------------------
func optionOutput() logging.OptionOutput {
return logging.OptionOutput{
Value: outputString,
}
}
func optionTimeHidden() logging.OptionTimeHidden {
return logging.OptionTimeHidden{
Value: true,
}
}