have fakeLoadbalancerService take lb type as argument

This commit is contained in:
Ashley Gau
2018-04-13 14:59:14 -07:00
parent f105397b88
commit 74092228b2
4 changed files with 37 additions and 43 deletions

View File

@@ -290,7 +290,7 @@ func TestEnsureExternalLoadBalancer(t *testing.T) {
gce, err := fakeGCECloud(vals)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
status, err := createExternalLoadBalancer(gce, apiService, nodeNames, vals.ClusterName, vals.ClusterID, vals.ZoneName)
assert.NoError(t, err)
assert.NotEmpty(t, status.Ingress)
@@ -305,7 +305,7 @@ func TestUpdateExternalLoadBalancer(t *testing.T) {
gce, err := fakeGCECloud((DefaultTestClusterValues()))
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
_, err = createExternalLoadBalancer(gce, apiService, []string{nodeName}, vals.ClusterName, vals.ClusterID, vals.ZoneName)
assert.NoError(t, err)
@@ -359,7 +359,7 @@ func TestEnsureExternalLoadBalancerDeleted(t *testing.T) {
gce, err := fakeGCECloud(vals)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
_, err = createExternalLoadBalancer(gce, apiService, []string{"test-node-1"}, vals.ClusterName, vals.ClusterID, vals.ZoneName)
assert.NoError(t, err)
@@ -376,7 +376,7 @@ func TestLoadBalancerWrongTierResourceDeletion(t *testing.T) {
// Enable the cloud.NetworkTiers feature
gce.AlphaFeatureGate.features[AlphaFeatureNetworkTiers] = true
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
apiService.Annotations = map[string]string{NetworkTierAnnotationKey: "Premium"}
// cloud.NetworkTier defaults to Premium
@@ -433,7 +433,7 @@ func TestEnsureExternalLoadBalancerFailsIfInvalidNetworkTier(t *testing.T) {
// Enable the cloud.NetworkTiers feature
gce.AlphaFeatureGate.features[AlphaFeatureNetworkTiers] = true
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
apiService.Annotations = map[string]string{NetworkTierAnnotationKey: wrongTier}
_, err = gce.ensureExternalLoadBalancer(vals.ClusterName, vals.ClusterID, apiService, nil, nodes)
@@ -446,7 +446,7 @@ func TestEnsureExternalLoadBalancerFailsWithNoNodes(t *testing.T) {
gce, err := fakeGCECloud(DefaultTestClusterValues())
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
_, err = gce.ensureExternalLoadBalancer(vals.ClusterName, vals.ClusterID, apiService, nil, []*v1.Node{})
require.Error(t, err)
assert.EqualError(t, err, errStrLbNoHosts)
@@ -456,11 +456,11 @@ func TestForwardingRuleNeedsUpdate(t *testing.T) {
vals := DefaultTestClusterValues()
gce, err := fakeGCECloud(DefaultTestClusterValues())
require.NoError(t, err)
status, err := createExternalLoadBalancer(gce, fakeLbApiService(), []string{"test-node-1"}, vals.ClusterName, vals.ClusterID, vals.ZoneName)
status, err := createExternalLoadBalancer(gce, fakeLoadbalancerService(""), []string{"test-node-1"}, vals.ClusterName, vals.ClusterID, vals.ZoneName)
require.NotNil(t, status)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
lbName := cloudprovider.GetLoadBalancerName(apiService)
ipAddr := status.Ingress[0].IP
@@ -539,7 +539,7 @@ func TestTargetPoolNeedsRecreation(t *testing.T) {
gce, err := fakeGCECloud(DefaultTestClusterValues())
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
serviceName := apiService.ObjectMeta.Name
lbName := cloudprovider.GetLoadBalancerName(apiService)
nodes, err := createAndInsertNodes(gce, []string{"test-node-1"}, vals.ZoneName)
@@ -584,7 +584,7 @@ func TestFirewallNeedsUpdate(t *testing.T) {
vals := DefaultTestClusterValues()
gce, err := fakeGCECloud(DefaultTestClusterValues())
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
status, err := createExternalLoadBalancer(gce, apiService, []string{"test-node-1"}, vals.ClusterName, vals.ClusterID, vals.ZoneName)
require.NotNil(t, status)
require.NoError(t, err)
@@ -757,7 +757,7 @@ func TestEnsureTargetPoolAndHealthCheck(t *testing.T) {
nodes, err := createAndInsertNodes(gce, []string{"test-node-1"}, vals.ZoneName)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
status, err := gce.ensureExternalLoadBalancer(
vals.ClusterName,
vals.ClusterID,
@@ -846,7 +846,7 @@ func TestCreateAndUpdateFirewallSucceedsOnXPN(t *testing.T) {
recorder := record.NewFakeRecorder(1024)
gce.eventRecorder = recorder
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
nodes, err := createAndInsertNodes(gce, []string{"test-node-1"}, vals.ZoneName)
require.NoError(t, err)
hostNames := nodeNames(nodes)
@@ -886,7 +886,7 @@ func TestEnsureExternalLoadBalancerDeletedSucceedsOnXPN(t *testing.T) {
gce, err := fakeGCECloud(DefaultTestClusterValues())
require.NoError(t, err)
_, err = createExternalLoadBalancer(gce, fakeLbApiService(), []string{"test-node-1"}, vals.ClusterName, vals.ClusterID, vals.ZoneName)
_, err = createExternalLoadBalancer(gce, fakeLoadbalancerService(""), []string{"test-node-1"}, vals.ClusterName, vals.ClusterID, vals.ZoneName)
require.NoError(t, err)
c := gce.c.(*cloud.MockGCE)
@@ -897,7 +897,7 @@ func TestEnsureExternalLoadBalancerDeletedSucceedsOnXPN(t *testing.T) {
recorder := record.NewFakeRecorder(1024)
gce.eventRecorder = recorder
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
err = gce.ensureExternalLoadBalancerDeleted(vals.ClusterName, vals.ClusterID, apiService)
require.NoError(t, err)
@@ -996,7 +996,7 @@ func TestEnsureExternalLoadBalancerErrors(t *testing.T) {
gce, err := fakeGCECloud(DefaultTestClusterValues())
nodes, err := createAndInsertNodes(gce, []string{"test-node-1"}, vals.ZoneName)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
params = newEnsureELBParams(nodes, apiService)
if tc.adjustParams != nil {
tc.adjustParams(params)

View File

@@ -54,7 +54,7 @@ func TestEnsureInternalBackendServiceUpdates(t *testing.T) {
gce, err := fakeGCECloud(vals)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService(string(LBTypeInternal))
lbName := cloudprovider.GetLoadBalancerName(apiService)
nodes, err := createAndInsertNodes(gce, nodeNames, vals.ZoneName)
igName := makeInstanceGroupName(vals.ClusterID)
@@ -82,7 +82,7 @@ func TestEnsureInternalBackendServiceGroups(t *testing.T) {
gce, err := fakeGCECloud(vals)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService(string(LBTypeInternal))
lbName := cloudprovider.GetLoadBalancerName(apiService)
nodes, err := createAndInsertNodes(gce, nodeNames, vals.ZoneName)
igName := makeInstanceGroupName(vals.ClusterID)
@@ -116,7 +116,7 @@ func TestEnsureInternalLoadBalancer(t *testing.T) {
gce, err := fakeGCECloud(vals)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService(string(LBTypeInternal))
status, err := createInternalLoadBalancer(gce, apiService, nil, nodeNames, vals.ClusterName, vals.ClusterID, vals.ZoneName)
assert.NoError(t, err)
assert.NotEmpty(t, status.Ingress)
@@ -130,7 +130,7 @@ func TestEnsureInternalLoadBalancerWithExistingResources(t *testing.T) {
gce, err := fakeGCECloud(vals)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService(string(LBTypeInternal))
// Create the expected resources necessary for an Internal Load Balancer
nm := types.NamespacedName{Name: apiService.Name, Namespace: apiService.Namespace}
lbName := cloudprovider.GetLoadBalancerName(apiService)
@@ -162,7 +162,7 @@ func TestEnsureInternalLoadBalancerClearPreviousResources(t *testing.T) {
gce, err := fakeGCECloud(vals)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService(string(LBTypeInternal))
lbName := cloudprovider.GetLoadBalancerName(apiService)
// Create a ForwardingRule that's missing an IP address
@@ -239,7 +239,7 @@ func TestUpdateInternalLoadBalancerBackendServices(t *testing.T) {
gce, err := fakeGCECloud(vals)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService(string(LBTypeInternal))
_, err = createInternalLoadBalancer(gce, apiService, nil, []string{"test-node-1"}, vals.ClusterName, vals.ClusterID, vals.ZoneName)
assert.NoError(t, err)
@@ -290,7 +290,7 @@ func TestUpdateInternalLoadBalancerNodes(t *testing.T) {
gce, err := fakeGCECloud(vals)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService(string(LBTypeInternal))
_, err = createInternalLoadBalancer(gce, apiService, nil, []string{"test-node-1"}, vals.ClusterName, vals.ClusterID, vals.ZoneName)
assert.NoError(t, err)
@@ -320,7 +320,7 @@ func TestEnsureInternalLoadBalancerDeleted(t *testing.T) {
gce, err := fakeGCECloud(vals)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService(string(LBTypeInternal))
_, err = createInternalLoadBalancer(gce, apiService, nil, []string{"test-node-1"}, vals.ClusterName, vals.ClusterID, vals.ZoneName)
assert.NoError(t, err)
@@ -335,7 +335,7 @@ func TestEnsureInternalLoadBalancerDeletedTwiceDoesNotError(t *testing.T) {
gce, err := fakeGCECloud(vals)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService(string(LBTypeInternal))
_, err = createInternalLoadBalancer(gce, apiService, nil, []string{"test-node-1"}, vals.ClusterName, vals.ClusterID, vals.ZoneName)
assert.NoError(t, err)

View File

@@ -29,7 +29,7 @@ func TestGetLoadBalancer(t *testing.T) {
gce, err := fakeGCECloud(vals)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
// When a loadbalancer has not been created
status, found, err := gce.GetLoadBalancer(context.Background(), vals.ClusterName, apiService)
@@ -58,7 +58,7 @@ func TestEnsureLoadBalancerCreatesExternalLb(t *testing.T) {
nodes, err := createAndInsertNodes(gce, nodeNames, vals.ZoneName)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
status, err := gce.EnsureLoadBalancer(context.Background(), vals.ClusterName, apiService, nodes)
assert.NoError(t, err)
assert.NotEmpty(t, status.Ingress)
@@ -74,11 +74,7 @@ func TestEnsureLoadBalancerCreatesInternalLb(t *testing.T) {
nodes, err := createAndInsertNodes(gce, nodeNames, vals.ZoneName)
require.NoError(t, err)
apiService := fakeLbApiService()
annotations := make(map[string]string)
annotations[ServiceAnnotationLoadBalancerType] = string(LBTypeInternal)
apiService.Annotations = annotations
apiService := fakeLoadbalancerService(string(LBTypeInternal))
status, err := gce.EnsureLoadBalancer(context.Background(), vals.ClusterName, apiService, nodes)
assert.NoError(t, err)
assert.NotEmpty(t, status.Ingress)
@@ -94,7 +90,7 @@ func TestEnsureLoadBalancerDeletesExistingInternalLb(t *testing.T) {
nodes, err := createAndInsertNodes(gce, nodeNames, vals.ZoneName)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
createInternalLoadBalancer(gce, apiService, nil, nodeNames, vals.ClusterName, vals.ClusterID, vals.ZoneName)
status, err := gce.EnsureLoadBalancer(context.Background(), vals.ClusterName, apiService, nodes)
@@ -114,12 +110,10 @@ func TestEnsureLoadBalancerDeletesExistingExternalLb(t *testing.T) {
nodes, err := createAndInsertNodes(gce, nodeNames, vals.ZoneName)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
createExternalLoadBalancer(gce, apiService, nodeNames, vals.ClusterName, vals.ClusterID, vals.ZoneName)
annotations := make(map[string]string)
annotations[ServiceAnnotationLoadBalancerType] = string(LBTypeInternal)
apiService.Annotations = annotations
apiService = fakeLoadbalancerService(string(LBTypeInternal))
status, err := gce.EnsureLoadBalancer(context.Background(), vals.ClusterName, apiService, nodes)
assert.NoError(t, err)
assert.NotEmpty(t, status.Ingress)
@@ -137,7 +131,7 @@ func TestEnsureLoadBalancerDeletedDeletesExternalLb(t *testing.T) {
_, err = createAndInsertNodes(gce, nodeNames, vals.ZoneName)
require.NoError(t, err)
apiService := fakeLbApiService()
apiService := fakeLoadbalancerService("")
createExternalLoadBalancer(gce, apiService, nodeNames, vals.ClusterName, vals.ClusterID, vals.ZoneName)
err = gce.EnsureLoadBalancerDeleted(context.Background(), vals.ClusterName, apiService)
@@ -154,10 +148,7 @@ func TestEnsureLoadBalancerDeletedDeletesInternalLb(t *testing.T) {
_, err = createAndInsertNodes(gce, nodeNames, vals.ZoneName)
require.NoError(t, err)
apiService := fakeLbApiService()
annotations := make(map[string]string)
annotations[ServiceAnnotationLoadBalancerType] = string(LBTypeInternal)
apiService.Annotations = annotations
apiService := fakeLoadbalancerService(string(LBTypeInternal))
createInternalLoadBalancer(gce, apiService, nil, nodeNames, vals.ClusterName, vals.ClusterID, vals.ZoneName)
err = gce.EnsureLoadBalancerDeleted(context.Background(), vals.ClusterName, apiService)

View File

@@ -69,9 +69,12 @@ func DefaultTestClusterValues() TestClusterValues {
}
}
func fakeLbApiService() *v1.Service {
func fakeLoadbalancerService(lbType string) *v1.Service {
return &v1.Service{
ObjectMeta: metav1.ObjectMeta{Name: ""},
ObjectMeta: metav1.ObjectMeta{
Name: "",
Annotations: map[string]string{ServiceAnnotationLoadBalancerType: lbType},
},
Spec: v1.ServiceSpec{
SessionAffinity: v1.ServiceAffinityClientIP,
Type: v1.ServiceTypeLoadBalancer,