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

     1  package e2e
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/argoproj/gitops-engine/pkg/utils/kube"
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    10  
    11  	. "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
    12  	"github.com/argoproj/argo-cd/v3/test/e2e/fixture"
    13  	. "github.com/argoproj/argo-cd/v3/test/e2e/fixture/admin"
    14  	. "github.com/argoproj/argo-cd/v3/test/e2e/fixture/admin/utils"
    15  	appfixture "github.com/argoproj/argo-cd/v3/test/e2e/fixture/app"
    16  )
    17  
    18  func TestBackupExportImport(t *testing.T) {
    19  	var exportRawOutput string
    20  	ctx := Given(t)
    21  	// Create application in argocd namespace
    22  	appctx := appfixture.GivenWithSameState(t)
    23  
    24  	// Create application in test namespace
    25  	appctx.
    26  		Path(guestbookPath).
    27  		Name("exported-app1").
    28  		When().
    29  		CreateApp().
    30  		Then().
    31  		And(func(app *Application) {
    32  			assert.Equal(t, "exported-app1", app.Name)
    33  			assert.Equal(t, fixture.TestNamespace(), app.Namespace)
    34  		})
    35  
    36  	// Create app in other namespace
    37  	appctx.
    38  		Path(guestbookPath).
    39  		Name("exported-app-other-namespace").
    40  		SetAppNamespace(fixture.AppNamespace()).
    41  		When().
    42  		CreateApp().
    43  		Then().
    44  		And(func(app *Application) {
    45  			assert.Equal(t, "exported-app-other-namespace", app.Name)
    46  			assert.Equal(t, fixture.AppNamespace(), app.Namespace)
    47  		})
    48  
    49  	ctx.
    50  		When().
    51  		RunExport().
    52  		Then().
    53  		AndCLIOutput(func(output string, err error) {
    54  			require.NoError(t, err, "export finished with error")
    55  			exportRawOutput = output
    56  		}).
    57  		AndExportedResources(func(exportResources *ExportedResources, err error) {
    58  			require.NoError(t, err, "export format not valid")
    59  			assert.True(t, exportResources.HasResource(kube.NewResourceKey("", "ConfigMap", "", "argocd-cm")), "argocd-cm not found in export")
    60  			assert.True(t, exportResources.HasResource(kube.NewResourceKey(ApplicationSchemaGroupVersionKind.Group, ApplicationSchemaGroupVersionKind.Kind, "", "exported-app1")), "test namespace application not in export")
    61  			assert.True(t, exportResources.HasResource(kube.NewResourceKey(ApplicationSchemaGroupVersionKind.Group, ApplicationSchemaGroupVersionKind.Kind, fixture.AppNamespace(), "exported-app-other-namespace")), "app namespace application not in export")
    62  		})
    63  
    64  	// Test import - clean state
    65  	ctx = Given(t)
    66  
    67  	ctx.
    68  		When().
    69  		RunImport(exportRawOutput).
    70  		Then().
    71  		AndCLIOutput(func(_ string, err error) {
    72  			require.NoError(t, err, "import finished with error")
    73  			_, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Get(t.Context(), "exported-app1", metav1.GetOptions{})
    74  			require.NoError(t, err, "failed getting test namespace application after import")
    75  			_, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Get(t.Context(), "exported-app-other-namespace", metav1.GetOptions{})
    76  			require.NoError(t, err, "failed getting app namespace application after import")
    77  		})
    78  }