diff --git a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/model/crd/ExecutionStatus.kt b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/model/crd/ExecutionStatus.kt index 6bec7197ddde61185ca37b3e0e96f471a910a0aa..d994da2c0da51580e8d5460f5df423782988d04a 100644 --- a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/model/crd/ExecutionStatus.kt +++ b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/model/crd/ExecutionStatus.kt @@ -47,7 +47,7 @@ class ExecutionStatus( private fun JavaDuration.toK8sString(): String { return when { - this <= JavaDuration.ofSeconds(2) -> "${this.toSeconds()}s" + this <= JavaDuration.ofMinutes(2) -> "${this.toSeconds()}s" this < JavaDuration.ofMinutes(99) -> "${this.toMinutes()}m" this < JavaDuration.ofHours(99) -> "${this.toHours()}h" else -> "${this.toDays()}d + ${this.minusDays(this.toDays()).toHours()}h" diff --git a/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/model/crd/ExecutionStatusTest.kt b/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/model/crd/ExecutionStatusTest.kt index 4c9326ac2e99dd7dd9707d4db25cb2e9e360ddf9..69750a2341cbf2590546ad99cd85d660e797f209 100644 --- a/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/model/crd/ExecutionStatusTest.kt +++ b/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/model/crd/ExecutionStatusTest.kt @@ -101,7 +101,7 @@ internal class ExecutionStatusTest { } @Test - fun testDurationSerialization() { + fun testMinutesDurationSerialization() { val objectMapper = ObjectMapper() val executionStatus = ExecutionStatus() val startInstant = Instant.parse("2022-01-02T18:59:20.492103Z") @@ -114,6 +114,20 @@ internal class ExecutionStatusTest { assertEquals("15m", jsonField.asText()) } + @Test + fun testSecondsDurationSerialization() { + val objectMapper = ObjectMapper() + val executionStatus = ExecutionStatus() + val startInstant = Instant.parse("2022-01-02T18:59:20.492103Z") + executionStatus.startTime = MicroTime(startInstant.toString()) + executionStatus.completionTime = MicroTime(startInstant.plus(Duration.ofSeconds(45)).toString()) + val jsonString = objectMapper.writeValueAsString(executionStatus) + val json = objectMapper.readTree(jsonString) + val jsonField = json.get("executionDuration") + assertTrue(jsonField.isTextual) + assertEquals("45s", jsonField.asText()) + } + @Test fun testNotStartedDurationSerialization() { val objectMapper = ObjectMapper()