fix: hostname for instance

This commit is contained in:
Qu Xuan
2020-10-16 17:05:26 +08:00
parent cfbb8458ee
commit 65582cab95
6 changed files with 133 additions and 20 deletions

View File

@@ -17,6 +17,8 @@ package stringutils2
import (
"reflect"
"testing"
"yunion.io/x/pkg/util/osprofile"
)
func TestEscapeString(t *testing.T) {
@@ -120,3 +122,47 @@ func TestEscapeEchoString(t *testing.T) {
})
}
}
func TestGenerateHostName(t *testing.T) {
type input struct {
name string
osType string
hostName string
}
for _, pair := range []input{
input{
name: "--test-host-name.......",
hostName: "test-host-name",
},
input{
name: "--test-host-1234567890-name.......",
osType: osprofile.OS_TYPE_WINDOWS,
hostName: "test-host-12345",
},
input{
name: "--test-host-1234-67890-name.......",
osType: osprofile.OS_TYPE_WINDOWS,
hostName: "test-host-1234",
},
input{
name: "1234567890123456",
osType: osprofile.OS_TYPE_WINDOWS,
hostName: "host-1234567890",
},
input{
name: "001234567890123456",
osType: osprofile.OS_TYPE_WINDOWS,
hostName: "host-0012345678",
},
input{
name: "",
hostName: "hostname-for",
},
} {
hostName := GenerateHostName(pair.name, pair.osType)
if hostName != pair.hostName {
t.Fatalf("%s hostName should be %s, current is %s", pair.name, pair.hostName, hostName)
}
}
}