2020-10-01 10:39:42 +02:00
|
|
|
package metricutil
|
2020-09-30 20:12:57 +02:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestLabelNameSanitization(t *testing.T) {
|
|
|
|
|
testcases := []struct {
|
|
|
|
|
input string
|
|
|
|
|
expected string
|
|
|
|
|
err bool
|
|
|
|
|
}{
|
|
|
|
|
{input: "job", expected: "job"},
|
|
|
|
|
{input: "job._loal['", expected: "job_loal"},
|
|
|
|
|
{input: "", expected: "", err: true},
|
|
|
|
|
{input: ";;;", expected: "", err: true},
|
|
|
|
|
{input: "Data source", expected: "Data_source"},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testcases {
|
|
|
|
|
got, err := SanitizeLabelName(tc.input)
|
|
|
|
|
if tc.err {
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
} else {
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, tc.expected, got)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|