/
logLineWrapperFormatter_test.go
70 lines (49 loc) · 1.6 KB
/
logLineWrapperFormatter_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
package logger_test
import (
"errors"
"testing"
logger "github.com/Reshusk23/dme-go-logger"
"github.com/Reshusk23/dme-go-logger/check"
"github.com/Reshusk23/dme-go-logger/mock"
"github.com/stretchr/testify/assert"
)
func TestNewLogLineWrapperFormatter_NilMarshalizerShouldErr(t *testing.T) {
t.Parallel()
llwf, err := logger.NewLogLineWrapperFormatter(nil)
assert.True(t, check.IfNil(llwf))
assert.Equal(t, logger.ErrNilMarshalizer, err)
}
func TestNewLogLineWrapperFormatter_ShouldWork(t *testing.T) {
t.Parallel()
llwf, err := logger.NewLogLineWrapperFormatter(&mock.MarshalizerStub{})
assert.False(t, check.IfNil(llwf))
assert.Nil(t, err)
}
//------- Output
func TestLogLineWrapperFormatter_OutputNilLogLineWrapperShouldRetNil(t *testing.T) {
t.Parallel()
llwf, _ := logger.NewLogLineWrapperFormatter(&mock.MarshalizerStub{})
buff := llwf.Output(nil)
assert.Nil(t, buff)
}
func TestLogLineWrapperFormatter_OutputMarshalizerErrorsShouldRetNil(t *testing.T) {
t.Parallel()
llwf, _ := logger.NewLogLineWrapperFormatter(&mock.MarshalizerStub{
MarshalCalled: func(obj interface{}) (bytes []byte, e error) {
return nil, errors.New("")
},
})
buff := llwf.Output(&logger.LogLineWrapper{})
assert.Nil(t, buff)
}
func TestLogLineWrapperFormatter_OutputShouldWork(t *testing.T) {
t.Parallel()
marshalizedData := []byte("test data")
llwf, _ := logger.NewLogLineWrapperFormatter(&mock.MarshalizerStub{
MarshalCalled: func(obj interface{}) (bytes []byte, e error) {
return marshalizedData, nil
},
})
buff := llwf.Output(&logger.LogLineWrapper{})
assert.Equal(t, marshalizedData, buff)
}