@@ -769,6 +769,63 @@ func TestDoNotPrunePruneFalse(t *testing.T) {
769
769
assert .Equal (t , synccommon .OperationSucceeded , phase )
770
770
}
771
771
772
+ // make sure that we need confirmation to prune resources with Prune=confirm
773
+ func TestPruneConfirmResource (t * testing.T ) {
774
+ syncCtx := newTestSyncCtx (nil , WithOperationSettings (false , true , false , false ))
775
+ pod := testingutils .NewPod ()
776
+ pod .SetAnnotations (map [string ]string {synccommon .AnnotationSyncOptions : "Prune=confirm" })
777
+ pod .SetNamespace (testingutils .FakeArgoCDNamespace )
778
+ syncCtx .resources = groupResources (ReconciliationResult {
779
+ Live : []* unstructured.Unstructured {pod },
780
+ Target : []* unstructured.Unstructured {nil },
781
+ })
782
+
783
+ syncCtx .Sync ()
784
+ phase , msg , resources := syncCtx .GetState ()
785
+
786
+ assert .Equal (t , synccommon .OperationRunning , phase )
787
+ assert .Len (t , resources , 0 )
788
+ assert .Equal (t , "Waiting for pruning confirmation of v1/Pod/my-pod" , msg )
789
+
790
+ syncCtx .pruneConfirmed = true
791
+ syncCtx .Sync ()
792
+
793
+ phase , msg , resources = syncCtx .GetState ()
794
+ assert .Equal (t , synccommon .OperationSucceeded , phase )
795
+ assert .Len (t , resources , 1 )
796
+ assert .Equal (t , synccommon .ResultCodePruned , resources [0 ].Status )
797
+ assert .Equal (t , "pruned" , resources [0 ].Message )
798
+ }
799
+
800
+ // make sure that we need confirmation to prune with Prune=confirm on the app
801
+ func TestPruneConfirmApp (t * testing.T ) {
802
+ syncCtx := newTestSyncCtx (nil , WithOperationSettings (false , true , false , false ))
803
+ syncCtx .requiresPruneConfirmation = true
804
+ pod := testingutils .NewPod ()
805
+ pod .SetAnnotations (map [string ]string {synccommon .AnnotationSyncOptions : "Prune=true" })
806
+ pod .SetNamespace (testingutils .FakeArgoCDNamespace )
807
+ syncCtx .resources = groupResources (ReconciliationResult {
808
+ Live : []* unstructured.Unstructured {pod },
809
+ Target : []* unstructured.Unstructured {nil },
810
+ })
811
+
812
+ syncCtx .Sync ()
813
+ phase , msg , resources := syncCtx .GetState ()
814
+
815
+ assert .Equal (t , synccommon .OperationRunning , phase )
816
+ assert .Len (t , resources , 0 )
817
+ assert .Equal (t , "Waiting for pruning confirmation of v1/Pod/my-pod" , msg )
818
+
819
+ syncCtx .pruneConfirmed = true
820
+ syncCtx .Sync ()
821
+
822
+ phase , msg , resources = syncCtx .GetState ()
823
+ assert .Equal (t , synccommon .OperationSucceeded , phase )
824
+ assert .Len (t , resources , 1 )
825
+ assert .Equal (t , synccommon .ResultCodePruned , resources [0 ].Status )
826
+ assert .Equal (t , "pruned" , resources [0 ].Message )
827
+ }
828
+
772
829
// // make sure Validate=false means we don't validate
773
830
func TestSyncOptionValidate (t * testing.T ) {
774
831
tests := []struct {
0 commit comments