-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging_test.go
78 lines (60 loc) · 1.48 KB
/
logging_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
package loki
import (
"golang.org/x/exp/slices"
"strings"
"testing"
)
func TestStringer(t *testing.T) {
l := LokiLogger{
Endpoint: "https://foo:[email protected]",
}
if strings.Contains(l.String(), "bar") {
t.Errorf("Expected String() to redact HTTP Basic password: %s", l.String())
}
}
func TestWriterKeyWithDifferentEndpoints(t *testing.T) {
tests := []string{
"http://user:[email protected]",
"https://user:[email protected]",
"https://example.com",
"https://127.0.0.1:3000",
"http://127.0.0.1",
}
var prev []string
logger := LokiLogger{}
for _, endpoint := range tests {
logger.Endpoint = endpoint
key := logger.WriterKey()
if slices.Contains(prev, key) {
idx := slices.Index(prev, key)
t.Errorf("Expected WriterKey to be unique, got %s for endpoint %s which is the same as for case: \n %+v", key, endpoint, tests[idx])
continue
}
prev = append(prev, key)
}
}
func TestWriterKeyWithDifferentLabels(t *testing.T) {
tests := []map[string]interface{}{
{
"foo": "bar",
},
{
"another": "test",
"var": "val",
},
}
var prev []string
logger := LokiLogger{
Endpoint: "https://test.example.com",
}
for _, labels := range tests {
key := logger.WriterKey()
logger.Labels = labels
if slices.Contains(prev, key) {
idx := slices.Index(prev, key)
t.Errorf("Expected WriterKey to be unique, got %s for labels %s which is the same as for case: \n %+v", key, labels, tests[idx])
continue
}
prev = append(prev, key)
}
}