From b45315a1ba43b4ff7bc3525c604358401a750a97 Mon Sep 17 00:00:00 2001
From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de>
Date: Mon, 12 Jul 2021 14:14:51 +0200
Subject: [PATCH] add patcher test

---
 .../KubernetesBenchmarkDeployment.kt          |  9 ++-
 .../patcher/ConfigOverrideModifierTest.kt     | 57 +++++++++++++++++++
 2 files changed, 64 insertions(+), 2 deletions(-)
 create mode 100644 theodolite-quarkus/src/test/kotlin/theodolite/patcher/ConfigOverrideModifierTest.kt

diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt
index d5a4df074..e086f7f88 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt
@@ -6,6 +6,7 @@ import io.quarkus.runtime.annotations.RegisterForReflection
 import mu.KotlinLogging
 import org.apache.kafka.clients.admin.NewTopic
 import theodolite.k8s.K8sManager
+import theodolite.k8s.ResourceByLabelHandler
 import theodolite.k8s.TopicManager
 import theodolite.util.KafkaConfig
 import java.time.Duration
@@ -32,7 +33,8 @@ class KubernetesBenchmarkDeployment(
 ) : BenchmarkDeployment {
     private val kafkaController = TopicManager(this.kafkaConfig)
     private val kubernetesManager = K8sManager(client)
-    private val LAG_EXPORTER_POD_LABEL = "app.kubernetes.io/name=kafka-lag-exporter"
+    private val LAG_EXPORTER_POD_LABEL_NAME= "app.kubernetes.io/name"
+    private val LAG_EXPORTER_POD_LABEL_VALUE= "kafka-lag-exporter"
 
     /**
      * Setup a [KubernetesBenchmark] using the [TopicManager] and the [K8sManager]:
@@ -59,7 +61,10 @@ class KubernetesBenchmarkDeployment(
         loadGenResources.forEach { kubernetesManager.remove(it) }
         appResources.forEach { kubernetesManager.remove(it) }
         kafkaController.removeTopics(this.topics.map { topic -> topic.name })
-        ResourceByLabelRemover(client).removePod(LAG_EXPORTER_POD_LABEL)
+        ResourceByLabelHandler(client).removePods(
+            labelName =  LAG_EXPORTER_POD_LABEL_NAME,
+            labelValue = LAG_EXPORTER_POD_LABEL_VALUE
+        )
         logger.info { "Teardown complete. Wait $afterTeardownDelay ms to let everything come down." }
         Thread.sleep(Duration.ofSeconds(afterTeardownDelay).toMillis())
     }
diff --git a/theodolite-quarkus/src/test/kotlin/theodolite/patcher/ConfigOverrideModifierTest.kt b/theodolite-quarkus/src/test/kotlin/theodolite/patcher/ConfigOverrideModifierTest.kt
new file mode 100644
index 000000000..9df095fb6
--- /dev/null
+++ b/theodolite-quarkus/src/test/kotlin/theodolite/patcher/ConfigOverrideModifierTest.kt
@@ -0,0 +1,57 @@
+package theodolite.patcher
+
+import io.quarkus.test.junit.QuarkusTest
+import org.junit.jupiter.api.Assertions
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.Test
+import theodolite.benchmark.BenchmarkExecution
+import theodolite.benchmark.KubernetesBenchmark
+import theodolite.execution.operator.BenchmarkCRDummy
+import theodolite.execution.operator.ExecutionCRDummy
+
+@QuarkusTest
+class ConfigOverrideModifierTest {
+    private var execution = BenchmarkExecution()
+    private var benchmark = KubernetesBenchmark()
+
+
+
+    @BeforeEach
+    fun setup() {
+        val execution1 = ExecutionCRDummy(name = "matching-execution", benchmark = "Test-Benchmark")
+        val benchmark1 = BenchmarkCRDummy(name = "Test-Benchmark")
+
+        this.execution = execution1.getCR().spec
+        this.benchmark = benchmark1.getCR().spec
+    }
+
+
+
+    @Test
+    fun setAdditionalLabelsTest() {
+        this.benchmark.appResource = listOf("test-resource.yaml")
+
+        val modifier = ConfigOverrideModifier(
+            execution = this.execution,
+            resources = this.benchmark.appResource )
+
+        modifier.setAdditionalLabels(
+            labelName = "test-name",
+            labelValue = "test-value")
+
+        Assertions.assertEquals(
+            "test-name",
+            this.execution
+                .configOverrides.firstOrNull()
+                ?.patcher
+                ?.properties
+                ?.get("variableName")
+        )
+        Assertions.assertEquals(
+            "test-value",
+            this.execution
+                .configOverrides.firstOrNull()
+                ?.value
+        )
+    }
+}
\ No newline at end of file
-- 
GitLab