@@ -841,6 +841,34 @@ func TestSync_ServerSideApply(t *testing.T) {
841
841
}
842
842
}
843
843
844
+ func TestSyncContext_ServerSideApplyWithDryRun (t * testing.T ) {
845
+ tests := []struct {
846
+ name string
847
+ scDryRun bool
848
+ dryRun bool
849
+ expectedSSA bool
850
+ objToUse func (* unstructured.Unstructured ) * unstructured.Unstructured
851
+ }{
852
+ {"BothFlagsFalseAnnotated" , false , false , true , withServerSideApplyAnnotation },
853
+ {"scDryRunTrueAnnotated" , true , false , false , withServerSideApplyAnnotation },
854
+ {"dryRunTrueAnnotated" , false , true , false , withServerSideApplyAnnotation },
855
+ {"BothFlagsTrueAnnotated" , true , true , false , withServerSideApplyAnnotation },
856
+ {"AnnotatedDisabledSSA" , false , false , false , withDisableServerSideApplyAnnotation },
857
+ }
858
+
859
+ for _ , tc := range tests {
860
+ t .Run (tc .name , func (t * testing.T ) {
861
+ sc := newTestSyncCtx (nil )
862
+ sc .dryRun = tc .scDryRun
863
+ targetObj := tc .objToUse (testingutils .NewPod ())
864
+
865
+ // Execute the shouldUseServerSideApply method and assert expectations
866
+ serverSideApply := sc .shouldUseServerSideApply (targetObj , tc .dryRun )
867
+ assert .Equal (t , tc .expectedSSA , serverSideApply )
868
+ })
869
+ }
870
+ }
871
+
844
872
func withForceAnnotation (un * unstructured.Unstructured ) * unstructured.Unstructured {
845
873
un .SetAnnotations (map [string ]string {synccommon .AnnotationSyncOptions : synccommon .SyncOptionForce })
846
874
return un
0 commit comments