mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Merge pull request #108655 from mengjiao-liu/improve_netsh_test
Improve unit test coverage in `pkg/util/netsh/`
This commit is contained in:
commit
cdee77a4a9
@ -441,27 +441,43 @@ func TestCheckIPExists(t *testing.T) {
|
||||
|
||||
func TestGetIP(t *testing.T) {
|
||||
testcases := []struct {
|
||||
name string
|
||||
showAddress string
|
||||
expectAddress string
|
||||
}{
|
||||
{
|
||||
name: "IP address displayed in Chinese",
|
||||
showAddress: "IP 地址: 10.96.0.2",
|
||||
expectAddress: "10.96.0.2",
|
||||
},
|
||||
{
|
||||
name: "IP address displayed in English",
|
||||
showAddress: "IP Address: 10.96.0.3",
|
||||
expectAddress: "10.96.0.3",
|
||||
},
|
||||
{
|
||||
name: "IP address without spaces",
|
||||
showAddress: "IP Address:10.96.0.4",
|
||||
expectAddress: "10.96.0.4",
|
||||
},
|
||||
{
|
||||
name: "Only 'IP Address:' field exists",
|
||||
showAddress: "IP Address:",
|
||||
expectAddress: "",
|
||||
},
|
||||
{
|
||||
name: "IP address without ':' separator",
|
||||
showAddress: "IP Address10.6.9.2",
|
||||
expectAddress: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testcases {
|
||||
address := getIP(tc.showAddress)
|
||||
if address != tc.expectAddress {
|
||||
t.Errorf("expected address=%q, got %q", tc.expectAddress, address)
|
||||
}
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
address := getIP(tc.showAddress)
|
||||
if address != tc.expectAddress {
|
||||
t.Errorf("expected address=%q, got %q", tc.expectAddress, address)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user