added test for revertPorts
This commit is contained in:
parent
56ad718008
commit
0d36dc7000
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user