mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Sanitize newEndpoints semantics, remove a dup arg
This commit is contained in:
@@ -1177,18 +1177,16 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
// This is a coarse test, but it offers some modicum of confidence as the code is evolved.
|
||||
func Test_accumulateEndpointsMap(t *testing.T) {
|
||||
testCases := []struct {
|
||||
newEndpoints api.Endpoints
|
||||
oldEndpoints map[proxy.ServicePortName][]*endpointsInfo
|
||||
expectedNew map[proxy.ServicePortName][]*endpointsInfo
|
||||
expectedActive []proxy.ServicePortName
|
||||
expectedStale []endpointServicePair
|
||||
newEndpoints api.Endpoints
|
||||
oldEndpoints map[proxy.ServicePortName][]*endpointsInfo
|
||||
expectedNew map[proxy.ServicePortName][]*endpointsInfo
|
||||
expectedStale []endpointServicePair
|
||||
}{{
|
||||
// Case[0]: nothing
|
||||
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) {}),
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{},
|
||||
expectedNew: map[proxy.ServicePortName][]*endpointsInfo{},
|
||||
expectedActive: []proxy.ServicePortName{},
|
||||
expectedStale: []endpointServicePair{},
|
||||
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) {}),
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{},
|
||||
expectedNew: map[proxy.ServicePortName][]*endpointsInfo{},
|
||||
expectedStale: []endpointServicePair{},
|
||||
}, {
|
||||
// Case[1]: no changes, unnamed port
|
||||
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) {
|
||||
@@ -1214,8 +1212,7 @@ func Test_accumulateEndpointsMap(t *testing.T) {
|
||||
{"1.1.1.1:11", false},
|
||||
},
|
||||
},
|
||||
expectedActive: []proxy.ServicePortName{makeServicePortName("ns1", "ep1", "")},
|
||||
expectedStale: []endpointServicePair{},
|
||||
expectedStale: []endpointServicePair{},
|
||||
}, {
|
||||
// Case[2]: no changes, named port
|
||||
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) {
|
||||
@@ -1241,8 +1238,7 @@ func Test_accumulateEndpointsMap(t *testing.T) {
|
||||
{"1.1.1.1:11", false},
|
||||
},
|
||||
},
|
||||
expectedActive: []proxy.ServicePortName{makeServicePortName("ns1", "ep1", "port")},
|
||||
expectedStale: []endpointServicePair{},
|
||||
expectedStale: []endpointServicePair{},
|
||||
}, {
|
||||
// Case[3]: new port
|
||||
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) {
|
||||
@@ -1265,8 +1261,7 @@ func Test_accumulateEndpointsMap(t *testing.T) {
|
||||
{"1.1.1.1:11", false},
|
||||
},
|
||||
},
|
||||
expectedActive: []proxy.ServicePortName{makeServicePortName("ns1", "ep1", "")},
|
||||
expectedStale: []endpointServicePair{},
|
||||
expectedStale: []endpointServicePair{},
|
||||
}, {
|
||||
// Case[4]: remove port
|
||||
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) {}),
|
||||
@@ -1275,9 +1270,8 @@ func Test_accumulateEndpointsMap(t *testing.T) {
|
||||
{"1.1.1.1:11", false},
|
||||
},
|
||||
},
|
||||
expectedNew: map[proxy.ServicePortName][]*endpointsInfo{},
|
||||
expectedActive: []proxy.ServicePortName{},
|
||||
expectedStale: []endpointServicePair{ /* can't detect this one */ },
|
||||
expectedNew: map[proxy.ServicePortName][]*endpointsInfo{},
|
||||
expectedStale: []endpointServicePair{ /* can't detect this one */ },
|
||||
}, {
|
||||
// Case[5]: new IP and port
|
||||
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) {
|
||||
@@ -1313,10 +1307,6 @@ func Test_accumulateEndpointsMap(t *testing.T) {
|
||||
{"2.2.2.2:22", false},
|
||||
},
|
||||
},
|
||||
expectedActive: []proxy.ServicePortName{
|
||||
makeServicePortName("ns1", "ep1", "p1"),
|
||||
makeServicePortName("ns1", "ep1", "p2"),
|
||||
},
|
||||
expectedStale: []endpointServicePair{},
|
||||
}, {
|
||||
// Case[6]: remove IP and port
|
||||
@@ -1348,9 +1338,6 @@ func Test_accumulateEndpointsMap(t *testing.T) {
|
||||
{"1.1.1.1:11", false},
|
||||
},
|
||||
},
|
||||
expectedActive: []proxy.ServicePortName{
|
||||
makeServicePortName("ns1", "ep1", "p1"),
|
||||
},
|
||||
expectedStale: []endpointServicePair{{
|
||||
endpoint: "2.2.2.2:11",
|
||||
servicePortName: makeServicePortName("ns1", "ep1", "p1"),
|
||||
@@ -1380,10 +1367,7 @@ func Test_accumulateEndpointsMap(t *testing.T) {
|
||||
{"1.1.1.1:11", false},
|
||||
},
|
||||
},
|
||||
expectedActive: []proxy.ServicePortName{
|
||||
makeServicePortName("ns1", "ep1", "p2"),
|
||||
},
|
||||
expectedStale: []endpointServicePair{},
|
||||
expectedStale: []endpointServicePair{ /* can't detect this one */ },
|
||||
}, {
|
||||
// Case[8]: renumber port
|
||||
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) {
|
||||
@@ -1409,9 +1393,6 @@ func Test_accumulateEndpointsMap(t *testing.T) {
|
||||
{"1.1.1.1:22", false},
|
||||
},
|
||||
},
|
||||
expectedActive: []proxy.ServicePortName{
|
||||
makeServicePortName("ns1", "ep1", "p1"),
|
||||
},
|
||||
expectedStale: []endpointServicePair{{
|
||||
endpoint: "1.1.1.1:11",
|
||||
servicePortName: makeServicePortName("ns1", "ep1", "p1"),
|
||||
@@ -1423,9 +1404,8 @@ func Test_accumulateEndpointsMap(t *testing.T) {
|
||||
newEndpoints := map[proxy.ServicePortName][]*endpointsInfo{}
|
||||
svcPortToInfoMap := map[proxy.ServicePortName][]hostPortInfo{}
|
||||
staleConnections := map[endpointServicePair]bool{}
|
||||
activeEndpoints := map[proxy.ServicePortName]bool{}
|
||||
accumulateEndpointsMap(&tc.newEndpoints, "host", tc.oldEndpoints,
|
||||
&newEndpoints, &svcPortToInfoMap, &staleConnections, &activeEndpoints)
|
||||
&newEndpoints, &svcPortToInfoMap, &staleConnections)
|
||||
|
||||
if len(newEndpoints) != len(tc.expectedNew) {
|
||||
t.Errorf("[%d] expected %d new, got %d: %v", tci, len(tc.expectedNew), len(newEndpoints), spew.Sdump(newEndpoints))
|
||||
@@ -1441,14 +1421,6 @@ func Test_accumulateEndpointsMap(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(activeEndpoints) != len(tc.expectedActive) {
|
||||
t.Errorf("[%d] expected %d active, got %d: %v", tci, len(tc.expectedActive), len(activeEndpoints), activeEndpoints)
|
||||
}
|
||||
for _, x := range tc.expectedActive {
|
||||
if activeEndpoints[x] != true {
|
||||
t.Errorf("[%d] expected active[%v], but didn't find it: %v", tci, x, activeEndpoints)
|
||||
}
|
||||
}
|
||||
if len(staleConnections) != len(tc.expectedStale) {
|
||||
t.Errorf("[%d] expected %d stale, got %d: %v", tci, len(tc.expectedStale), len(staleConnections), staleConnections)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user