mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-11 17:04:22 -05:00
64 lines
1015 B
Go
64 lines
1015 B
Go
|
/*
|
||
|
Copyright (c) Edgeless Systems GmbH
|
||
|
|
||
|
SPDX-License-Identifier: AGPL-3.0-only
|
||
|
*/
|
||
|
|
||
|
package kubernetes
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"go.uber.org/goleak"
|
||
|
)
|
||
|
|
||
|
func TestMain(m *testing.M) {
|
||
|
goleak.VerifyTestMain(m)
|
||
|
}
|
||
|
|
||
|
func TestK8sCompliantHostname(t *testing.T) {
|
||
|
testCases := map[string]struct {
|
||
|
input string
|
||
|
expected string
|
||
|
wantErr bool
|
||
|
}{
|
||
|
"no change": {
|
||
|
input: "test",
|
||
|
expected: "test",
|
||
|
},
|
||
|
"uppercase": {
|
||
|
input: "TEST",
|
||
|
expected: "test",
|
||
|
},
|
||
|
"underscore": {
|
||
|
input: "test_node",
|
||
|
expected: "test-node",
|
||
|
},
|
||
|
"empty": {
|
||
|
input: "",
|
||
|
expected: "",
|
||
|
wantErr: true,
|
||
|
},
|
||
|
"error": {
|
||
|
input: "test_node_",
|
||
|
expected: "",
|
||
|
wantErr: true,
|
||
|
},
|
||
|
}
|
||
|
|
||
|
for name, tc := range testCases {
|
||
|
t.Run(name, func(t *testing.T) {
|
||
|
assert := assert.New(t)
|
||
|
|
||
|
actual, err := k8sCompliantHostname(tc.input)
|
||
|
if tc.wantErr {
|
||
|
assert.Error(err)
|
||
|
return
|
||
|
}
|
||
|
assert.NoError(err)
|
||
|
assert.Equal(tc.expected, actual)
|
||
|
})
|
||
|
}
|
||
|
}
|