Skip to content

Commit

Permalink
e2e fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
swattyT committed May 28, 2023
1 parent 7316c5d commit 0b0e1f8
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 76 deletions.
96 changes: 50 additions & 46 deletions internal/cli/atlas/clusters/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ func TestLabelExists(t *testing.T) {
}

func TestRemoveReadOnlyAttributes(t *testing.T) {
var (
id = "Test"
testVar = "test"
specId = "22"
shards = 2
zone = "1"
timeStamp = time.Now()
)
tests := []struct {
name string
args *atlasv2.ClusterDescriptionV15
Expand All @@ -147,71 +155,65 @@ func TestRemoveReadOnlyAttributes(t *testing.T) {
{
name: "One AdvancedReplicationSpec",
args: &atlasv2.ClusterDescriptionV15{
Id: pointer.Get("Test"),
MongoDBVersion: pointer.Get("test"),
StateName: pointer.Get("test"),
Id: &id,
MongoDBVersion: &testVar,
StateName: &testVar,
ReplicationSpecs: []atlasv2.ReplicationSpec{
{
Id: pointer.Get("22"),
NumShards: pointer.Get(2),
ZoneName: pointer.Get("1"),
Id: &specId,
NumShards: &shards,
ZoneName: &zone,
},
},
CreateDate: pointer.Get(time.Now()),
CreateDate: &timeStamp,
},
want: &atlasv2.ClusterDescriptionV15{
Id: nil,
MongoDBVersion: nil,
StateName: nil,
ReplicationSpecs: []atlasv2.ReplicationSpec{
{
NumShards: pointer.Get(2),
ZoneName: pointer.Get("1"),
NumShards: &shards,
ZoneName: &zone,
},
},
},
},
{
name: "More AdvancedReplicationSpecs",
args: &atlasv2.ClusterDescriptionV15{
Id: pointer.Get("Test"),
MongoDBVersion: pointer.Get("test"),
StateName: pointer.Get("test"),
Id: &id,
MongoDBVersion: &testVar,
StateName: &testVar,
ReplicationSpecs: []atlasv2.ReplicationSpec{
{
Id: pointer.Get("22"),
NumShards: pointer.Get(2),
ZoneName: pointer.Get("1"),
Id: &specId,
NumShards: &shards,
ZoneName: &zone,
},
{
Id: pointer.Get("22"),
NumShards: pointer.Get(2),
ZoneName: pointer.Get("1"),
Id: &specId,
NumShards: &shards,
ZoneName: &zone,
},
{
Id: pointer.Get("22"),
NumShards: pointer.Get(2),
ZoneName: pointer.Get("1"),
Id: &specId,
NumShards: &shards,
ZoneName: &zone,
},
},
CreateDate: pointer.Get(time.Now()),
CreateDate: &timeStamp,
},
want: &atlasv2.ClusterDescriptionV15{
Id: nil,
MongoDBVersion: nil,
StateName: nil,
ReplicationSpecs: []atlasv2.ReplicationSpec{
{
NumShards: pointer.Get(2),
ZoneName: pointer.Get("1"),
NumShards: &shards,
ZoneName: &zone,
},
{
NumShards: pointer.Get(2),
ZoneName: pointer.Get("1"),
NumShards: &shards,
ZoneName: &zone,
},
{
NumShards: pointer.Get(2),
ZoneName: pointer.Get("1"),
NumShards: &shards,
ZoneName: &zone,
},
},
},
Expand All @@ -221,32 +223,32 @@ func TestRemoveReadOnlyAttributes(t *testing.T) {
args: &atlasv2.ClusterDescriptionV15{
ReplicationSpecs: []atlasv2.ReplicationSpec{
{
NumShards: pointer.Get(2),
ZoneName: pointer.Get("1"),
NumShards: &shards,
ZoneName: &zone,
},
{
NumShards: pointer.Get(2),
ZoneName: pointer.Get("1"),
NumShards: &shards,
ZoneName: &zone,
},
{
NumShards: pointer.Get(2),
ZoneName: pointer.Get("1"),
NumShards: &shards,
ZoneName: &zone,
},
},
},
want: &atlasv2.ClusterDescriptionV15{
ReplicationSpecs: []atlasv2.ReplicationSpec{
{
NumShards: pointer.Get(2),
ZoneName: pointer.Get("1"),
NumShards: &shards,
ZoneName: &zone,
},
{
NumShards: pointer.Get(2),
ZoneName: pointer.Get("1"),
NumShards: &shards,
ZoneName: &zone,
},
{
NumShards: pointer.Get(2),
ZoneName: pointer.Get("1"),
NumShards: &shards,
ZoneName: &zone,
},
},
},
Expand All @@ -259,6 +261,8 @@ func TestRemoveReadOnlyAttributes(t *testing.T) {
t.Run(name, func(t *testing.T) {
RemoveReadOnlyAttributes(arg)
if diff := deep.Equal(arg, want); diff != nil {
t.Log(arg)
t.Log(want)
t.Error(diff)
}
})
Expand Down
10 changes: 5 additions & 5 deletions internal/cli/atlas/quickstart/cluster_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ package quickstart
import (
"errors"
"fmt"
"github.com/mongodb/mongodb-atlas-cli/internal/pointer"
atlasv2 "go.mongodb.org/atlas-sdk/admin"
"strings"

"github.com/AlecAivazis/survey/v2"
"github.com/mongodb/mongodb-atlas-cli/internal/cli"
"github.com/mongodb/mongodb-atlas-cli/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/internal/pointer"
"github.com/mongodb/mongodb-atlas-cli/internal/search"
"github.com/mongodb/mongodb-atlas-cli/internal/telemetry"
"github.com/mongodb/mongodb-atlas-cli/internal/usage"
atlasv2 "go.mongodb.org/atlas-sdk/admin"
atlas "go.mongodb.org/atlas/mongodbatlas"
)

Expand Down Expand Up @@ -224,22 +224,22 @@ func (opts *Opts) defaultRegions() ([]string, error) {
return nil, errors.New("no regions available")
}

availableRegions := cloudProviders.Results[0].InstanceSizes[0].AvailableRegions
availableRegions := cloudProviders.Results[0].InstanceSizes[0].GetAvailableRegions()

defaultRegions := make([]string, 0, len(availableRegions))
popularRegionIndex := search.DefaultRegion(availableRegions)

if popularRegionIndex != -1 {
// the most popular region must be the first in the list
popularRegion := availableRegions[popularRegionIndex]
defaultRegions = append(defaultRegions, popularRegion.Name)
defaultRegions = append(defaultRegions, popularRegion.GetName())

// remove popular region from availableRegions
availableRegions = append(availableRegions[:popularRegionIndex], availableRegions[popularRegionIndex+1:]...)
}

for _, v := range availableRegions {
defaultRegions = append(defaultRegions, v.Name)
defaultRegions = append(defaultRegions, v.GetName())
}

return defaultRegions, nil
Expand Down
5 changes: 3 additions & 2 deletions internal/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package search

import (
atlasv2 "go.mongodb.org/atlas-sdk/admin"
atlas "go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
"go.mongodb.org/ops-manager/search"
Expand Down Expand Up @@ -54,9 +55,9 @@ func AtlasClusterExists(clusters []atlas.Cluster, name string) bool {
}

// DefaultRegion returns the index of the default region.
func DefaultRegion(regions []*atlas.AvailableRegion) int {
func DefaultRegion(regions []atlasv2.AvailableRegion) int {
for i, v := range regions {
if v.Default {
if v.GetDefault() {
return i
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/search/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestDefaultRegion(t *testing.T) {
want: 1,
},
{
input: []*atlas.AvailableRegion{
input: []atlas.AvailableRegion{
{
Name: "test",
Default: false,
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/atlas/clusters_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package atlas_test
import (
"encoding/json"
"fmt"
atlasv2 "go.mongodb.org/atlas-sdk/admin"
"os"
"os/exec"
"testing"
Expand All @@ -26,7 +27,6 @@ import (
"github.com/mongodb/mongodb-atlas-cli/test/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mongodb.org/atlas/mongodbatlas"
)

func TestClustersFile(t *testing.T) {
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestClustersFile(t *testing.T) {
resp, err := cmd.CombinedOutput()
req.NoError(err, string(resp))

var cluster mongodbatlas.AdvancedCluster
var cluster atlasv2.ClusterDescriptionV15
err = json.Unmarshal(resp, &cluster)
req.NoError(err)

Expand Down Expand Up @@ -91,7 +91,7 @@ func TestClustersFile(t *testing.T) {
resp, err := cmd.CombinedOutput()
req.NoError(err, string(resp))

var cluster mongodbatlas.AdvancedCluster
var cluster atlasv2.ClusterDescriptionV15
err = json.Unmarshal(resp, &cluster)
req.NoError(err)

Expand Down
14 changes: 7 additions & 7 deletions test/e2e/atlas/clusters_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestClustersFlags(t *testing.T) {
resp, err := cmd.CombinedOutput()
req.NoError(err, string(resp))

var cluster *mongodbatlas.AdvancedCluster
var cluster *atlasv2.ClusterDescriptionV15
err = json.Unmarshal(resp, &cluster)
req.NoError(err)

Expand Down Expand Up @@ -98,12 +98,12 @@ func TestClustersFlags(t *testing.T) {
resp, err := cmd.CombinedOutput()
req.NoError(err, string(resp))

var job *mongodbatlas.SampleDatasetJob
var job *atlasv2.SampleDatasetStatus
err = json.Unmarshal(resp, &job)
req.NoError(err)

a := assert.New(t)
a.Equal(clusterName, job.ClusterName)
a.Equal(clusterName, job.GetClusterName())
})

t.Run("List", func(t *testing.T) {
Expand All @@ -116,7 +116,7 @@ func TestClustersFlags(t *testing.T) {
resp, err := cmd.CombinedOutput()
req.NoError(err, string(resp))

var clusters mongodbatlas.AdvancedClustersResponse
var clusters atlasv2.PaginatedClusterDescriptionV15
err = json.Unmarshal(resp, &clusters)
req.NoError(err)

Expand All @@ -135,12 +135,12 @@ func TestClustersFlags(t *testing.T) {
resp, err := cmd.CombinedOutput()
req.NoError(err, string(resp))

var cluster mongodbatlas.AdvancedCluster
var cluster atlasv2.ClusterDescriptionV15
err = json.Unmarshal(resp, &cluster)
req.NoError(err)

a := assert.New(t)
a.Equal(clusterName, cluster.Name)
a.Equal(clusterName, cluster.GetName())
})

t.Run("Describe Connection String", func(t *testing.T) {
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestClustersFlags(t *testing.T) {
resp, err := cmd.CombinedOutput()
req.NoError(err, string(resp))

var cluster mongodbatlas.AdvancedCluster
var cluster atlasv2.ClusterDescriptionV15
err = json.Unmarshal(resp, &cluster)
req.NoError(err)

Expand Down
8 changes: 4 additions & 4 deletions test/e2e/atlas/clusters_m0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package atlas_test
import (
"encoding/json"
"fmt"
atlasv2 "go.mongodb.org/atlas-sdk/admin"
"os"
"os/exec"
"testing"

"github.com/mongodb/mongodb-atlas-cli/test/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mongodb.org/atlas/mongodbatlas"
)

const (
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestClustersM0Flags(t *testing.T) {
resp, err := cmd.CombinedOutput()
req.NoError(err, string(resp))

var cluster *mongodbatlas.AdvancedCluster
var cluster *atlasv2.ClusterDescriptionV15
err = json.Unmarshal(resp, &cluster)
req.NoError(err)

Expand Down Expand Up @@ -95,12 +95,12 @@ func TestClustersM0Flags(t *testing.T) {
resp, err := cmd.CombinedOutput()
req.NoError(err, string(resp))

var cluster mongodbatlas.AdvancedCluster
var cluster atlasv2.ClusterDescriptionV15
err = json.Unmarshal(resp, &cluster)
req.NoError(err)

a := assert.New(t)
a.Equal(clusterName, cluster.Name)
a.Equal(clusterName, cluster.GetName())
})

t.Run("Delete", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/atlas/clusters_sharded_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package atlas_test
import (
"encoding/json"
"fmt"
atlasv2 "go.mongodb.org/atlas-sdk/admin"
"os"
"os/exec"
"testing"

"github.com/mongodb/mongodb-atlas-cli/test/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mongodb.org/atlas/mongodbatlas"
)

func TestShardedCluster(t *testing.T) {
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestShardedCluster(t *testing.T) {
resp, err := cmd.CombinedOutput()
req.NoError(err, string(resp))

var cluster mongodbatlas.AdvancedCluster
var cluster atlasv2.ClusterDescriptionV15
err = json.Unmarshal(resp, &cluster)
req.NoError(err)

Expand Down
Loading

0 comments on commit 0b0e1f8

Please sign in to comment.