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
f3715bbb
Commit
f3715bbb
authored
May 03, 2019
by
Andrew Sy Kim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ipvs: add descriptions to ipset unit tests
Signed-off-by:
Andrew Sy Kim
<
kiman@vmware.com
>
parent
f780ac02
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
49 deletions
+68
-49
ipset_test.go
pkg/proxy/ipvs/ipset_test.go
+68
-49
No files found.
pkg/proxy/ipvs/ipset_test.go
View file @
f3715bbb
...
@@ -25,29 +25,30 @@ import (
...
@@ -25,29 +25,30 @@ import (
func
TestCheckIPSetVersion
(
t
*
testing
.
T
)
{
func
TestCheckIPSetVersion
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
name
string
vstring
string
vstring
string
valid
bool
valid
bool
}{
}{
// version less than "6.0" is not valid.
{
"4.0 < 6.0 is invalid"
,
"4.0"
,
false
},
{
"4.0"
,
false
},
{
"5.1 < 6.0 is invalid"
,
"5.1"
,
false
},
{
"5.1"
,
false
},
{
"5.2 < 6.0 is invalid"
,
"5.1.2"
,
false
},
{
"5.1.2"
,
false
},
{
"7 is not a valid version"
,
"7"
,
false
},
// "7" is not a valid version string.
{
"6.0 is valid since >= 6.0"
,
"6.0"
,
true
},
{
"7"
,
false
},
{
"6.1 is valid since >= 6.0"
,
"6.1"
,
true
},
{
"6.0"
,
true
},
{
"6.19 is valid since >= 6.0"
,
"6.19"
,
true
},
{
"6.1"
,
true
},
{
"7.0 is valid since >= 6.0"
,
"7.0"
,
true
},
{
"6.19"
,
true
},
{
"8.1.2 is valid since >= 6.0"
,
"8.1.2"
,
true
},
{
"7.0"
,
true
},
{
"9.3.4.0 is valid since >= 6.0"
,
"9.3.4.0"
,
true
},
{
"8.1.2"
,
true
},
{
"not a valid semantic version"
,
"total junk"
,
false
},
{
"9.3.4.0"
,
true
},
{
"total junk"
,
false
},
}
}
for
i
:=
range
testCases
{
for
_
,
testCase
:=
range
testCases
{
valid
:=
checkMinVersion
(
testCases
[
i
]
.
vstring
)
t
.
Run
(
testCase
.
name
,
func
(
t
*
testing
.
T
)
{
if
testCases
[
i
]
.
valid
!=
valid
{
valid
:=
checkMinVersion
(
testCase
.
vstring
)
t
.
Errorf
(
"Expected result: %v, Got result: %v"
,
testCases
[
i
]
.
valid
,
valid
)
if
testCase
.
valid
!=
valid
{
}
t
.
Errorf
(
"Expected result: %v, Got result: %v"
,
testCase
.
valid
,
valid
)
}
})
}
}
}
}
...
@@ -55,6 +56,7 @@ const testIPSetVersion = "v6.19"
...
@@ -55,6 +56,7 @@ const testIPSetVersion = "v6.19"
func
TestSyncIPSetEntries
(
t
*
testing
.
T
)
{
func
TestSyncIPSetEntries
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
name
string
set
*
utilipset
.
IPSet
set
*
utilipset
.
IPSet
setType
utilipset
.
Type
setType
utilipset
.
Type
ipv6
bool
ipv6
bool
...
@@ -62,7 +64,8 @@ func TestSyncIPSetEntries(t *testing.T) {
...
@@ -62,7 +64,8 @@ func TestSyncIPSetEntries(t *testing.T) {
currentEntries
[]
string
currentEntries
[]
string
expectedEntries
[]
string
expectedEntries
[]
string
}{
}{
{
// case 0
{
name
:
"normal ipset sync"
,
set
:
&
utilipset
.
IPSet
{
set
:
&
utilipset
.
IPSet
{
Name
:
"foo"
,
Name
:
"foo"
,
},
},
...
@@ -72,7 +75,8 @@ func TestSyncIPSetEntries(t *testing.T) {
...
@@ -72,7 +75,8 @@ func TestSyncIPSetEntries(t *testing.T) {
currentEntries
:
nil
,
currentEntries
:
nil
,
expectedEntries
:
[]
string
{
"172.17.0.4,tcp:80"
},
expectedEntries
:
[]
string
{
"172.17.0.4,tcp:80"
},
},
},
{
// case 1
{
name
:
"ipset IPv6 sync with no new entries"
,
set
:
&
utilipset
.
IPSet
{
set
:
&
utilipset
.
IPSet
{
Name
:
"abz"
,
Name
:
"abz"
,
},
},
...
@@ -82,7 +86,8 @@ func TestSyncIPSetEntries(t *testing.T) {
...
@@ -82,7 +86,8 @@ func TestSyncIPSetEntries(t *testing.T) {
currentEntries
:
[]
string
{
"FE80::0202:B3FF:FE1E:8329,tcp:80"
},
currentEntries
:
[]
string
{
"FE80::0202:B3FF:FE1E:8329,tcp:80"
},
expectedEntries
:
[]
string
{
"FE80::0202:B3FF:FE1E:8329,tcp:80"
},
expectedEntries
:
[]
string
{
"FE80::0202:B3FF:FE1E:8329,tcp:80"
},
},
},
{
// case 2
{
name
:
"ipset sync with updated udp->tcp in hash"
,
set
:
&
utilipset
.
IPSet
{
set
:
&
utilipset
.
IPSet
{
Name
:
"bca"
,
Name
:
"bca"
,
},
},
...
@@ -92,7 +97,8 @@ func TestSyncIPSetEntries(t *testing.T) {
...
@@ -92,7 +97,8 @@ func TestSyncIPSetEntries(t *testing.T) {
currentEntries
:
[]
string
{
"172.17.0.5,udp:53"
},
currentEntries
:
[]
string
{
"172.17.0.5,udp:53"
},
expectedEntries
:
[]
string
{
"172.17.0.4,tcp:80"
,
"172.17.0.5,tcp:80"
},
expectedEntries
:
[]
string
{
"172.17.0.4,tcp:80"
,
"172.17.0.5,tcp:80"
},
},
},
{
// case 3
{
name
:
"ipset sync no updates required"
,
set
:
&
utilipset
.
IPSet
{
set
:
&
utilipset
.
IPSet
{
Name
:
"bar"
,
Name
:
"bar"
,
},
},
...
@@ -102,7 +108,8 @@ func TestSyncIPSetEntries(t *testing.T) {
...
@@ -102,7 +108,8 @@ func TestSyncIPSetEntries(t *testing.T) {
currentEntries
:
[]
string
{
"172.17.0.4,tcp:80:172.17.0.4"
},
currentEntries
:
[]
string
{
"172.17.0.4,tcp:80:172.17.0.4"
},
expectedEntries
:
[]
string
{
"172.17.0.4,tcp:80:172.17.0.4"
},
expectedEntries
:
[]
string
{
"172.17.0.4,tcp:80:172.17.0.4"
},
},
},
{
// case 4
{
name
:
"ipset IPv6 sync, delete and add new entry"
,
set
:
&
utilipset
.
IPSet
{
set
:
&
utilipset
.
IPSet
{
Name
:
"baz"
,
Name
:
"baz"
,
},
},
...
@@ -112,7 +119,8 @@ func TestSyncIPSetEntries(t *testing.T) {
...
@@ -112,7 +119,8 @@ func TestSyncIPSetEntries(t *testing.T) {
currentEntries
:
[]
string
{
"1111:0000:0000:0000:0202:B3FF:FE1E:8329,tcp:8081:1111:0000:0000:0000:0202:B3FF:FE1E:8329:8081"
},
currentEntries
:
[]
string
{
"1111:0000:0000:0000:0202:B3FF:FE1E:8329,tcp:8081:1111:0000:0000:0000:0202:B3FF:FE1E:8329:8081"
},
expectedEntries
:
[]
string
{
"FE80:0000:0000:0000:0202:B3FF:FE1E:8329,tcp:8080:FE80:0000:0000:0000:0202:B3FF:FE1E:8329"
},
expectedEntries
:
[]
string
{
"FE80:0000:0000:0000:0202:B3FF:FE1E:8329,tcp:8080:FE80:0000:0000:0000:0202:B3FF:FE1E:8329"
},
},
},
{
// case 5
{
name
:
"ipset sync, no current entries"
,
set
:
&
utilipset
.
IPSet
{
set
:
&
utilipset
.
IPSet
{
Name
:
"NOPE"
,
Name
:
"NOPE"
,
},
},
...
@@ -122,7 +130,8 @@ func TestSyncIPSetEntries(t *testing.T) {
...
@@ -122,7 +130,8 @@ func TestSyncIPSetEntries(t *testing.T) {
currentEntries
:
nil
,
currentEntries
:
nil
,
expectedEntries
:
[]
string
{
"172.17.0.4,tcp:80,172.17.0.9"
,
"172.17.0.5,tcp:80,172.17.0.10"
},
expectedEntries
:
[]
string
{
"172.17.0.4,tcp:80,172.17.0.9"
,
"172.17.0.5,tcp:80,172.17.0.10"
},
},
},
{
// case 6
{
name
:
"ipset sync, no current entries with /16 subnet"
,
set
:
&
utilipset
.
IPSet
{
set
:
&
utilipset
.
IPSet
{
Name
:
"ABC-DEF"
,
Name
:
"ABC-DEF"
,
},
},
...
@@ -132,7 +141,8 @@ func TestSyncIPSetEntries(t *testing.T) {
...
@@ -132,7 +141,8 @@ func TestSyncIPSetEntries(t *testing.T) {
currentEntries
:
nil
,
currentEntries
:
nil
,
expectedEntries
:
[]
string
{
"172.17.0.4,tcp:80,172.17.0.0/16"
,
"172.17.0.5,tcp:80,172.17.0.0/16"
},
expectedEntries
:
[]
string
{
"172.17.0.4,tcp:80,172.17.0.0/16"
,
"172.17.0.5,tcp:80,172.17.0.0/16"
},
},
},
{
// case 7
{
name
:
"ipset IPv6 sync, no updates required with /32 subnet"
,
set
:
&
utilipset
.
IPSet
{
set
:
&
utilipset
.
IPSet
{
Name
:
"zar"
,
Name
:
"zar"
,
},
},
...
@@ -142,7 +152,8 @@ func TestSyncIPSetEntries(t *testing.T) {
...
@@ -142,7 +152,8 @@ func TestSyncIPSetEntries(t *testing.T) {
currentEntries
:
[]
string
{
"FE80::8329,tcp:8800,2001:db8::/32"
},
currentEntries
:
[]
string
{
"FE80::8329,tcp:8800,2001:db8::/32"
},
expectedEntries
:
[]
string
{
"FE80::8329,tcp:8800,2001:db8::/32"
},
expectedEntries
:
[]
string
{
"FE80::8329,tcp:8800,2001:db8::/32"
},
},
},
{
// case 8
{
name
:
"ipset IPv6 sync, current entries removed"
,
set
:
&
utilipset
.
IPSet
{
set
:
&
utilipset
.
IPSet
{
Name
:
"bbb"
,
Name
:
"bbb"
,
},
},
...
@@ -152,7 +163,8 @@ func TestSyncIPSetEntries(t *testing.T) {
...
@@ -152,7 +163,8 @@ func TestSyncIPSetEntries(t *testing.T) {
currentEntries
:
[]
string
{
"FE80::8329,udp:8801,2001:db8::/32"
},
currentEntries
:
[]
string
{
"FE80::8329,udp:8801,2001:db8::/32"
},
expectedEntries
:
nil
,
expectedEntries
:
nil
,
},
},
{
// case 9
{
name
:
"ipset sync, port entry removed"
,
set
:
&
utilipset
.
IPSet
{
set
:
&
utilipset
.
IPSet
{
Name
:
"AAA"
,
Name
:
"AAA"
,
},
},
...
@@ -161,7 +173,8 @@ func TestSyncIPSetEntries(t *testing.T) {
...
@@ -161,7 +173,8 @@ func TestSyncIPSetEntries(t *testing.T) {
currentEntries
:
[]
string
{
"80"
},
currentEntries
:
[]
string
{
"80"
},
expectedEntries
:
nil
,
expectedEntries
:
nil
,
},
},
{
// case 10
{
name
:
"ipset sync, remove old and add new"
,
set
:
&
utilipset
.
IPSet
{
set
:
&
utilipset
.
IPSet
{
Name
:
"c-c-c"
,
Name
:
"c-c-c"
,
},
},
...
@@ -170,7 +183,8 @@ func TestSyncIPSetEntries(t *testing.T) {
...
@@ -170,7 +183,8 @@ func TestSyncIPSetEntries(t *testing.T) {
currentEntries
:
[]
string
{
"80"
},
currentEntries
:
[]
string
{
"80"
},
expectedEntries
:
[]
string
{
"8080"
,
"9090"
},
expectedEntries
:
[]
string
{
"8080"
,
"9090"
},
},
},
{
// case 11
{
name
:
"ipset sync, remove many stale ports"
,
set
:
&
utilipset
.
IPSet
{
set
:
&
utilipset
.
IPSet
{
Name
:
"NODE-PORT"
,
Name
:
"NODE-PORT"
,
},
},
...
@@ -179,7 +193,8 @@ func TestSyncIPSetEntries(t *testing.T) {
...
@@ -179,7 +193,8 @@ func TestSyncIPSetEntries(t *testing.T) {
currentEntries
:
[]
string
{
"80"
,
"9090"
,
"8081"
,
"8082"
},
currentEntries
:
[]
string
{
"80"
,
"9090"
,
"8081"
,
"8082"
},
expectedEntries
:
[]
string
{
"8080"
},
expectedEntries
:
[]
string
{
"8080"
},
},
},
{
// case 12
{
name
:
"ipset sync, add sctp entry"
,
set
:
&
utilipset
.
IPSet
{
set
:
&
utilipset
.
IPSet
{
Name
:
"sctp-1"
,
Name
:
"sctp-1"
,
},
},
...
@@ -189,7 +204,8 @@ func TestSyncIPSetEntries(t *testing.T) {
...
@@ -189,7 +204,8 @@ func TestSyncIPSetEntries(t *testing.T) {
currentEntries
:
nil
,
currentEntries
:
nil
,
expectedEntries
:
[]
string
{
"172.17.0.4,sctp:80"
},
expectedEntries
:
[]
string
{
"172.17.0.4,sctp:80"
},
},
},
{
// case 1
{
name
:
"ipset sync, add IPV6 sctp entry"
,
set
:
&
utilipset
.
IPSet
{
set
:
&
utilipset
.
IPSet
{
Name
:
"sctp-2"
,
Name
:
"sctp-2"
,
},
},
...
@@ -201,26 +217,29 @@ func TestSyncIPSetEntries(t *testing.T) {
...
@@ -201,26 +217,29 @@ func TestSyncIPSetEntries(t *testing.T) {
},
},
}
}
for
i
:=
range
testCases
{
for
_
,
testCase
:=
range
testCases
{
set
:=
NewIPSet
(
fakeipset
.
NewFake
(
testIPSetVersion
),
testCases
[
i
]
.
set
.
Name
,
testCases
[
i
]
.
setType
,
testCases
[
i
]
.
ipv6
,
"comment-"
+
testCases
[
i
]
.
set
.
Name
)
t
.
Run
(
testCase
.
name
,
func
(
t
*
testing
.
T
)
{
set
:=
NewIPSet
(
fakeipset
.
NewFake
(
testIPSetVersion
),
testCase
.
set
.
Name
,
testCase
.
setType
,
testCase
.
ipv6
,
"comment-"
+
testCase
.
set
.
Name
)
if
err
:=
set
.
handle
.
CreateSet
(
&
set
.
IPSet
,
true
);
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
for
_
,
entry
:=
range
testCases
[
i
]
.
expectedEntries
{
set
.
handle
.
AddEntry
(
entry
,
testCases
[
i
]
.
set
,
true
)
}
set
.
activeEntries
.
Insert
(
testCases
[
i
]
.
activeEntries
...
)
if
err
:=
set
.
handle
.
CreateSet
(
&
set
.
IPSet
,
true
);
err
!=
nil
{
set
.
syncIPSetEntries
()
for
_
,
entry
:=
range
testCases
[
i
]
.
expectedEntries
{
found
,
err
:=
set
.
handle
.
TestEntry
(
entry
,
testCases
[
i
]
.
set
.
Name
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
}
if
!
found
{
t
.
Errorf
(
"Unexpected entry 172.17.0.4,tcp:80 not found in set foo"
)
for
_
,
entry
:=
range
testCase
.
currentEntries
{
set
.
handle
.
AddEntry
(
entry
,
testCase
.
set
,
true
)
}
set
.
activeEntries
.
Insert
(
testCase
.
activeEntries
...
)
set
.
syncIPSetEntries
()
for
_
,
entry
:=
range
testCase
.
expectedEntries
{
found
,
err
:=
set
.
handle
.
TestEntry
(
entry
,
testCase
.
set
.
Name
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
if
!
found
{
t
.
Errorf
(
"Unexpected entry %q not found in set foo"
,
entry
)
}
}
}
}
}
)
}
}
}
}
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