Skip to content

Commit

Permalink
Remove validatePatchRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Apr 21, 2020
1 parent 4fb7f48 commit 3dc901c
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions pkg/l4/l4controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ package l4

import (
context2 "context"
"reflect"
"testing"
"time"

"k8s.io/client-go/kubernetes"
testing2 "k8s.io/client-go/testing"
"k8s.io/ingress-gce/pkg/loadbalancers"
"k8s.io/ingress-gce/pkg/neg/types"

Expand Down Expand Up @@ -93,23 +90,6 @@ func getKeyForSvc(svc *api_v1.Service, t *testing.T) string {
return key
}

// validatePatchRequest validates that the given client patched the resource with the given change.
// This is needed because there is a bug in go-client test implementation where a patch operation cannot be used
// to delete fields - https://github.com/kubernetes/client-go/issues/607
// TODO remove this once https://github.com/kubernetes/client-go/issues/607 has been fixed.
func validatePatchRequest(client kubernetes.Interface, patchVal string, t *testing.T) {
fakeClient := client.(*fake.Clientset)
actionLen := len(fakeClient.Actions())
if actionLen == 0 {
t.Errorf("Expected atleast one action in fake client")
}
// The latest action should be the one setting status to the given value
patchAction := fakeClient.Actions()[actionLen-1].(testing2.PatchAction)
if !reflect.DeepEqual(patchAction.GetPatch(), []byte(patchVal)) {
t.Errorf("Expected patch '%s', got '%s'", patchVal, string(patchAction.GetPatch()))
}
}

func validateSvcStatus(svc *api_v1.Service, expectStatus bool, t *testing.T) {
if common.HasGivenFinalizer(svc.ObjectMeta, common.ILBFinalizerV2) != expectStatus {
t.Fatalf("Expected L4 finalizer present to be %v, but it was %v", expectStatus, !expectStatus)
Expand Down Expand Up @@ -164,8 +144,7 @@ func TestProcessCreateOrUpdate(t *testing.T) {
if err != nil {
t.Errorf("Failed to sync updated service %s, err %v", newSvc.Name, err)
}
// TODO remove this once https://github.com/kubernetes/client-go/issues/607 has been fixed.
validatePatchRequest(l4c.client, resetLBStatus, t)

// List the service and ensure that it contains the finalizer as well as Status field.
newSvc, err = l4c.client.CoreV1().Services(newSvc.Namespace).Get(context2.TODO(), newSvc.Name, v1.GetOptions{})
if err != nil {
Expand Down Expand Up @@ -200,8 +179,7 @@ func TestProcessDeletion(t *testing.T) {
if err != nil {
t.Errorf("Failed to sync updated service %s, err %v", newSvc.Name, err)
}
// TODO remove this once https://github.com/kubernetes/client-go/issues/607 has been fixed.
validatePatchRequest(l4c.client, resetLBStatus, t)

// List the service and ensure that it contains the finalizer as well as Status field.
newSvc, err = l4c.client.CoreV1().Services(newSvc.Namespace).Get(context2.TODO(), newSvc.Name, v1.GetOptions{})
if err != nil {
Expand Down

0 comments on commit 3dc901c

Please sign in to comment.