github.com/argoproj/argo-cd/v3@v3.2.1/test/e2e/app_deletion_test.go (about)

     1  package e2e
     2  
     3  import (
     4  	"testing"
     5  
     6  	. "github.com/argoproj/gitops-engine/pkg/sync/common"
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  
    10  	. "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
    11  	. "github.com/argoproj/argo-cd/v3/test/e2e/fixture"
    12  	. "github.com/argoproj/argo-cd/v3/test/e2e/fixture/app"
    13  )
    14  
    15  // when a app gets stuck in sync, and we try to delete it, it won't delete, instead we must then terminate it
    16  // and deletion will then just happen
    17  func TestDeletingAppStuckInSync(t *testing.T) {
    18  	Given(t).
    19  		And(func() {
    20  			require.NoError(t, SetResourceOverrides(map[string]ResourceOverride{
    21  				"ConfigMap": {
    22  					HealthLua: `return { status = obj.annotations and obj.annotations['health'] or 'Progressing' }`,
    23  				},
    24  			}))
    25  		}).
    26  		Async(true).
    27  		Path("hook-custom-health").
    28  		When().
    29  		CreateApp().
    30  		Sync().
    31  		Then().
    32  		// stuck in running state
    33  		Expect(OperationPhaseIs(OperationRunning)).
    34  		Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
    35  		When().
    36  		Delete(true).
    37  		Then().
    38  		// delete is ignored, still stuck in running state
    39  		Expect(OperationPhaseIs(OperationRunning)).
    40  		When().
    41  		TerminateOp().
    42  		Then().
    43  		// delete is successful
    44  		Expect(DoesNotExist())
    45  }
    46  
    47  func TestDeletingAppByLabel(t *testing.T) {
    48  	Given(t).
    49  		Path(guestbookPath).
    50  		When().
    51  		CreateApp("--label=foo=bar").
    52  		Sync().
    53  		Then().
    54  		Expect(SyncStatusIs(SyncStatusCodeSynced)).
    55  		When().
    56  		IgnoreErrors().
    57  		DeleteBySelector("foo=baz").
    58  		Then().
    59  		// delete is unsuccessful since no selector match
    60  		AndCLIOutput(
    61  			func(_ string, err error) {
    62  				assert.ErrorContains(t, err, "no apps match selector foo=baz")
    63  			},
    64  		).
    65  		When().
    66  		DeleteBySelector("foo=bar").
    67  		Then().
    68  		// delete is successful
    69  		Expect(DoesNotExist())
    70  }
    71  
    72  func TestDeletingAppByLabelWait(t *testing.T) {
    73  	Given(t).
    74  		Path(guestbookPath).
    75  		When().
    76  		CreateApp("--label=foo=bar").
    77  		Sync().
    78  		Then().
    79  		Expect(SyncStatusIs(SyncStatusCode(SyncStatusCodeSynced))).
    80  		When().
    81  		DeleteBySelectorWithWait("foo=bar").
    82  		Then().
    83  		// delete is successful
    84  		Expect(DoesNotExistNow())
    85  }