|
8 | 8 | "net/http"
|
9 | 9 | "net/http/httptest"
|
10 | 10 | "reflect"
|
| 11 | + "strconv" |
11 | 12 | "strings"
|
12 | 13 | "testing"
|
13 | 14 | "time"
|
@@ -769,6 +770,43 @@ func TestDoNotPrunePruneFalse(t *testing.T) {
|
769 | 770 | assert.Equal(t, synccommon.OperationSucceeded, phase)
|
770 | 771 | }
|
771 | 772 |
|
| 773 | +// make sure that we need confirmation to prune with Prune=confirm |
| 774 | +func TestPruneConfirm(t *testing.T) { |
| 775 | + for _, appLevelConfirmation := range []bool{true, false} { |
| 776 | + t.Run("appLevelConfirmation="+strconv.FormatBool(appLevelConfirmation), func(t *testing.T) { |
| 777 | + syncCtx := newTestSyncCtx(nil, WithOperationSettings(false, true, false, false)) |
| 778 | + syncCtx.requiresPruneConfirmation = appLevelConfirmation |
| 779 | + pod := testingutils.NewPod() |
| 780 | + if appLevelConfirmation { |
| 781 | + pod.SetAnnotations(map[string]string{synccommon.AnnotationSyncOptions: "Prune=true"}) |
| 782 | + } else { |
| 783 | + pod.SetAnnotations(map[string]string{synccommon.AnnotationSyncOptions: "Prune=confirm"}) |
| 784 | + } |
| 785 | + pod.SetNamespace(testingutils.FakeArgoCDNamespace) |
| 786 | + syncCtx.resources = groupResources(ReconciliationResult{ |
| 787 | + Live: []*unstructured.Unstructured{pod}, |
| 788 | + Target: []*unstructured.Unstructured{nil}, |
| 789 | + }) |
| 790 | + |
| 791 | + syncCtx.Sync() |
| 792 | + phase, msg, resources := syncCtx.GetState() |
| 793 | + |
| 794 | + assert.Equal(t, synccommon.OperationRunning, phase) |
| 795 | + assert.Empty(t, resources) |
| 796 | + assert.Equal(t, "Waiting for pruning confirmation of v1/Pod/my-pod", msg) |
| 797 | + |
| 798 | + syncCtx.pruneConfirmed = true |
| 799 | + syncCtx.Sync() |
| 800 | + |
| 801 | + phase, _, resources = syncCtx.GetState() |
| 802 | + assert.Equal(t, synccommon.OperationSucceeded, phase) |
| 803 | + assert.Len(t, resources, 1) |
| 804 | + assert.Equal(t, synccommon.ResultCodePruned, resources[0].Status) |
| 805 | + assert.Equal(t, "pruned", resources[0].Message) |
| 806 | + }) |
| 807 | + } |
| 808 | +} |
| 809 | + |
772 | 810 | // // make sure Validate=false means we don't validate
|
773 | 811 | func TestSyncOptionValidate(t *testing.T) {
|
774 | 812 | tests := []struct {
|
|
0 commit comments