Skip to content

Commit af3bb79

Browse files
CLOUDP-73546: Add e2e test for atlas customDns (#456)
1 parent d36dd31 commit af3bb79

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

e2e/atlas/custom_dns_test.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Copyright 2020 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+
// +build e2e atlas,generic
15+
16+
package atlas_test
17+
18+
import (
19+
"encoding/json"
20+
"fmt"
21+
"os"
22+
"os/exec"
23+
"testing"
24+
25+
"github.com/mongodb/mongocli/e2e"
26+
"github.com/stretchr/testify/assert"
27+
"go.mongodb.org/atlas/mongodbatlas"
28+
)
29+
30+
func TestCustomDNS(t *testing.T) {
31+
n, err := e2e.RandInt(255)
32+
if err != nil {
33+
t.Fatalf("unexpected error: %v", err)
34+
}
35+
36+
cliPath, err := e2e.Bin()
37+
if err != nil {
38+
t.Fatalf("unexpected error: %v", err)
39+
}
40+
41+
projectName := fmt.Sprintf("e2e-integration-custom-dns-%v", n)
42+
projectID, err := createProject(projectName)
43+
if err != nil {
44+
t.Fatalf("unexpected error: %v", err)
45+
}
46+
47+
defer func() {
48+
if e := deleteProject(projectID); e != nil {
49+
t.Errorf("error deleting project: %v", e)
50+
}
51+
}()
52+
53+
t.Run("Enable", func(t *testing.T) {
54+
cmd := exec.Command(cliPath,
55+
atlasEntity,
56+
customDNSEntity,
57+
awsEntity,
58+
"enable",
59+
"--projectId",
60+
projectID,
61+
"-o=json")
62+
cmd.Env = os.Environ()
63+
resp, err := cmd.CombinedOutput()
64+
65+
a := assert.New(t)
66+
a.NoError(err, string(resp))
67+
68+
var dns mongodbatlas.AWSCustomDNSSetting
69+
if err := json.Unmarshal(resp, &dns); a.NoError(err) {
70+
a.True(dns.Enabled)
71+
}
72+
})
73+
74+
t.Run("Describe", func(t *testing.T) {
75+
cmd := exec.Command(cliPath,
76+
atlasEntity,
77+
customDNSEntity,
78+
awsEntity,
79+
"describe",
80+
"--projectId",
81+
projectID,
82+
"-o=json")
83+
cmd.Env = os.Environ()
84+
resp, err := cmd.CombinedOutput()
85+
86+
a := assert.New(t)
87+
a.NoError(err, string(resp))
88+
89+
var dns mongodbatlas.AWSCustomDNSSetting
90+
if err := json.Unmarshal(resp, &dns); a.NoError(err) {
91+
a.True(dns.Enabled)
92+
}
93+
})
94+
95+
t.Run("Disable", func(t *testing.T) {
96+
cmd := exec.Command(cliPath,
97+
atlasEntity,
98+
customDNSEntity,
99+
awsEntity,
100+
"disable",
101+
"--projectId",
102+
projectID,
103+
"-o=json")
104+
cmd.Env = os.Environ()
105+
resp, err := cmd.CombinedOutput()
106+
107+
a := assert.New(t)
108+
a.NoError(err, string(resp))
109+
110+
var dns mongodbatlas.AWSCustomDNSSetting
111+
if err := json.Unmarshal(resp, &dns); a.NoError(err) {
112+
a.False(dns.Enabled)
113+
}
114+
})
115+
}

e2e/atlas/helper_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const (
4747
integrationsEntity = "integrations"
4848
securityEntity = "security"
4949
ldapEntity = "ldap"
50+
awsEntity = "aws"
51+
customDNSEntity = "customDns"
5052
)
5153

5254
func getHostnameAndPort() (string, error) {

0 commit comments

Comments
 (0)