|
|
@ -851,3 +851,52 @@ func BenchmarkRelabel(b *testing.B) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestConfig_UnmarshalThenMarshal(t *testing.T) {
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
|
|
|
name string
|
|
|
|
|
|
|
|
inputYaml string
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "Values provided",
|
|
|
|
|
|
|
|
inputYaml: `source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_port]
|
|
|
|
|
|
|
|
separator: ;
|
|
|
|
|
|
|
|
regex: \\d+
|
|
|
|
|
|
|
|
target_label: __meta_kubernetes_pod_container_port_number
|
|
|
|
|
|
|
|
replacement: $1
|
|
|
|
|
|
|
|
action: replace
|
|
|
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "No regex provided",
|
|
|
|
|
|
|
|
inputYaml: `source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_port]
|
|
|
|
|
|
|
|
separator: ;
|
|
|
|
|
|
|
|
target_label: __meta_kubernetes_pod_container_port_number
|
|
|
|
|
|
|
|
replacement: $1
|
|
|
|
|
|
|
|
action: keepequal
|
|
|
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "Default regex provided",
|
|
|
|
|
|
|
|
inputYaml: `source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_port]
|
|
|
|
|
|
|
|
separator: ;
|
|
|
|
|
|
|
|
regex: (.*)
|
|
|
|
|
|
|
|
target_label: __meta_kubernetes_pod_container_port_number
|
|
|
|
|
|
|
|
replacement: $1
|
|
|
|
|
|
|
|
action: replace
|
|
|
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
|
|
|
|
unmarshalled := Config{}
|
|
|
|
|
|
|
|
err := yaml.Unmarshal([]byte(test.inputYaml), &unmarshalled)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
marshalled, err := yaml.Marshal(&unmarshalled)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require.Equal(t, test.inputYaml, string(marshalled))
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|