Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/loki/source/kubernetes/kubetail/tailer_test.go
4096 views
1
package kubetail
2
3
import (
4
"testing"
5
"time"
6
7
"github.com/stretchr/testify/require"
8
)
9
10
func Test_parseKubernetesLog(t *testing.T) {
11
tt := []struct {
12
inputLine string
13
expectTS time.Time
14
expectLine string
15
}{
16
{
17
// Test normal RFC3339Nano log line.
18
inputLine: `2023-01-23T17:00:10.000000001Z hello, world!`,
19
expectTS: time.Date(2023, time.January, 23, 17, 0, 10, 1, time.UTC),
20
expectLine: "hello, world!",
21
},
22
{
23
// Test normal RFC3339 log line.
24
inputLine: `2023-01-23T17:00:10Z hello, world!`,
25
expectTS: time.Date(2023, time.January, 23, 17, 0, 10, 0, time.UTC),
26
expectLine: "hello, world!",
27
},
28
{
29
// Test empty log line. There will always be a space prepended by
30
// Kubernetes.
31
inputLine: `2023-01-23T17:00:10.000000001Z `,
32
expectTS: time.Date(2023, time.January, 23, 17, 0, 10, 1, time.UTC),
33
expectLine: "",
34
},
35
}
36
37
for _, tc := range tt {
38
t.Run(tc.inputLine, func(t *testing.T) {
39
actualTS, actualLine := parseKubernetesLog(tc.inputLine)
40
require.Equal(t, tc.expectTS, actualTS)
41
require.Equal(t, tc.expectLine, actualLine)
42
})
43
}
44
}
45
46