Skip to content

Commit

Permalink
Merge pull request #447 from rramkumar1/master
Browse files Browse the repository at this point in the history
Export getPatchBytes in pkg/util
  • Loading branch information
k8s-ci-robot committed Aug 22, 2018
2 parents 7501865 + 340f3bc commit 439421d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/utils/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func hasFinalizer(m meta_v1.ObjectMeta, key string) bool {
return slice.ContainsString(m.Finalizers, key, nil)
}

// getPatchBytes returns a patch which is the difference between the old and new objects.
// GetPatchBytes returns a patch which is the difference between the old and new objects.
// Note: refStruct is a empty struct of the type which the patch is being generated for.
func getPatchBytes(old interface{}, cur interface{}, refStruct interface{}) ([]byte, error) {
func GetPatchBytes(old interface{}, cur interface{}, refStruct interface{}) ([]byte, error) {
oldBytes, err := json.Marshal(old)
if err != nil {
return nil, fmt.Errorf("failed to marshal old object: %v", err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/utils/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ func TestGetPatchBytes(t *testing.T) {
Finalizers: []string{"foo"},
},
}
b, err := getPatchBytes(ing, updated, extensions.Ingress{})
b, err := GetPatchBytes(ing, updated, extensions.Ingress{})
if err != nil {
t.Fatal(err)
}
expected := `{"metadata":{"finalizers":["foo"]}}`
if string(b) != expected {
t.Errorf("getPatchBytes(%+v, %+v) = %s ; want %s", ing, updated, string(b), expected)
t.Errorf("GetPatchBytes(%+v, %+v) = %s ; want %s", ing, updated, string(b), expected)
}

// Patch an Ingress with the finalizer removed
ing = updated
updated = &extensions.Ingress{}
b, err = getPatchBytes(ing, updated, extensions.Ingress{})
b, err = GetPatchBytes(ing, updated, extensions.Ingress{})
if err != nil {
t.Fatal(err)
}
expected = `{"metadata":{"finalizers":null}}`
if string(b) != expected {
t.Errorf("getPatchBytes(%+v, %+v) = %s ; want %s", ing, updated, string(b), expected)
t.Errorf("GetPatchBytes(%+v, %+v) = %s ; want %s", ing, updated, string(b), expected)
}
}

0 comments on commit 439421d

Please sign in to comment.