Skip to content

Commit 9b01567

Browse files
committed
add int tests
1 parent 38dd975 commit 9b01567

File tree

5 files changed

+289
-0
lines changed

5 files changed

+289
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"eventTypeName": "NO_PRIMARY",
3+
"id": "6842e1a5d13438297a3fb730",
4+
"enabled": false,
5+
"notifications": [
6+
{
7+
"typeName": "GROUP",
8+
"intervalMin": 5,
9+
"delayMin": 0,
10+
"emailEnabled": true,
11+
"smsEnabled": true
12+
}
13+
]
14+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// Copyright 2024 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//go:build e2e || e2eSnap || (atlas && clusters && iss)
15+
16+
package clustersiss
17+
18+
import (
19+
"encoding/json"
20+
"fmt"
21+
"os"
22+
"os/exec"
23+
"testing"
24+
25+
"github.com/mongodb/mongodb-atlas-cli/atlascli/test/internal"
26+
"github.com/stretchr/testify/assert"
27+
"github.com/stretchr/testify/require"
28+
"go.mongodb.org/atlas-sdk/v20250312003/admin"
29+
)
30+
31+
const (
32+
clustersEntity = "clusters"
33+
diskSizeGB30 = "30"
34+
independentShardScalingFlag = "independentShardScaling"
35+
36+
// Cluster settings.
37+
e2eClusterProvider = "AWS"
38+
)
39+
40+
func TestIndependendShardScalingCluster(t *testing.T) {
41+
g := internal.NewAtlasE2ETestGenerator(t, internal.WithSnapshot())
42+
cliPath, err := internal.AtlasCLIBin()
43+
req := require.New(t)
44+
req.NoError(err)
45+
46+
issClusterName := g.Memory("issClusterName", internal.Must(internal.RandClusterName())).(string)
47+
48+
tier := internal.E2eTier()
49+
region, err := g.NewAvailableRegion(tier, e2eClusterProvider)
50+
req.NoError(err)
51+
52+
mdbVersion, err := internal.MongoDBMajorVersion()
53+
req.NoError(err)
54+
55+
g.Run("Create ISS cluster", func(t *testing.T) { //nolint:thelper // g.Run replaces t.Run
56+
cmd := exec.Command(cliPath,
57+
clustersEntity,
58+
"create",
59+
issClusterName,
60+
"--region", region,
61+
"--type=SHARDED",
62+
"--shards=2",
63+
"--members=3",
64+
"--tier", tier,
65+
"--provider", e2eClusterProvider,
66+
"--mdbVersion", mdbVersion,
67+
"--diskSizeGB", diskSizeGB30,
68+
"--autoScalingMode", independentShardScalingFlag,
69+
"--watch",
70+
"-o=json")
71+
72+
cmd.Env = os.Environ()
73+
resp, err := internal.RunAndGetStdOut(cmd)
74+
req.NoError(err, string(resp))
75+
76+
var cluster admin.ClusterDescription20240805
77+
req.NoError(json.Unmarshal(resp, &cluster))
78+
79+
internal.EnsureClusterLatest(t, &cluster, issClusterName, mdbVersion, 30, false)
80+
assert.Equal(t, 2, len(cluster.GetReplicationSpecs()))
81+
})
82+
83+
//TODO: Enable on CLOUDP-323577
84+
// g.Run("Get ISS cluster", func(t *testing.T) { //nolint:thelper // g.Run replaces t.Run
85+
// cmd := exec.Command(cliPath,
86+
// clustersEntity,
87+
// "get",
88+
// issClusterName,
89+
// "--autoScalingMode", independentShardScalingFlag,
90+
// "-o=json")
91+
92+
// cmd.Env = os.Environ()
93+
// resp, err := internal.RunAndGetStdOut(cmd)
94+
// req.NoError(err, string(resp))
95+
96+
// var cluster admin.ClusterDescription20240805
97+
// req.NoError(json.Unmarshal(resp, &cluster))
98+
99+
// internal.EnsureClusterLatest(t, &cluster, issClusterName, mdbVersion, 30, false)
100+
// assert.Equal(t, len(cluster.GetReplicationSpecs()), 2)
101+
// })
102+
103+
// g.Run("List ISS cluster", func(t *testing.T) { //nolint:thelper // g.Run replaces t.Run
104+
// cmd := exec.Command(cliPath,
105+
// clustersEntity,
106+
// "list",
107+
// "--autoScalingMode", independentShardScalingFlag,
108+
// "-o=json")
109+
// cmd.Env = os.Environ()
110+
// resp, err := internal.RunAndGetStdOut(cmd)
111+
// req.NoError(err, string(resp))
112+
113+
// var clusters admin.PaginatedClusterDescription20240805
114+
// req.NoError(json.Unmarshal(resp, &clusters))
115+
116+
// assert.Positive(t, clusters.GetTotalCount())
117+
// assert.NotEmpty(t, clusters.Results)
118+
// })
119+
120+
g.Run("Delete ISS cluster", func(t *testing.T) { //nolint:thelper // g.Run replaces t.Run
121+
cmd := exec.Command(cliPath,
122+
clustersEntity,
123+
"delete",
124+
issClusterName,
125+
"--force",
126+
"--watch")
127+
cmd.Env = os.Environ()
128+
resp, err := internal.RunAndGetStdOut(cmd)
129+
req.NoError(err, string(resp))
130+
131+
expected := fmt.Sprintf("Deleting cluster '%s'Cluster deleted\n", issClusterName)
132+
assert.Equal(t, expected, string(resp))
133+
})
134+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2024 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//go:build e2e || e2eSnap || (atlas && clusters && iss)
15+
16+
package clustersissfile
17+
18+
import (
19+
"encoding/json"
20+
"fmt"
21+
"os"
22+
"os/exec"
23+
"testing"
24+
25+
"github.com/mongodb/mongodb-atlas-cli/atlascli/test/internal"
26+
"github.com/stretchr/testify/assert"
27+
"github.com/stretchr/testify/require"
28+
"go.mongodb.org/atlas-sdk/v20250312003/admin"
29+
)
30+
31+
const (
32+
clustersEntity = "clusters"
33+
)
34+
35+
func TestISSClustersFile(t *testing.T) {
36+
g := internal.NewAtlasE2ETestGenerator(t, internal.WithSnapshot())
37+
cliPath, err := internal.AtlasCLIBin()
38+
req := require.New(t)
39+
req.NoError(err)
40+
41+
clusterIssFileName := g.Memory("clusterIssFileName", internal.Must(internal.RandClusterName())).(string)
42+
43+
g.Run("Create ISS Cluster via file", func(t *testing.T) { //nolint:thelper // g.Run replaces t.Run
44+
cmd := exec.Command(cliPath,
45+
clustersEntity,
46+
"create",
47+
clusterIssFileName,
48+
"--file", "testdata/create_iss_cluster_test.json",
49+
"-o=json")
50+
51+
cmd.Env = os.Environ()
52+
resp, err := internal.RunAndGetStdOut(cmd)
53+
req.NoError(err, string(resp))
54+
55+
var cluster admin.ClusterDescription20240805
56+
req.NoError(json.Unmarshal(resp, &cluster))
57+
internal.EnsureClusterLatest(t, &cluster, clusterIssFileName, "8.0", 30, false)
58+
})
59+
60+
g.Run("Delete Flex Cluster - created via file", func(t *testing.T) { //nolint:thelper // g.Run replaces t.Run
61+
cmd := exec.Command(
62+
cliPath,
63+
clustersEntity,
64+
"delete",
65+
clusterIssFileName,
66+
"--watch",
67+
"--force")
68+
69+
cmd.Env = os.Environ()
70+
resp, err := internal.RunAndGetStdOut(cmd)
71+
req.NoError(err, string(resp))
72+
73+
expected := fmt.Sprintf("Deleting cluster '%s'Cluster deleted\n", clusterIssFileName)
74+
assert.Equal(t, expected, string(resp))
75+
})
76+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"clusterType": "SHARDED",
3+
"name": "AsymmetricCluster",
4+
"mongoDBMajorVersion":"8.0",
5+
"backupEnabled":true,
6+
7+
"replicationSpecs": [
8+
{
9+
"regionConfigs": [
10+
{
11+
"electableSpecs": {
12+
"instanceSize": "M40",
13+
"nodeCount": 3,
14+
"backingProviderName": "AWS",
15+
"backingRegionName": "US_EAST_1",
16+
"diskSizeGB": 30
17+
},
18+
"priority": 7,
19+
"providerName": "AWS",
20+
"regionName": "EU_WEST_1"
21+
}
22+
],
23+
"zoneName": "Zone1"
24+
},
25+
{
26+
"regionConfigs": [
27+
{
28+
"electableSpecs": {
29+
"instanceSize": "M30",
30+
"nodeCount": 3,
31+
"backingProviderName": "AWS",
32+
"backingRegionName": "US_EAST_1",
33+
"diskSizeGB": 30
34+
},
35+
"priority": 7,
36+
"providerName": "AWS",
37+
"regionName": "EU_WEST_1"
38+
}
39+
],
40+
"zoneName": "Zone1"
41+
}
42+
],
43+
"tags": [
44+
{
45+
"key": "e2e_test",
46+
"value": "yes"
47+
}
48+
],
49+
"terminationProtectionEnabled": false
50+
}

test/internal/helper.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,21 @@ func EnsureCluster(t *testing.T, cluster *atlasClustersPinned.AdvancedClusterDes
977977
a.Equal(terminationProtection, cluster.GetTerminationProtectionEnabled())
978978
}
979979

980+
func EnsureClusterLatest(t *testing.T, cluster *atlasv2.ClusterDescription20240805, clusterName, version string, diskSizeGB float64, terminationProtection bool) {
981+
t.Helper()
982+
a := assert.New(t)
983+
a.Equal(clusterName, cluster.GetName())
984+
a.Equal(version, cluster.GetMongoDBMajorVersion())
985+
a.Equal(terminationProtection, cluster.GetTerminationProtectionEnabled())
986+
for _, repSpecs := range cluster.GetReplicationSpecs() {
987+
for _, config := range repSpecs.GetRegionConfigs() {
988+
electableSpecs := config.GetElectableSpecs()
989+
diskSize := electableSpecs.GetDiskSizeGB()
990+
a.InDelta(diskSizeGB, diskSize, 0.01) //nolint:mnd // ensure disk size is within 0.01 of expected value
991+
}
992+
}
993+
}
994+
980995
func EnsureFlexCluster(t *testing.T, cluster *atlasv2.FlexClusterDescription20241113, clusterName string, diskSizeGB float64, terminationProtection bool) {
981996
t.Helper()
982997
a := assert.New(t)

0 commit comments

Comments
 (0)