From abc0cbeb299a776be00247cd7db111193c59845c Mon Sep 17 00:00:00 2001 From: Iurii Malchenko Date: Thu, 16 Nov 2023 01:08:10 +0100 Subject: [PATCH] simplify a bit --- .../kubernetes/client/TestPodSpec.scala | 7 ++++- .../kubernetes/client/api/JobsApiTest.scala | 4 +-- .../kubernetes/client/api/PodsApiTest.scala | 30 +++++-------------- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/kubernetes-client/test/src/com/goyeau/kubernetes/client/TestPodSpec.scala b/kubernetes-client/test/src/com/goyeau/kubernetes/client/TestPodSpec.scala index b7d79be..6b51e87 100644 --- a/kubernetes-client/test/src/com/goyeau/kubernetes/client/TestPodSpec.scala +++ b/kubernetes-client/test/src/com/goyeau/kubernetes/client/TestPodSpec.scala @@ -6,11 +6,16 @@ import io.k8s.apimachinery.pkg.api.resource.Quantity object TestPodSpec { - val alpine: PodSpec = PodSpec( + val alpine: PodSpec = alpine(None) + + def alpine(command: Seq[String]): PodSpec = alpine(command.some) + + private def alpine(command: Option[Seq[String]]): PodSpec = PodSpec( containers = Seq( Container( name = "test", image = "alpine".some, + command = command, imagePullPolicy = "IfNotPresent".some, resources = ResourceRequirements( requests = Map( diff --git a/kubernetes-client/test/src/com/goyeau/kubernetes/client/api/JobsApiTest.scala b/kubernetes-client/test/src/com/goyeau/kubernetes/client/api/JobsApiTest.scala index bda601d..fd7a441 100644 --- a/kubernetes-client/test/src/com/goyeau/kubernetes/client/api/JobsApiTest.scala +++ b/kubernetes-client/test/src/com/goyeau/kubernetes/client/api/JobsApiTest.scala @@ -38,9 +38,7 @@ class JobsApiTest template = PodTemplateSpec( metadata = Option(ObjectMeta(name = Option(resourceName))), spec = Option( - TestPodSpec.alpine.copy( - restartPolicy = "Never".some - ) + TestPodSpec.alpine.copy(restartPolicy = "Never".some) ) ) ) diff --git a/kubernetes-client/test/src/com/goyeau/kubernetes/client/api/PodsApiTest.scala b/kubernetes-client/test/src/com/goyeau/kubernetes/client/api/PodsApiTest.scala index d92f979..9df4cbc 100644 --- a/kubernetes-client/test/src/com/goyeau/kubernetes/client/api/PodsApiTest.scala +++ b/kubernetes-client/test/src/com/goyeau/kubernetes/client/api/PodsApiTest.scala @@ -63,32 +63,18 @@ class PodsApiTest def testPod(podName: String, labels: Map[String, String] = Map.empty): Pod = Pod( metadata = Option(ObjectMeta(name = Option(podName), labels = Option(labels))), - spec = TestPodSpec.alpine - .copy( - containers = TestPodSpec.alpine.containers.map { container => - container.copy( - command = Option(Seq("sh", "-c", "sleep 120")) - ) - } - ) - .some + spec = TestPodSpec.alpine(command = Seq("sh", "-c", "sleep 120")).some ) def testPodWithLogs(podName: String, labels: Map[String, String] = Map.empty): Pod = Pod( metadata = Option(ObjectMeta(name = Option(podName), labels = Option(labels))), - spec = TestPodSpec.alpine - .copy( - containers = TestPodSpec.alpine.containers.map { container => - container.copy( - command = Option( - Seq( - "sh", - "-c", - "echo line 1; sleep 1; echo line 2; sleep 2; echo line 3; echo line 4; echo line 5; echo line 6" - ) - ) - ) - } + spec = TestPodSpec + .alpine(command = + Seq( + "sh", + "-c", + "echo line 1; sleep 1; echo line 2; sleep 2; echo line 3; echo line 4; echo line 5; echo line 6" + ) ) .some )