diff --git a/controllers/datadogagent_controller_v2_test.go b/controllers/datadogagent_controller_v2_test.go index c59ac956f..9e7007b2d 100644 --- a/controllers/datadogagent_controller_v2_test.go +++ b/controllers/datadogagent_controller_v2_test.go @@ -43,221 +43,81 @@ const ( // errors that crash containers and keep them in "CrashLoopBackOff" state. var _ = Describe("V2 Controller - DatadogAgent Deployment", func() { namespace := "default" - agent := v2alpha1.DatadogAgent{} - var name string - Context("with no features enabled", func() { - BeforeEach(func() { - name = "basic" - agent = testutils.NewDatadogAgentWithoutFeatures(namespace, name) - createAgent(&agent) - }) - - AfterEach(func() { - deleteAgent(&agent) - }) - - It("should deploy successfully", func() { - checkAgentDeployment(namespace, name) - }) - }) - - Context("with cluster checks enabled", func() { - BeforeEach(func() { - name = "with-cluster-checks" - agent = testutils.NewDatadogAgentWithClusterChecks(namespace, name) - createAgent(&agent) - }) - - AfterEach(func() { - deleteAgent(&agent) - }) - - It("should deploy successfully", func() { - checkAgentDeployment(namespace, name) - }) - }) - - Context("with CSPM enabled", func() { - BeforeEach(func() { - name = "with-cspm" - agent = testutils.NewDatadogAgentWithCSPM(namespace, name) - createAgent(&agent) - }) - - AfterEach(func() { - deleteAgent(&agent) - }) - - It("should deploy successfully", func() { - checkAgentDeployment(namespace, name) - }) - }) - - Context("with CWS enabled", func() { - BeforeEach(func() { - name = "with-cws" - agent = testutils.NewDatadogAgentWithCWS(namespace, name) - createAgent(&agent) - }) - - AfterEach(func() { - deleteAgent(&agent) - }) - - It("should deploy successfully", func() { - checkAgentDeployment(namespace, name) - }) - }) - - Context("with Dogstatsd enabled", func() { - BeforeEach(func() { - name = "with-dogstatsd" - agent = testutils.NewDatadogAgentWithDogstatsd(namespace, name) - createAgent(&agent) - }) - - AfterEach(func() { - deleteAgent(&agent) - }) - - It("should deploy successfully", func() { - checkAgentDeployment(namespace, name) - }) - }) - - Context("with event collection", func() { - BeforeEach(func() { - name = "with-event-collection" - agent = testutils.NewDatadogAgentWithEventCollection(namespace, name) - createAgent(&agent) - }) - - AfterEach(func() { - deleteAgent(&agent) - }) - - It("should deploy successfully", func() { - checkAgentDeployment(namespace, name) - }) - }) - - Context("with KSM core", func() { - BeforeEach(func() { - name = "with-ksm" - agent = testutils.NewDatadogAgentWithKSM(namespace, name) - createAgent(&agent) - }) - - AfterEach(func() { - deleteAgent(&agent) - }) - - It("should deploy successfully", func() { - checkAgentDeployment(namespace, name) - }) - }) - - Context("with log collection", func() { - BeforeEach(func() { - name = "with-log-collection" - agent = testutils.NewDatadogAgentWithLogCollection(namespace, name) - createAgent(&agent) - }) - - AfterEach(func() { - deleteAgent(&agent) - }) - - It("should deploy successfully", func() { - checkAgentDeployment(namespace, name) - }) - }) - - Context("with NPM", func() { - BeforeEach(func() { - name = "with-npm" - agent = testutils.NewDatadogAgentWithNPM(namespace, name) - createAgent(&agent) - }) - - AfterEach(func() { - deleteAgent(&agent) - }) - - It("should deploy successfully", func() { - checkAgentDeployment(namespace, name) - }) - }) - - Context("with OOM Kill", func() { - BeforeEach(func() { - name = "with-oom-kill" - agent = testutils.NewDatadogAgentWithOOMKill(namespace, name) - createAgent(&agent) - }) - - AfterEach(func() { - deleteAgent(&agent) - }) - - It("should deploy successfully", func() { - checkAgentDeployment(namespace, name) - }) - }) - - Context("with orchestrator explorer", func() { - BeforeEach(func() { - name = "with-orchestrator-explorer" - agent = testutils.NewDatadogAgentWithOrchestratorExplorer(namespace, name) - createAgent(&agent) - }) - - AfterEach(func() { - deleteAgent(&agent) - }) - - It("should deploy successfully", func() { - checkAgentDeployment(namespace, name) - }) - }) - - Context("with Prometheus scrape", func() { - BeforeEach(func() { - name = "with-prometheus-scrape" - agent = testutils.NewDatadogAgentWithPrometheusScrape(namespace, name) - createAgent(&agent) - }) - - AfterEach(func() { - deleteAgent(&agent) - }) - - It("should deploy successfully", func() { - checkAgentDeployment(namespace, name) - }) - }) - - Context("with TCP queue length", func() { - BeforeEach(func() { - name = "with-tcp-queue-length" - agent = testutils.NewDatadogAgentWithTCPQueueLength(namespace, name) - createAgent(&agent) - }) - - AfterEach(func() { - deleteAgent(&agent) - }) - - It("should deploy successfully", func() { - checkAgentDeployment(namespace, name) - }) - }) + Context( + "with no features enabled", + testFunction(testutils.NewDatadogAgentWithoutFeatures(namespace, "basic")), + ) + + Context( + "with cluster checks enabled", + testFunction(testutils.NewDatadogAgentWithClusterChecks(namespace, "with-cluster-checks")), + ) + + Context( + "with CSPM enabled", + testFunction(testutils.NewDatadogAgentWithCSPM(namespace, "with-cspm")), + ) + + Context( + "with CWS enabled", + testFunction(testutils.NewDatadogAgentWithCWS(namespace, "with-cws")), + ) + + Context( + "with Dogstatsd enabled", + testFunction(testutils.NewDatadogAgentWithDogstatsd(namespace, "with-dogstatsd")), + ) + + Context( + "with event collection", + testFunction(testutils.NewDatadogAgentWithEventCollection(namespace, "with-event-collection")), + ) + + Context( + "with KSM core", + testFunction(testutils.NewDatadogAgentWithKSM(namespace, "with-ksm")), + ) + + Context( + "with log collection", + testFunction(testutils.NewDatadogAgentWithLogCollection(namespace, "with-log-collection")), + ) + + Context( + "with NPM", + testFunction(testutils.NewDatadogAgentWithNPM(namespace, "with-npm")), + ) + + Context( + "with OOM Kill", + testFunction(testutils.NewDatadogAgentWithOOMKill(namespace, "with-oom-kill")), + ) + + Context( + "with orchestrator explorer", + testFunction(testutils.NewDatadogAgentWithOrchestratorExplorer(namespace, "with-orchestrator-explorer")), + ) + + Context( + "with Prometheus scrape", + testFunction(testutils.NewDatadogAgentWithPrometheusScrape(namespace, "with-prometheus-scrape")), + ) + + Context( + "with TCP queue length", + testFunction(testutils.NewDatadogAgentWithTCPQueueLength(namespace, "with-tcp-queue-length")), + ) + + Context( + "with USM", + testFunction(testutils.NewDatadogAgentWithUSM(namespace, "with-usm")), + ) +}) - Context("with USM", func() { +func testFunction(agent v2alpha1.DatadogAgent) func() { + return func() { BeforeEach(func() { - name = "with-usm" - agent = testutils.NewDatadogAgentWithUSM(namespace, name) createAgent(&agent) }) @@ -266,10 +126,10 @@ var _ = Describe("V2 Controller - DatadogAgent Deployment", func() { }) It("should deploy successfully", func() { - checkAgentDeployment(namespace, name) + checkAgentDeployment(agent.Namespace, agent.Name) }) - }) -}) + } +} func checkAgentDeployment(namespace string, name string) { checkAgentStatus(namespace, name)