Skip to content

Commit 7571523

Browse files
authored
Cover new DATADOG supported regions and add PagerDuty test (#1257)
1 parent 50d9c38 commit 7571523

File tree

1 file changed

+105
-64
lines changed

1 file changed

+105
-64
lines changed

test/e2e/integration_test.go

Lines changed: 105 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,23 @@ import (
1212
"github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/project"
1313
"github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/status"
1414
"github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/actions"
15-
"github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/api/atlas"
1615
"github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/data"
1716
"github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/k8s"
1817
"github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/model"
1918
)
2019

21-
var _ = Describe("Configuration namespaced. Deploy deployment", Label("integration-ns"), func() {
20+
const (
21+
datadogEnvKey = "DATADOG_KEY"
22+
pagerDutyEnvKey = "PAGER_DUTY_SERVICE_KEY"
23+
integrationSecretName = "integration-secret"
24+
)
25+
26+
var _ = Describe("Project Third-Party Integration", Label("integration-ns"), func() {
2227
var testData *model.TestDataProvider
23-
var key string
2428

2529
BeforeEach(func() {
26-
key = os.Getenv("DATADOG_KEY")
27-
Expect(key).ShouldNot(BeEmpty())
30+
Expect(os.Getenv(datadogEnvKey)).ShouldNot(BeEmpty())
31+
Expect(os.Getenv(pagerDutyEnvKey)).ShouldNot(BeEmpty())
2832
})
2933

3034
AfterEach(func() {
@@ -39,95 +43,132 @@ var _ = Describe("Configuration namespaced. Deploy deployment", Label("integrati
3943
actions.AfterEachFinalCleanup([]model.TestDataProvider{*testData})
4044
})
4145

42-
DescribeTable("Namespaced operators working only with its own namespace with different configuration",
43-
func(test *model.TestDataProvider) {
46+
DescribeTable("Integration can be configured in a project",
47+
func(test *model.TestDataProvider, integration project.Integration, envKeyName string, setSecret configSecret) {
4448
testData = test
4549
actions.ProjectCreationFlow(test)
46-
integrationCycle(test, key)
50+
integrationTest(test, integration, os.Getenv(envKeyName), setSecret)
4751
},
48-
Entry("Users can use integration section", Label("project-integration"),
52+
53+
Entry("Users can integrate DATADOG on region US1", Label("project-integration"),
54+
model.DataProvider(
55+
"datatog-us1",
56+
model.NewEmptyAtlasKeyType().UseDefaultFullAccess(),
57+
30018,
58+
[]func(*model.TestDataProvider){},
59+
).WithProject(data.DefaultProject()),
60+
project.Integration{
61+
Type: "DATADOG",
62+
Region: "US",
63+
},
64+
datadogEnvKey,
65+
func(integration *project.Integration, ref common.ResourceRefNamespaced) {
66+
integration.APIKeyRef = ref
67+
},
68+
),
69+
Entry("Users can integrate DATADOG on region US3", Label("project-integration"),
70+
model.DataProvider(
71+
"datatog-us3",
72+
model.NewEmptyAtlasKeyType().UseDefaultFullAccess(),
73+
30018,
74+
[]func(*model.TestDataProvider){},
75+
).WithProject(data.DefaultProject()),
76+
project.Integration{
77+
Type: "DATADOG",
78+
Region: "US3",
79+
},
80+
datadogEnvKey,
81+
func(integration *project.Integration, ref common.ResourceRefNamespaced) {
82+
integration.APIKeyRef = ref
83+
},
84+
),
85+
Entry("Users can integrate DATADOG on region US5", Label("project-integration"),
86+
model.DataProvider(
87+
"datatog-us5",
88+
model.NewEmptyAtlasKeyType().UseDefaultFullAccess(),
89+
30018,
90+
[]func(*model.TestDataProvider){},
91+
).WithProject(data.DefaultProject()),
92+
project.Integration{
93+
Type: "DATADOG",
94+
Region: "US5",
95+
},
96+
datadogEnvKey,
97+
func(integration *project.Integration, ref common.ResourceRefNamespaced) {
98+
integration.APIKeyRef = ref
99+
},
100+
),
101+
Entry("Users can integrate DATADOG on region EU1", Label("project-integration"),
49102
model.DataProvider(
50-
"operator-integration-cr",
103+
"datatog-eu1",
51104
model.NewEmptyAtlasKeyType().UseDefaultFullAccess(),
52105
30018,
53106
[]func(*model.TestDataProvider){},
54107
).WithProject(data.DefaultProject()),
108+
project.Integration{
109+
Type: "DATADOG",
110+
Region: "EU",
111+
},
112+
datadogEnvKey,
113+
func(integration *project.Integration, ref common.ResourceRefNamespaced) {
114+
integration.APIKeyRef = ref
115+
},
116+
),
117+
Entry("Users can integrate PagerDuty on region US", Label("project-integration"),
118+
model.DataProvider(
119+
"pager-duty-us",
120+
model.NewEmptyAtlasKeyType().UseDefaultFullAccess(),
121+
30018,
122+
[]func(*model.TestDataProvider){},
123+
).WithProject(data.DefaultProject()),
124+
project.Integration{
125+
Type: "PAGER_DUTY",
126+
Region: "US",
127+
},
128+
pagerDutyEnvKey,
129+
func(integration *project.Integration, ref common.ResourceRefNamespaced) {
130+
integration.ServiceKeyRef = ref
131+
},
55132
),
56133
)
57134
})
58135

59-
func integrationCycle(data *model.TestDataProvider, key string) {
60-
integrationType := "DATADOG"
136+
func integrationTest(data *model.TestDataProvider, integration project.Integration, key string, setSecret configSecret) {
137+
By("Create Secret for integration", func() {
138+
Expect(k8s.CreateUserSecret(data.Context, data.K8SClient, key, integrationSecretName, data.Resources.Namespace)).Should(Succeed())
61139

62-
By("Deploy User Resources", func() {
63-
projectStatus := GetProjectIntegrationStatus(data)
64-
Expect(projectStatus).Should(BeEmpty())
140+
setSecret(&integration, common.ResourceRefNamespaced{Name: integrationSecretName, Namespace: data.Resources.Namespace})
65141
})
66142

67143
By("Add integration", func() {
68-
Expect(data.K8SClient.Get(data.Context, types.NamespacedName{Name: data.Project.Name,
69-
Namespace: data.Resources.Namespace}, data.Project)).Should(Succeed())
70-
newIntegration := project.Integration{
71-
Type: integrationType,
72-
APIKeyRef: common.ResourceRefNamespaced{
73-
Name: "datadog-secret",
74-
Namespace: data.Resources.Namespace,
75-
},
76-
Region: "EU",
77-
}
78-
data.Project.Spec.Integrations = append(data.Project.Spec.Integrations, newIntegration)
79-
By("Create Secret for integration", func() {
80-
for _, i := range data.Project.Spec.Integrations {
81-
Expect(k8s.CreateUserSecret(data.Context, data.K8SClient, key, i.APIKeyRef.Name, i.APIKeyRef.Namespace)).Should(Succeed())
82-
}
83-
})
144+
Expect(data.K8SClient.Get(data.Context, types.NamespacedName{Name: data.Project.Name, Namespace: data.Resources.Namespace}, data.Project)).Should(Succeed())
145+
data.Project.Spec.Integrations = append(data.Project.Spec.Integrations, integration)
146+
84147
Expect(data.K8SClient.Update(data.Context, data.Project)).Should(Succeed())
85-
actions.WaitForConditionsToBecomeTrue(data, status.IntegrationReadyType, status.ReadyType)
86148
})
87149

88-
atlasClient := atlas.GetClientOrFail()
89-
By("Check statuses", func() {
90-
var projectStatus string
91-
projectStatus, err := k8s.GetProjectStatusCondition(data.Context, data.K8SClient, status.IntegrationReadyType, data.Resources.Namespace, data.Project.GetName())
92-
Expect(err).ShouldNot(HaveOccurred())
93-
Expect(projectStatus).Should(Equal("True"))
94-
95-
Expect(err).ShouldNot(HaveOccurred())
150+
By("Integration is ready", func() {
151+
actions.WaitForConditionsToBecomeTrue(data, status.IntegrationReadyType, status.ReadyType)
96152

97-
dog, err := atlasClient.GetIntegrationByType(data.Project.ID(), integrationType)
153+
atlasIntegration, err := atlasClient.GetIntegrationByType(data.Project.ID(), integration.Type)
98154
Expect(err).ShouldNot(HaveOccurred())
99-
Expect(strings.HasSuffix(key, removeStarsFromString(dog.APIKey))).Should(BeTrue())
155+
Expect(strings.HasSuffix(key, strings.TrimLeft(atlasIntegration.APIKey, "*"))).Should(BeTrue())
100156
})
101157

102158
By("Delete integration", func() {
103-
Expect(data.K8SClient.Get(data.Context, types.NamespacedName{Name: data.Project.Name,
104-
Namespace: data.Resources.Namespace}, data.Project)).Should(Succeed())
159+
Expect(data.K8SClient.Get(data.Context, types.NamespacedName{Name: data.Project.Name, Namespace: data.Resources.Namespace}, data.Project)).Should(Succeed())
105160
data.Project.Spec.Integrations = []project.Integration{}
161+
106162
Expect(data.K8SClient.Update(data.Context, data.Project)).Should(Succeed())
107-
actions.CheckProjectConditionsNotSet(data, status.IntegrationReadyType)
108163
})
109164

110165
By("Delete integration check", func() {
111-
integration, err := atlasClient.GetIntegrationByType(data.Project.ID(), integrationType)
112-
Expect(err).Should(HaveOccurred())
113-
Expect(integration).To(BeNil())
166+
actions.CheckProjectConditionsNotSet(data, status.IntegrationReadyType)
114167

115-
// TODO uncomment with
116-
// status := kubecli.GetStatusCondition(string(status.IntegrationReadyType), data.Resources.Namespace, data.Resources.GetAtlasProjectFullKubeName())
117-
// Expect(status).Should(BeEmpty())
168+
atlasIntegration, err := atlasClient.GetIntegrationByType(data.Project.ID(), integration.Type)
169+
Expect(err).Should(HaveOccurred())
170+
Expect(atlasIntegration).To(BeNil())
118171
})
119172
}
120173

121-
func GetProjectIntegrationStatus(testData *model.TestDataProvider) string {
122-
Expect(testData.K8SClient.Get(testData.Context, types.NamespacedName{Name: testData.Project.Name, Namespace: testData.Project.Namespace}, testData.Project)).Should(Succeed())
123-
for _, condition := range testData.Project.Status.Conditions {
124-
if condition.Type == status.IntegrationReadyType {
125-
return string(condition.Status)
126-
}
127-
}
128-
return ""
129-
}
130-
131-
func removeStarsFromString(str string) string {
132-
return strings.ReplaceAll(str, "*", "")
133-
}
174+
type configSecret func(integration *project.Integration, ref common.ResourceRefNamespaced)

0 commit comments

Comments
 (0)