mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
33 lines
666 B
Go
33 lines
666 B
Go
package metricutil
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|