-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sql): Add test verifying precision and adjust precision to 6 to m…
…atch mysql
- Loading branch information
1 parent
4a823d5
commit dbe8e0b
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...rc/test/kotlin/com/netflix/spinnaker/keel/serialization/ObjectMapperSerializationTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.netflix.spinnaker.keel.serialization | ||
|
||
import dev.minutest.junit.JUnit5Minutests | ||
import dev.minutest.rootContext | ||
import org.assertj.core.api.Assertions.assertThat | ||
import java.time.Instant | ||
import java.time.LocalDateTime | ||
import java.time.OffsetDateTime | ||
import java.time.ZoneOffset | ||
import java.time.format.DateTimeFormatter | ||
import java.time.format.DateTimeFormatterBuilder | ||
|
||
class ObjectMapperSerializationTests : JUnit5Minutests { | ||
|
||
class ObjectMapperSerializationTestsObject { | ||
var date = Instant.from(DateTimeFormatter.ISO_INSTANT.parse("2024-03-10T12:28:19.228816801Z")) | ||
} | ||
|
||
fun tests() = rootContext { | ||
test("Verify instant precision is no more than 6 characters") { | ||
val mapper = configuredObjectMapper() | ||
val sampleObject = ObjectMapperSerializationTestsObject() | ||
val readBack = mapper.readValue( | ||
mapper.writeValueAsString(sampleObject), | ||
ObjectMapperSerializationTestsObject::class.java | ||
) | ||
// 6 precision is the max allowed via str_to_date in SQL. See | ||
// https://dev.mysql.com/doc/refman/8.4/en/date-and-time-type-syntax.html#:~:text=MySQL%20permits%20fractional%20seconds%20for,microseconds%20(6%20digits)%20precision. | ||
// SO we want to make sure waht we store matches this | ||
val foramt = DateTimeFormatterBuilder().parseCaseInsensitive().appendInstant(6).parseStrict().toFormatter() | ||
assertThat(readBack.date).isEqualTo(foramt.format(sampleObject.date)) | ||
} | ||
} | ||
} |