Path: blob/main/component/loki/source/kubernetes/kubetail/tailer_test.go
4096 views
package kubetail12import (3"testing"4"time"56"github.com/stretchr/testify/require"7)89func Test_parseKubernetesLog(t *testing.T) {10tt := []struct {11inputLine string12expectTS time.Time13expectLine string14}{15{16// Test normal RFC3339Nano log line.17inputLine: `2023-01-23T17:00:10.000000001Z hello, world!`,18expectTS: time.Date(2023, time.January, 23, 17, 0, 10, 1, time.UTC),19expectLine: "hello, world!",20},21{22// Test normal RFC3339 log line.23inputLine: `2023-01-23T17:00:10Z hello, world!`,24expectTS: time.Date(2023, time.January, 23, 17, 0, 10, 0, time.UTC),25expectLine: "hello, world!",26},27{28// Test empty log line. There will always be a space prepended by29// Kubernetes.30inputLine: `2023-01-23T17:00:10.000000001Z `,31expectTS: time.Date(2023, time.January, 23, 17, 0, 10, 1, time.UTC),32expectLine: "",33},34}3536for _, tc := range tt {37t.Run(tc.inputLine, func(t *testing.T) {38actualTS, actualLine := parseKubernetesLog(tc.inputLine)39require.Equal(t, tc.expectTS, actualTS)40require.Equal(t, tc.expectLine, actualLine)41})42}43}444546