Skip to content

Commit

Permalink
test/e2e/atlas/kube: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
s-urbaniak committed Jan 20, 2025
1 parent 3b98d4a commit a3a1698
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
24 changes: 18 additions & 6 deletions internal/kubernetes/operator/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"errors"
"fmt"

"k8s.io/client-go/util/retry"

"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/kubernetes"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/kubernetes/operator/features"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/kubernetes/operator/resources"
Expand Down Expand Up @@ -148,9 +150,9 @@ func (i *Install) ensureProject(orgID, projectName string) (*admin.Group, error)

project, err = i.atlasStore.CreateProject(&admin.CreateProjectApiParams{
Group: &admin.Group{
Name: projectName,
OrgId: orgID,
RegionUsageRestrictions: pointer.Get(""),
Name: projectName,
OrgId: orgID,
//RegionUsageRestrictions: pointer.Get(""),
WithDefaultAlertsSettings: pointer.Get(true),
},
})
Expand Down Expand Up @@ -284,10 +286,20 @@ func (i *Install) ensureCredentialsAssignment(ctx context.Context) error {
}
}

project.Spec.ConnectionSecret = connectionSecret
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
if err := i.kubectl.Get(ctx, client.ObjectKeyFromObject(&project), &project); err != nil {
return err
}

project.Spec.ConnectionSecret = connectionSecret

if err = i.kubectl.Update(ctx, &project); err != nil {
return fmt.Errorf("failed to update atlas project %s", i.projectName)
if err := i.kubectl.Update(ctx, &project); err != nil {

Check failure on line 296 in internal/kubernetes/operator/install.go

View workflow job for this annotation

GitHub Actions / lint

if-return: redundant if ...; err != nil check, just return error instead. (revive)
return err
}
return nil
})
if err != nil {
return fmt.Errorf("failed to update atlas project %s: %w", i.projectName, err)
}
}

Expand Down
22 changes: 11 additions & 11 deletions test/e2e/atlas/kubernetes_operator_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func TestKubernetesOperatorInstall(t *testing.T) {
"install",
"--operatorVersion", "1.1.0")
cmd.Env = os.Environ()
resp, inErr := e2e.RunAndGetStdOut(cmd)
require.Error(t, inErr, string(resp))
assert.Equal(t, "Error: version 1.1.0 is not supported\n", string(resp))
_, inErr := e2e.RunAndGetStdOutAndErr(cmd)
require.Error(t, inErr, inErr)

Check failure on line 57 in test/e2e/atlas/kubernetes_operator_install_test.go

View workflow job for this annotation

GitHub Actions / lint

error-is-as: invalid usage of require.Error, use require.ErrorIs instead (testifylint)
assert.Equal(t, "Error: version 1.1.0 is not supported\n (exit status 1)", inErr.Error())
})

t.Run("should failed to install a non-existing version of the operator", func(t *testing.T) {
Expand All @@ -65,9 +65,9 @@ func TestKubernetesOperatorInstall(t *testing.T) {
"install",
"--operatorVersion", "100.0.0")
cmd.Env = os.Environ()
resp, inErr := e2e.RunAndGetStdOut(cmd)
require.Error(t, inErr, string(resp))
assert.Equal(t, "Error: version 100.0.0 is not supported\n", string(resp))
_, inErr := e2e.RunAndGetStdOutAndErr(cmd)
require.Error(t, inErr, inErr)

Check failure on line 69 in test/e2e/atlas/kubernetes_operator_install_test.go

View workflow job for this annotation

GitHub Actions / lint

error-is-as: invalid usage of require.Error, use require.ErrorIs instead (testifylint)
assert.Equal(t, "Error: version 100.0.0 is not supported\n (exit status 1)", inErr.Error())
})

t.Run("should failed when unable to setup connection to the cluster", func(t *testing.T) {
Expand All @@ -77,9 +77,9 @@ func TestKubernetesOperatorInstall(t *testing.T) {
"install",
"--kubeconfig", "/path/to/non/existing/config")
cmd.Env = os.Environ()
resp, inErr := e2e.RunAndGetStdOut(cmd)
require.Error(t, inErr, string(resp))
assert.Equal(t, "Error: unable to prepare client configuration: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable\n", string(resp))
_, inErr := e2e.RunAndGetStdOutAndErr(cmd)
require.Error(t, inErr, inErr)

Check failure on line 81 in test/e2e/atlas/kubernetes_operator_install_test.go

View workflow job for this annotation

GitHub Actions / lint

error-is-as: invalid usage of require.Error, use require.ErrorIs instead (testifylint)
assert.Equal(t, "Error: unable to prepare client configuration: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable\n (exit status 1)", inErr.Error())
})

t.Run("should install operator with default options", func(t *testing.T) {
Expand Down Expand Up @@ -179,8 +179,8 @@ func TestKubernetesOperatorInstall(t *testing.T) {
"--import",
"--kubeContext", context)
cmd.Env = os.Environ()
resp, inErr := e2e.RunAndGetStdOut(cmd)
require.NoError(t, inErr, string(resp))
resp, inErr := e2e.RunAndGetStdOutAndErr(cmd)
require.NoError(t, inErr, inErr)

Check failure on line 183 in test/e2e/atlas/kubernetes_operator_install_test.go

View workflow job for this annotation

GitHub Actions / lint

error-is-as: invalid usage of require.NoError, use require.NotErrorIs instead (testifylint)
assert.Equal(t, "Atlas Kubernetes Operator installed successfully\n", string(resp))

checkDeployment(t, operator, operatorNamespace)
Expand Down

0 comments on commit a3a1698

Please sign in to comment.