Skip to content

Commit

Permalink
fix: A test that passed locally but not on git workflow
Browse files Browse the repository at this point in the history
Related to issue #6.
  • Loading branch information
hirak99 committed Jan 10, 2025
1 parent 9fd3932 commit 287a6c0
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/code/snap_holder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
# For testing, we can access private methods.
# pyright: reportPrivateUsage=false

NOW = datetime.datetime.strptime("20250130", r"%Y%m%d")
# UTC time.
_NOW = datetime.datetime(2025, 1, 30, hour=12, minute=0, second=0)


class SnapHolderTest(unittest.TestCase):
Expand Down Expand Up @@ -78,31 +79,31 @@ def test_filecontent(self):
snap = snap_holder.Snapshot(snap_destination)
self.assertEqual(snap.metadata._to_file_content(), {"snap_type": "UNKNOWN"})

snap.set_ttl("1 hour", now=NOW)
snap.set_ttl("1 hour", now=_NOW)
self.assertEqual(
snap.metadata._to_file_content(),
{"snap_type": "UNKNOWN", "expiry": 1738179000.0},
{"snap_type": "UNKNOWN", "expiry": 1738222200.0},
)

# Setting to empty string erases ttl.
snap.set_ttl("", now=NOW)
snap.set_ttl("", now=_NOW)
self.assertEqual(snap.metadata._to_file_content(), {"snap_type": "UNKNOWN"})

def test_expired(self):
with tempfile.TemporaryDirectory() as dir:
snap_destination = os.path.join(dir, "root-20231122193630")
snap = snap_holder.Snapshot(snap_destination)

self.assertFalse(snap.metadata.is_expired(NOW))
self.assertFalse(snap.metadata.is_expired(_NOW))

snap.set_ttl("1 h", now=NOW)
self.assertFalse(snap.metadata.is_expired(NOW))
snap.set_ttl("1 h", now=_NOW)
self.assertFalse(snap.metadata.is_expired(_NOW))

snap.metadata.expiry = NOW.timestamp() - 100
self.assertTrue(snap.metadata.is_expired(NOW))
snap.metadata.expiry = _NOW.timestamp() - 100
self.assertTrue(snap.metadata.is_expired(_NOW))

snap.metadata.expiry = NOW.timestamp() + 100
self.assertFalse(snap.metadata.is_expired(NOW))
snap.metadata.expiry = _NOW.timestamp() + 100
self.assertFalse(snap.metadata.is_expired(_NOW))


if __name__ == "__main__":
Expand Down

0 comments on commit 287a6c0

Please sign in to comment.