mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +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) {
|
func TestGetIP(t *testing.T) {
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
|
name string
|
||||||
showAddress string
|
showAddress string
|
||||||
expectAddress string
|
expectAddress string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "IP address displayed in Chinese",
|
||||||
showAddress: "IP 地址: 10.96.0.2",
|
showAddress: "IP 地址: 10.96.0.2",
|
||||||
expectAddress: "10.96.0.2",
|
expectAddress: "10.96.0.2",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "IP address displayed in English",
|
||||||
showAddress: "IP Address: 10.96.0.3",
|
showAddress: "IP Address: 10.96.0.3",
|
||||||
expectAddress: "10.96.0.3",
|
expectAddress: "10.96.0.3",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "IP address without spaces",
|
||||||
showAddress: "IP Address:10.96.0.4",
|
showAddress: "IP Address:10.96.0.4",
|
||||||
expectAddress: "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 {
|
for _, tc := range testcases {
|
||||||
address := getIP(tc.showAddress)
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
if address != tc.expectAddress {
|
address := getIP(tc.showAddress)
|
||||||
t.Errorf("expected address=%q, got %q", tc.expectAddress, address)
|
if address != tc.expectAddress {
|
||||||
}
|
t.Errorf("expected address=%q, got %q", tc.expectAddress, address)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user