@@ -98,6 +98,27 @@ var _ = Describe("plan builder test", func() {
9898 Expect (planBuilder .defaultWalkFunc (v )).Should (Succeed ())
9999 })
100100
101+ It ("should patch object" , func () {
102+ svcOrig := builder .NewServiceBuilder (namespace , name ).GetObject ()
103+ svc := svcOrig .DeepCopy ()
104+ svc .Labels = map [string ]string {"patched" : "true" }
105+ v := & model.ObjectVertex {
106+ OriObj : svcOrig ,
107+ Obj : svc ,
108+ Action : model .ActionPatchPtr (),
109+ }
110+ k8sMock .EXPECT ().
111+ Patch (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).
112+ DoAndReturn (func (_ context.Context , obj * corev1.Service , _ client.Patch , _ ... client.PatchOption ) error {
113+ Expect (obj ).ShouldNot (BeNil ())
114+ Expect (obj .Namespace ).Should (Equal (svc .Namespace ))
115+ Expect (obj .Name ).Should (Equal (svc .Name ))
116+ Expect (obj .Labels ).Should (Equal (svc .Labels ))
117+ return nil
118+ }).Times (1 )
119+ Expect (planBuilder .defaultWalkFunc (v )).Should (Succeed ())
120+ })
121+
101122 It ("should update pvc object" , func () {
102123 pvcOrig := builder .NewPVCBuilder (namespace , name ).GetObject ()
103124 pvc := pvcOrig .DeepCopy ()
@@ -286,6 +307,30 @@ var _ = Describe("plan builder test", func() {
286307 }
287308 Expect (found ).To (BeTrue ())
288309 })
310+
311+ It ("should append a patch vertex when requested by object options" , func () {
312+ oldPod := builder .NewPodBuilder ("ns" , "pod" ).GetObject ()
313+ newPod := oldPod .DeepCopy ()
314+ newPod .Labels = map [string ]string {"patched" : "true" }
315+
316+ currentTree := NewObjectTree ()
317+ desiredTree := NewObjectTree ()
318+ currentTree .SetRoot (builder .NewInstanceSetBuilder ("ns" , "root" ).GetObject ())
319+ desiredTree .SetRoot (currentTree .GetRoot ())
320+ Expect (currentTree .Add (oldPod )).Should (Succeed ())
321+ Expect (desiredTree .Update (newPod , WithPatch (true ))).Should (Succeed ())
322+
323+ vertices := buildOrderedVertices (transCtx , currentTree , desiredTree )
324+
325+ found := false
326+ for _ , v := range vertices {
327+ if pod , ok := v .Obj .(* corev1.Pod ); ok && pod .Name == "pod" {
328+ found = true
329+ Expect (* v .Action ).To (Equal (model .PATCH ))
330+ }
331+ }
332+ Expect (found ).To (BeTrue ())
333+ })
289334 })
290335 })
291336})
0 commit comments