Skip to content

Instantly share code, notes, and snippets.

@stevenctl
Created May 4, 2023 16:51
Show Gist options
  • Save stevenctl/d064c8afd04e8246c2b54fa008281b6b to your computer and use it in GitHub Desktop.
Save stevenctl/d064c8afd04e8246c2b54fa008281b6b to your computer and use it in GitHub Desktop.
package crdclient
func TestGenMergePatch(t *testing.T) {
existing := &clientnetworkingv1alpha3.WorkloadEntry{
ObjectMeta: metav1.ObjectMeta{
Name: "foo-we",
Namespace: "ns",
Labels: map[string]string{
"oldlabel": "oldvalue",
},
UID: "12345678",
ResourceVersion: "1",
},
Spec: v1alpha3.WorkloadEntry{
Labels: map[string]string{
"oldlabel": "oldvalue",
},
},
}
modified := &clientnetworkingv1alpha3.WorkloadEntry{
ObjectMeta: metav1.ObjectMeta{
Name: "foo-we",
Namespace: "ns",
Labels: map[string]string{
"newlabel": "newvalue",
},
UID: "12345678",
ResourceVersion: "1",
},
Spec: v1alpha3.WorkloadEntry{
Labels: map[string]string{
"newlabel": "newvalue",
},
},
}
bytes, _ := genPatchBytes(existing, modified, types.MergePatchType)
fmt.Println(string(bytes))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment