Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
Signed-off-by: Ilia Medvedev <[email protected]>
  • Loading branch information
ilia-medvedev-codefresh committed Aug 16, 2024
1 parent 3771cff commit 656b859
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 50 deletions.
49 changes: 30 additions & 19 deletions test/e2e/admin_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package e2e

import (
"context"
"testing"

"github.com/argoproj/gitops-engine/pkg/utils/kube"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/argoproj/argo-cd/v2/test/e2e/fixture"
fixtureutils "github.com/argoproj/argo-cd/v2/test/e2e/fixture/admin/utils"
Expand All @@ -28,41 +31,49 @@ func TestBackupExportImport(t *testing.T) {
CreateApp().
Then().
And(func(app *Application) {
assert.Equal(t, app.Name, "exported-app1")
assert.Equal(t, app.Namespace, fixture.TestNamespace())
assert.Equal(t, "exported-app1", app.Name)
assert.Equal(t, fixture.TestNamespace(), app.Namespace)
})

// Create app in other namespace
appctx.
Path(guestbookPath).
Name("exported-app-oter-namespace").
Name("exported-app-other-namespace").
SetAppNamespace(fixture.AppNamespace()).
When().
CreateApp().
Then().
And(func(app *Application) {
assert.Equal(t, app.Name, "exported-app-oter-namespace")
assert.Equal(t, app.Namespace, fixture.AppNamespace())
assert.Equal(t, "exported-app-other-namespace", app.Name)
assert.Equal(t, fixture.AppNamespace(), app.Namespace)
})

ctx.
When().
RunExport().
Then().
AndCLIOutput(func(output string, err error) {
exportRawOutput = output
assert.NoError(t, err, "export finished with error")
exportResources, err := fixtureutils.GetExportedResourcesFromOutput(output)
assert.NoError(t, err, "export format not valid")
assert.True(t, exportResources.HasResource(kube.NewResourceKey("", "ConfigMap", "", "argocd-cm")), "argocd-cm not found in export")
assert.True(t, exportResources.HasResource(kube.NewResourceKey(ApplicationSchemaGroupVersionKind.Group, ApplicationSchemaGroupVersionKind.Kind, "", "exported-app1")), "test namespace application not in export")
assert.True(t, exportResources.HasResource(kube.NewResourceKey(ApplicationSchemaGroupVersionKind.Group, ApplicationSchemaGroupVersionKind.Kind, fixture.AppNamespace(), "exported-app-oter-namespace")), "app namespace application not in export")
})
RunExport().
Then().
AndCLIOutput(func(output string, err error) {
require.NoError(t, err, "export finished with error")
exportRawOutput = output
exportResources, err := fixtureutils.GetExportedResourcesFromOutput(output)
require.NoError(t, err, "export format not valid")
assert.True(t, exportResources.HasResource(kube.NewResourceKey("", "ConfigMap", "", "argocd-cm")), "argocd-cm not found in export")
assert.True(t, exportResources.HasResource(kube.NewResourceKey(ApplicationSchemaGroupVersionKind.Group, ApplicationSchemaGroupVersionKind.Kind, "", "exported-app1")), "test namespace application not in export")
assert.True(t, exportResources.HasResource(kube.NewResourceKey(ApplicationSchemaGroupVersionKind.Group, ApplicationSchemaGroupVersionKind.Kind, fixture.AppNamespace(), "exported-app-other-namespace")), "app namespace application not in export")
})

// Test import - cleanup
// Test import - clean state
ctx = Given(t)

ctx.
When().
RunImport(exportRawOutput)
When().
RunImport(exportRawOutput).
Then().
AndCLIOutput(func(output string, err error) {
require.NoError(t, err, "import finished with error")
_, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Get(context.Background(), "exported-app1", v1.GetOptions{})
require.NoError(t, err, "failed getting test namespace application after import")
_, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Get(context.Background(), "exported-app-other-namespace", v1.GetOptions{})
require.NoError(t, err, "failed getting app namespace application after import")
})
}
1 change: 0 additions & 1 deletion test/e2e/fixture/admin/consequences.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func (c *Consequences) AndCLIOutput(block func(output string, err error)) *Conse
return c
}


