@@ -98,6 +98,14 @@ WAIT_LOOP:
98
98
Fail (fmt .Sprintf ("timed out waiting for namespace %q to be deleted" , ns .Name ))
99
99
}
100
100
101
+ type mockPatchOption struct {
102
+ applied bool
103
+ }
104
+
105
+ func (o * mockPatchOption ) ApplyToPatch (_ * client.PatchOptions ) {
106
+ o .applied = true
107
+ }
108
+
101
109
// metaOnlyFromObj returns PartialObjectMetadata from a concrete Go struct that
102
110
// returns a concrete *metav1.ObjectMeta from GetObjectMeta (yes, that plays a
103
111
// bit fast and loose, but the only other options are serializing and then
@@ -715,6 +723,39 @@ var _ = Describe("Client", func() {
715
723
})
716
724
})
717
725
726
+ Describe ("Patch" , func () {
727
+ Context ("Metadata Client" , func () {
728
+ It ("should merge patch with options" , func (done Done ) {
729
+ cl , err := client .New (cfg , client.Options {})
730
+ Expect (err ).NotTo (HaveOccurred ())
731
+ Expect (cl ).NotTo (BeNil ())
732
+
733
+ By ("initially creating a Deployment" )
734
+ dep , err := clientset .AppsV1 ().Deployments (ns ).Create (ctx , dep , metav1.CreateOptions {})
735
+ Expect (err ).NotTo (HaveOccurred ())
736
+
737
+ metadata := metaOnlyFromObj (dep , scheme )
738
+ if metadata .Labels == nil {
739
+ metadata .Labels = make (map [string ]string )
740
+ }
741
+ metadata .Labels ["foo" ] = "bar"
742
+
743
+ testOption := & mockPatchOption {}
744
+ Expect (cl .Patch (context .TODO (), metadata , client .Merge , testOption )).To (Succeed ())
745
+
746
+ By ("validating that patched metadata has new labels" )
747
+ actual , err := clientset .AppsV1 ().Deployments (ns ).Get (ctx , dep .Name , metav1.GetOptions {})
748
+ Expect (err ).NotTo (HaveOccurred ())
749
+ Expect (actual ).NotTo (BeNil ())
750
+ Expect (actual .Labels ["foo" ]).To (Equal ("bar" ))
751
+
752
+ By ("validating patch options were applied" )
753
+ Expect (testOption .applied ).To (Equal (true ))
754
+ close (done )
755
+ })
756
+ })
757
+ })
758
+
718
759
Describe ("StatusClient" , func () {
719
760
Context ("with structured objects" , func () {
720
761
It ("should update status of an existing object" , func (done Done ) {
0 commit comments