Skip to content

CLOUDP-57657: Add E2E test for updating an atlas cluster with a file #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions e2e/atlas_clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ func TestAtlasClusters(t *testing.T) {
}
})

clusterFileName := fmt.Sprintf("e2e-cluster-%v", r.Uint32())
t.Run("Create via file", func(t *testing.T) {
cmd := exec.Command(cliPath,
atlasEntity,
clustersEntity,
"create",
clusterFileName,
"--file=create_cluster_test.json")
cmd.Env = os.Environ()
resp, err := cmd.CombinedOutput()
Expand All @@ -161,19 +163,42 @@ func TestAtlasClusters(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}

ensureCluster(t, cluster, clusterName, "4.0", 10)
ensureCluster(t, cluster, clusterFileName, "4.0", 10)
})

t.Run("Delete", func(t *testing.T) {
cmd := exec.Command(cliPath, atlasEntity, clustersEntity, "delete", "TestMultiRegionCluster", "--force")
t.Run("Update via file", func(t *testing.T) {
cmd := exec.Command(cliPath,
atlasEntity,
clustersEntity,
"update",
clusterFileName,
"--file=update_cluster_test.json")
cmd.Env = os.Environ()
resp, err := cmd.CombinedOutput()

if err != nil {
t.Fatalf("unexpected error: %v, resp: %v", err, string(resp))
}

cluster := new(mongodbatlas.Cluster)
err = json.Unmarshal(resp, cluster)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

ensureCluster(t, cluster, clusterFileName, "4.0", 25)
})

t.Run("Delete file creation", func(t *testing.T) {
cmd := exec.Command(cliPath, atlasEntity, clustersEntity, "delete", clusterFileName, "--force")
cmd.Env = os.Environ()
resp, err := cmd.CombinedOutput()

if err != nil {
t.Fatalf("unexpected error: %v, resp: %v", err, string(resp))
}

expected := fmt.Sprintf("Cluster '%s' deleted\n", "TestMultiRegionCluster")
expected := fmt.Sprintf("Cluster '%s' deleted\n", clusterFileName)
if string(resp) != expected {
t.Errorf("got=%#v\nwant=%#v\n", string(resp), expected)
}
Expand Down
5 changes: 2 additions & 3 deletions e2e/create_cluster_test.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "TestMultiRegionCluster",
"diskSizeGB": 25,
"diskSizeGB": 10,
"numShards": 1,
"providerSettings": {
"providerName": "GCP",
Expand Down Expand Up @@ -31,5 +30,5 @@
},
"zoneName" : "Zone 1"
} ],
"backupEnabled": true
"backupEnabled": false
}
3 changes: 3 additions & 0 deletions e2e/update_cluster_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"diskSizeGB": 25
}
8 changes: 7 additions & 1 deletion internal/cli/atlas_clusters_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func (opts *atlasClustersCreateOpts) newCluster() (*atlas.Cluster, error) {
cluster.ClusterType = replicaSet
opts.applyOpts(cluster)
}

if opts.name != "" {
cluster.Name = opts.name
}

cluster.GroupID = opts.ProjectID()
return cluster, nil
}
Expand All @@ -91,7 +96,6 @@ func (opts *atlasClustersCreateOpts) applyOpts(out *atlas.Cluster) {
out.BackupEnabled = &opts.backup
out.DiskSizeGB = &opts.diskSizeGB
out.MongoDBMajorVersion = opts.mdbVersion
out.Name = opts.name
out.ProviderSettings = opts.newProviderSettings()
out.ReplicationSpecs = []atlas.ReplicationSpec{replicationSpec}
}
Expand Down Expand Up @@ -159,6 +163,8 @@ func AtlasClustersCreateBuilder() *cobra.Command {
if len(args) == 0 {
return errMissingClusterName
}
}
if len(args) != 0 {
opts.name = args[0]
}
return opts.init()
Expand Down
11 changes: 7 additions & 4 deletions internal/cli/atlas_clusters_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func (opts *atlasClustersUpdateOpts) cluster() (*atlas.Cluster, error) {
if opts.filename != "" {
cluster = new(atlas.Cluster)
err = file.Load(opts.fs, opts.filename, cluster)
if opts.name != "" {
cluster.Name = opts.name
}
} else {
cluster, err = opts.store.Cluster(opts.projectID, opts.name)
}
Expand Down Expand Up @@ -112,10 +115,10 @@ func AtlasClustersUpdateBuilder() *cobra.Command {
Example: ` mongocli atlas cluster update myCluster --projectId=1 --instanceSize M2 --mdbVersion 4.2 --diskSizeGB 2`,
Args: cobra.MaximumNArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
if opts.filename == "" {
if len(args) == 0 {
return errMissingClusterName
}
if opts.filename == "" && len(args) == 0 {
return errMissingClusterName
}
if len(args) != 0 {
opts.name = args[0]
}
return opts.init()
Expand Down