-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloki_client_test.go
72 lines (65 loc) · 1.37 KB
/
loki_client_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
package wasp
import (
"errors"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func lokiLogTupleMsg() []interface{} {
// Loki log entry is a tuple, 9th element is Status, 13th is errors.Error
logMsg := make([]interface{}, 13)
for i := 0; i < 13; i++ {
logMsg = append(logMsg, errors.New("fatal error"))
}
return logMsg
}
func TestSmokeLokiFailIfURLIsNotResolving(t *testing.T) {
cfg := NewEnvLokiConfig()
cfg.URL = "http://nothing:3000"
_, err := NewLokiClient(cfg)
require.Error(t, err)
}
func TestLokiErrors(t *testing.T) {
type testcase struct {
name string
maxErrors int
mustError bool
}
tests := []testcase{
{
name: "must ignore all the errors",
maxErrors: -1,
},
{
name: "must continue, but log errors",
maxErrors: 2,
},
{
name: "must return an error",
mustError: true,
maxErrors: 1,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
cfg := NewEnvLokiConfig()
cfg.MaxErrors = tc.maxErrors
lc, err := NewLokiClient(cfg)
require.NoError(t, err)
defer lc.StopNow()
_ = lc.logWrapper.Log(lokiLogTupleMsg()...)
_ = lc.logWrapper.Log(lokiLogTupleMsg()...)
q := struct {
Name string
}{
Name: "test",
}
err = lc.HandleStruct(nil, time.Now(), q)
if tc.mustError {
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
}
}