Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c45a7ba4
Commit
c45a7ba4
authored
Sep 25, 2017
by
sakeven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix netsh checkIPExists in Chinese
Signed-off-by:
sakeven
<
jc5930@sina.cn
>
parent
d9459270
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
3 deletions
+38
-3
netsh.go
pkg/util/netsh/netsh.go
+11
-3
netsh_test.go
pkg/util/netsh/netsh_test.go
+27
-0
No files found.
pkg/util/netsh/netsh.go
View file @
c45a7ba4
...
...
@@ -190,9 +190,8 @@ func checkIPExists(ipToCheck string, args []string, runner *runner) (bool, error
glog
.
V
(
3
)
.
Infof
(
"Searching for IP: %v in IP dump: %v"
,
ipToCheck
,
ipAddressString
)
showAddressArray
:=
strings
.
Split
(
ipAddressString
,
"
\n
"
)
for
_
,
showAddress
:=
range
showAddressArray
{
if
strings
.
Contains
(
showAddress
,
"IP Address:"
)
{
ipFromNetsh
:=
strings
.
TrimLeft
(
showAddress
,
"IP Address:"
)
ipFromNetsh
=
strings
.
TrimSpace
(
ipFromNetsh
)
if
strings
.
Contains
(
showAddress
,
"IP"
)
{
ipFromNetsh
:=
getIP
(
showAddress
)
if
ipFromNetsh
==
ipToCheck
{
return
true
,
nil
}
...
...
@@ -201,3 +200,12 @@ func checkIPExists(ipToCheck string, args []string, runner *runner) (bool, error
return
false
,
nil
}
// getIP gets ip from showAddress (e.g. "IP Address: 10.96.0.4").
func
getIP
(
showAddress
string
)
string
{
list
:=
strings
.
SplitN
(
showAddress
,
":"
,
2
)
if
len
(
list
)
!=
2
{
return
""
}
return
strings
.
TrimSpace
(
list
[
1
])
}
pkg/util/netsh/netsh_test.go
View file @
c45a7ba4
...
...
@@ -438,3 +438,30 @@ func TestCheckIPExists(t *testing.T) {
}
}
}
func
TestGetIP
(
t
*
testing
.
T
)
{
testcases
:=
[]
struct
{
showAddress
string
expectAddress
string
}{
{
showAddress
:
"IP 地址: 10.96.0.2"
,
expectAddress
:
"10.96.0.2"
,
},
{
showAddress
:
"IP Address: 10.96.0.3"
,
expectAddress
:
"10.96.0.3"
,
},
{
showAddress
:
"IP Address:10.96.0.4"
,
expectAddress
:
"10.96.0.4"
,
},
}
for
_
,
tc
:=
range
testcases
{
address
:=
getIP
(
tc
.
showAddress
)
if
address
!=
tc
.
expectAddress
{
t
.
Errorf
(
"expected address=%q, got %q"
,
tc
.
expectAddress
,
address
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment