Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/loki/source/gcplog/internal/gcplogtarget/push_translation_test.go
4096 views
1
package gcplogtarget
2
3
import (
4
"testing"
5
)
6
7
func TestConvertToLokiCompatibleLabel(t *testing.T) {
8
type args struct {
9
label string
10
}
11
tests := []struct {
12
name string
13
args args
14
want string
15
}{
16
{
17
name: "Google timestamp label attribute name",
18
args: args{
19
label: "logging.googleapis.com/timestamp",
20
},
21
want: "logging_googleapis_com_timestamp",
22
},
23
{
24
name: "Label attribute name with multiple non-underscore characters",
25
args: args{
26
label: "logging.googleapis.com/Crazy-label",
27
},
28
want: "logging_googleapis_com_crazy_label",
29
},
30
{
31
name: "Label attribute name in CamelCase converted into SnakeCase",
32
args: args{
33
label: "logging.googleapis.com/CrazyLabel",
34
},
35
want: "logging_googleapis_com_crazy_label",
36
},
37
}
38
for _, tt := range tests {
39
t.Run(tt.name, func(t *testing.T) {
40
if got := convertToLokiCompatibleLabel(tt.args.label); got != tt.want {
41
t.Errorf("convertToLokiCompatibleLabel() = %v, want %v", got, tt.want)
42
}
43
})
44
}
45
}
46
47