Skip to content

Commit 7258614

Browse files
authored
chore: add unit test for ssa with dryRun (argoproj#703)
Signed-off-by: Peter Jiang <[email protected]>
1 parent e5ef2e1 commit 7258614

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pkg/sync/sync_context_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,34 @@ func TestSync_ServerSideApply(t *testing.T) {
841841
}
842842
}
843843

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+
844872
func withForceAnnotation(un *unstructured.Unstructured) *unstructured.Unstructured {
845873
un.SetAnnotations(map[string]string{synccommon.AnnotationSyncOptions: synccommon.SyncOptionForce})
846874
return un

0 commit comments

Comments
 (0)