import unittest from rollback import image_restore_plan class RollbackPlanTests(unittest.TestCase): def setUp(self): self.manifest = { "images": { "backend": {"configured": "akyldash/backend:local", "image_id": "sha256:" + "a" * 64}, "opensearch": {"configured": "akyldash/opensearch:local", "image_id": "sha256:" + "b" * 64}, } } self.configured = { "backend": "akyldash/backend:local", "opensearch": "akyldash/opensearch:local", } def test_plans_only_recorded_local_images(self): plan = image_restore_plan(self.manifest, self.configured) self.assertEqual(plan["backend"][1], "akyldash/backend:local") self.assertEqual(plan["opensearch"][1], "akyldash/opensearch:local") def test_refuses_changed_compose_image_reference(self): with self.assertRaisesRegex(ValueError, "reference changed"): image_restore_plan(self.manifest, {**self.configured, "backend": "other/backend:tag"}) def test_refuses_digest_reference_that_cannot_be_retagged(self): self.manifest["images"]["backend"]["configured"] = "registry/backend@sha256:" + "c" * 64 self.configured["backend"] = self.manifest["images"]["backend"]["configured"] with self.assertRaisesRegex(ValueError, "local tag"): image_restore_plan(self.manifest, self.configured) if __name__ == "__main__": unittest.main()