func (c *Consequences) Given() *Context {
return c.context
}
Expand Down
6 changes: 2 additions & 4 deletions test/e2e/fixture/admin/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ type Context struct {
// seconds
timeout int
name string
applicationNamespaces []string
applicationsetNamespaces []string
}

func Given(t *testing.T) *Context {
Expand All @@ -28,8 +26,8 @@ func GivenWithSameState(t *testing.T) *Context {
// for any context.
timeout := env.ParseNumFromEnv("ARGOCD_E2E_DEFAULT_TIMEOUT", 20, 0, 180)
return &Context{
t: t,
name: fixture.Name(),
t: t,
name: fixture.Name(),
timeout: timeout,
}
}
Expand Down
3 changes: 0 additions & 3 deletions test/e2e/fixture/admin/fixture.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package admin

import (

"github.com/argoproj/argo-cd/v2/test/e2e/fixture"


)

// For admin CLI with kubernetes context
Expand Down
39 changes: 19 additions & 20 deletions test/e2e/fixture/admin/utils/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,35 @@ import (
type ExportedResources []unstructured.Unstructured

func GetExportedResourcesFromOutput(output string) (ExportedResources, error) {

var resources []unstructured.Unstructured
docs := strings.Split(output, "---")
docs := strings.Split(output, "---")

for _, doc := range docs {
doc = strings.TrimSpace(doc)
if len(doc) == 0 {
continue
}
for _, doc := range docs {
doc = strings.TrimSpace(doc)
if len(doc) == 0 {
continue
}

var resourceData map[string]interface{}
var resourceData map[string]interface{}

if err := yaml.Unmarshal([]byte(doc), &resourceData); err != nil {
return nil, fmt.Errorf("error unmarshaling YAML: %w", err)
}
if err := yaml.Unmarshal([]byte(doc), &resourceData); err != nil {
return nil, fmt.Errorf("error unmarshaling YAML: %w", err)
}

resource := unstructured.Unstructured{Object: resourceData}
resources = append(resources, resource)
}
resource := unstructured.Unstructured{Object: resourceData}
resources = append(resources, resource)
}

return resources, nil
return resources, nil
}

func (e ExportedResources) HasResource(resource kube.ResourceKey) bool {
for _, res := range e {
if (res.GetObjectKind().GroupVersionKind().Group == resource.Group &&
res.GetKind() == resource.Kind &&
res.GetName() == resource.Name &&
res.GetNamespace() == resource.Namespace) {
return true
if res.GetObjectKind().GroupVersionKind().Group == resource.Group &&
res.GetKind() == resource.Kind &&
res.GetName() == resource.Name &&
res.GetNamespace() == resource.Namespace {
return true
}
}

Expand Down
5 changes: 2 additions & 3 deletions test/e2e/fixture/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,15 +744,14 @@ func RunCli(args ...string) (string, error) {
return RunCliWithStdin("", false, args...)
}

func RunCliWithStdin(stdin string, isKubeConextOnlyCli bool,args ...string) (string, error) {

func RunCliWithStdin(stdin string, isKubeConextOnlyCli bool, args ...string) (string, error) {
if plainText {
args = append(args, "--plaintext")
}

// For commands executed with Kubernetes context server argument causes a conflict (for those commands server argument is for KubeAPI server), also authentication is not required
if isKubeConextOnlyCli {
args = append(args, "--namespace" ,TestNamespace())
args = append(args, "--namespace", TestNamespace())
} else {
args = append(args, "--server", apiServerAddress, "--auth-token", token)
}
Expand Down

0 comments on commit 656b859

Please sign in to comment.