github.com/argoproj/argo-cd/v2@v2.10.5/test/e2e/app_namespaces_test.go (about)

     1  package e2e
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	. "github.com/argoproj/gitops-engine/pkg/sync/common"
     8  	"github.com/stretchr/testify/assert"
     9  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    10  	"k8s.io/apimachinery/pkg/types"
    11  
    12  	. "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
    13  	. "github.com/argoproj/argo-cd/v2/test/e2e/fixture"
    14  	. "github.com/argoproj/argo-cd/v2/test/e2e/fixture/app"
    15  	. "github.com/argoproj/argo-cd/v2/util/argo"
    16  	. "github.com/argoproj/argo-cd/v2/util/errors"
    17  )
    18  
    19  func TestAppCreationInOtherNamespace(t *testing.T) {
    20  	ctx := Given(t)
    21  	ctx.
    22  		Path(guestbookPath).
    23  		SetAppNamespace(AppNamespace()).
    24  		When().
    25  		CreateApp().
    26  		Then().
    27  		Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
    28  		And(func(app *Application) {
    29  			assert.Equal(t, ctx.AppName(), app.Name)
    30  			assert.Equal(t, AppNamespace(), app.Namespace)
    31  			assert.Equal(t, RepoURL(RepoURLTypeFile), app.Spec.GetSource().RepoURL)
    32  			assert.Equal(t, guestbookPath, app.Spec.GetSource().Path)
    33  			assert.Equal(t, DeploymentNamespace(), app.Spec.Destination.Namespace)
    34  			assert.Equal(t, KubernetesInternalAPIServerAddr, app.Spec.Destination.Server)
    35  		}).
    36  		Expect(NamespacedEvent(ctx.AppNamespace(), EventReasonResourceCreated, "create")).
    37  		And(func(_ *Application) {
    38  			// app should be listed
    39  			output, err := RunCli("app", "list")
    40  			assert.NoError(t, err)
    41  			assert.Contains(t, output, ctx.AppName())
    42  		}).
    43  		When().
    44  		// ensure that create is idempotent
    45  		CreateApp().
    46  		Then().
    47  		Given().
    48  		Revision("master").
    49  		When().
    50  		// ensure that update replaces spec and merge labels and annotations
    51  		And(func() {
    52  			FailOnErr(AppClientset.ArgoprojV1alpha1().Applications(AppNamespace()).Patch(context.Background(),
    53  				ctx.AppName(), types.MergePatchType, []byte(`{"metadata": {"labels": { "test": "label" }, "annotations": { "test": "annotation" }}}`), metav1.PatchOptions{}))
    54  		}).
    55  		CreateApp("--upsert").
    56  		Then().
    57  		And(func(app *Application) {
    58  			assert.Equal(t, "label", app.Labels["test"])
    59  			assert.Equal(t, "annotation", app.Annotations["test"])
    60  			assert.Equal(t, "master", app.Spec.GetSource().TargetRevision)
    61  		})
    62  }
    63  
    64  func TestForbiddenNamespace(t *testing.T) {
    65  	ctx := Given(t)
    66  	ctx.
    67  		Path(guestbookPath).
    68  		SetAppNamespace("forbidden").
    69  		When().
    70  		IgnoreErrors().
    71  		CreateApp().
    72  		Then().
    73  		Expect(DoesNotExist())
    74  }
    75  
    76  func TestDeletingNamespacedAppStuckInSync(t *testing.T) {
    77  	ctx := Given(t)
    78  	ctx.And(func() {
    79  		SetResourceOverrides(map[string]ResourceOverride{
    80  			"ConfigMap": {
    81  				HealthLua: `return { status = obj.annotations and obj.annotations['health'] or 'Progressing' }`,
    82  			},
    83  		})
    84  	}).
    85  		Async(true).
    86  		SetAppNamespace(AppNamespace()).
    87  		Path("hook-custom-health").
    88  		When().
    89  		CreateApp().
    90  		Sync().
    91  		Then().
    92  		// stuck in running state
    93  		Expect(OperationPhaseIs(OperationRunning)).
    94  		Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
    95  		When().
    96  		Delete(true).
    97  		Then().
    98  		// delete is ignored, still stuck in running state
    99  		Expect(OperationPhaseIs(OperationRunning)).
   100  		When().
   101  		TerminateOp().
   102  		Then().
   103  		// delete is successful
   104  		Expect(DoesNotExist())
   105  }