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
0d36dc70
Commit
0d36dc70
authored
Apr 22, 2016
by
Minhan Xia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added test for revertPorts
parent
56ad7180
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
0 deletions
+98
-0
proxier_test.go
pkg/proxy/iptables/proxier_test.go
+98
-0
No files found.
pkg/proxy/iptables/proxier_test.go
View file @
0d36dc70
...
@@ -374,4 +374,102 @@ func TestDeleteServiceConnections(t *testing.T) {
...
@@ -374,4 +374,102 @@ func TestDeleteServiceConnections(t *testing.T) {
}
}
}
}
type
fakeClosable
struct
{
closed
bool
}
func
(
c
*
fakeClosable
)
Close
()
error
{
c
.
closed
=
true
return
nil
}
func
TestRevertPorts
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
replacementPorts
[]
localPort
existingPorts
[]
localPort
expectToBeClose
[]
bool
}{
{
replacementPorts
:
[]
localPort
{
{
port
:
5001
},
{
port
:
5002
},
{
port
:
5003
},
},
existingPorts
:
[]
localPort
{},
expectToBeClose
:
[]
bool
{
true
,
true
,
true
},
},
{
replacementPorts
:
[]
localPort
{},
existingPorts
:
[]
localPort
{
{
port
:
5001
},
{
port
:
5002
},
{
port
:
5003
},
},
expectToBeClose
:
[]
bool
{},
},
{
replacementPorts
:
[]
localPort
{
{
port
:
5001
},
{
port
:
5002
},
{
port
:
5003
},
},
existingPorts
:
[]
localPort
{
{
port
:
5001
},
{
port
:
5002
},
{
port
:
5003
},
},
expectToBeClose
:
[]
bool
{
false
,
false
,
false
},
},
{
replacementPorts
:
[]
localPort
{
{
port
:
5001
},
{
port
:
5002
},
{
port
:
5003
},
},
existingPorts
:
[]
localPort
{
{
port
:
5001
},
{
port
:
5003
},
},
expectToBeClose
:
[]
bool
{
false
,
true
,
false
},
},
{
replacementPorts
:
[]
localPort
{
{
port
:
5001
},
{
port
:
5002
},
{
port
:
5003
},
},
existingPorts
:
[]
localPort
{
{
port
:
5001
},
{
port
:
5002
},
{
port
:
5003
},
{
port
:
5004
},
},
expectToBeClose
:
[]
bool
{
false
,
false
,
false
},
},
}
for
i
,
tc
:=
range
testCases
{
replacementPortsMap
:=
make
(
map
[
localPort
]
closeable
)
for
_
,
lp
:=
range
tc
.
replacementPorts
{
replacementPortsMap
[
lp
]
=
&
fakeClosable
{}
}
existingPortsMap
:=
make
(
map
[
localPort
]
closeable
)
for
_
,
lp
:=
range
tc
.
existingPorts
{
existingPortsMap
[
lp
]
=
&
fakeClosable
{}
}
revertPorts
(
replacementPortsMap
,
existingPortsMap
)
for
j
,
expectation
:=
range
tc
.
expectToBeClose
{
if
replacementPortsMap
[
tc
.
replacementPorts
[
j
]]
.
(
*
fakeClosable
)
.
closed
!=
expectation
{
t
.
Errorf
(
"Expect replacement localport %v to be %v in test case %v"
,
tc
.
replacementPorts
[
j
],
expectation
,
i
)
}
}
for
_
,
lp
:=
range
tc
.
existingPorts
{
if
existingPortsMap
[
lp
]
.
(
*
fakeClosable
)
.
closed
==
true
{
t
.
Errorf
(
"Expect existing localport %v to be false in test case %v"
,
lp
,
i
)
}
}
}
}
// TODO(thockin): add a test for syncProxyRules() or break it down further and test the pieces.
// TODO(thockin): add a test for syncProxyRules() or break it down further and test the pieces.
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