mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-10-05 10:05:47 +00:00
nodes: improve handling of erroneous host names
This commit is contained in:
@@ -89,3 +89,35 @@ func TestGetPreferredAddress(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetHostname(t *testing.T) {
|
||||
testCases := []struct {
|
||||
hostName string
|
||||
expectedHostName string
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
hostName: " ",
|
||||
expectError: true,
|
||||
},
|
||||
{
|
||||
hostName: " abc ",
|
||||
expectedHostName: "abc",
|
||||
expectError: false,
|
||||
},
|
||||
}
|
||||
|
||||
for idx, test := range testCases {
|
||||
hostName, err := GetHostname(test.hostName)
|
||||
if err != nil && !test.expectError {
|
||||
t.Errorf("[%d]: unexpected error: %s", idx, err)
|
||||
}
|
||||
if err == nil && test.expectError {
|
||||
t.Errorf("[%d]: expected error, got none", idx)
|
||||
}
|
||||
if test.expectedHostName != hostName {
|
||||
t.Errorf("[%d]: expected output %q, got %q", idx, test.expectedHostName, hostName)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user