Skip to content

Commit

Permalink
Provide more context when filesystem dates are out of bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
squarejesse committed Dec 22, 2020
1 parent a176e8d commit 009b447
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions okio/src/commonTest/kotlin/okio/AbstractFilesystemTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ abstract class AbstractFilesystemTest(
assertTrue(metadata.isRegularFile)
assertFalse(metadata.isDirectory)
assertEquals(13, metadata.size)
assertTrue { (metadata.createdAt ?: minTime) in minTime..maxTime }
assertTrue { (metadata.lastModifiedAt ?: minTime) in minTime..maxTime }
assertTrue { (metadata.lastAccessedAt ?: minTime) in minTime..maxTime }
assertInRange(metadata.createdAt, minTime, maxTime)
assertInRange(metadata.lastModifiedAt, minTime, maxTime)
assertInRange(metadata.lastAccessedAt, minTime, maxTime)
}

@Test
Expand All @@ -346,9 +346,9 @@ abstract class AbstractFilesystemTest(
assertFalse(metadata.isRegularFile)
assertTrue(metadata.isDirectory)
// Note that the size check is omitted; we'd expect null but the JVM returns values like 64.
assertTrue { (metadata.createdAt ?: minTime) in minTime..maxTime }
assertTrue { (metadata.lastModifiedAt ?: minTime) in minTime..maxTime }
assertTrue { (metadata.lastAccessedAt ?: minTime) in minTime..maxTime }
assertInRange(metadata.createdAt, minTime, maxTime)
assertInRange(metadata.lastModifiedAt, minTime, maxTime)
assertInRange(metadata.lastAccessedAt, minTime, maxTime)
}

@Test
Expand Down Expand Up @@ -478,4 +478,9 @@ abstract class AbstractFilesystemTest(
private fun Instant.maxFileSystemTime(): Instant {
return Instant.fromEpochSeconds(plus(2.seconds).epochSeconds)
}

private fun assertInRange(sampled: Instant?, minTime: Instant, maxTime: Instant) {
if (sampled == null) return
assertTrue("expected $sampled in $minTime..$maxTime") { sampled in minTime..maxTime }
}
}

0 comments on commit 009b447

Please sign in to comment.