feat: coordinate static site deployments through Gandalf
All checks were successful
Test / test (push) Successful in 8s
All checks were successful
Test / test (push) Successful in 8s
This commit is contained in:
parent
d3a6b4bb0a
commit
411010ef5a
4 changed files with 257 additions and 17 deletions
|
|
@ -203,10 +203,14 @@ class StaticSiteTests(unittest.TestCase):
|
|||
request.get_header("Authorization"), "Bearer storage-password"
|
||||
)
|
||||
|
||||
@mock.patch.object(static_site, "purge_bunny_gateway")
|
||||
@mock.patch.object(static_site, "finalize_bunny_deployment")
|
||||
@mock.patch.object(static_site, "start_bunny_deployment")
|
||||
@mock.patch.object(static_site, "BunnyStorage")
|
||||
def test_unchanged_deployment_retries_gateway_purge(
|
||||
self, storage_class: mock.Mock, purge_gateway: mock.Mock
|
||||
def test_unchanged_deployment_is_finalized_without_forcing_a_purge(
|
||||
self,
|
||||
storage_class: mock.Mock,
|
||||
start_deployment: mock.Mock,
|
||||
finalize_deployment: mock.Mock,
|
||||
) -> None:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
|
|
@ -215,6 +219,12 @@ class StaticSiteTests(unittest.TestCase):
|
|||
storage_class.return_value.get_manifest.return_value = json.dumps(
|
||||
manifest_for(files)
|
||||
).encode()
|
||||
start_deployment.return_value = {"deployment_id": "deployment-id"}
|
||||
finalize_deployment.return_value = {
|
||||
"deployment_id": "deployment-id",
|
||||
"status": "unchanged",
|
||||
"purged": False,
|
||||
}
|
||||
args = static_site.argparse.Namespace(
|
||||
directory=root,
|
||||
zone="example-org",
|
||||
|
|
@ -224,13 +234,61 @@ class StaticSiteTests(unittest.TestCase):
|
|||
pull_zone_id="",
|
||||
api_key="",
|
||||
dry_run=False,
|
||||
workers=4,
|
||||
revision="abc1234",
|
||||
idempotency_key="test-run-123",
|
||||
)
|
||||
result = static_site.deploy_bunny(args)
|
||||
|
||||
self.assertFalse(result["changed"])
|
||||
self.assertTrue(result["purged"])
|
||||
purge_gateway.assert_called_once_with(
|
||||
"https://purge.example", "example-org", "storage-password"
|
||||
self.assertFalse(result["purged"])
|
||||
start_deployment.assert_called_once()
|
||||
finalize_deployment.assert_called_once()
|
||||
storage_class.return_value.upload_manifest.assert_not_called()
|
||||
|
||||
@mock.patch.object(static_site, "abort_bunny_deployment")
|
||||
@mock.patch.object(static_site, "finalize_bunny_deployment")
|
||||
@mock.patch.object(static_site, "start_bunny_deployment")
|
||||
@mock.patch.object(static_site, "apply_bunny_plan")
|
||||
@mock.patch.object(static_site, "BunnyStorage")
|
||||
def test_failed_upload_releases_the_deployment_lease(
|
||||
self,
|
||||
storage_class: mock.Mock,
|
||||
apply_plan: mock.Mock,
|
||||
start_deployment: mock.Mock,
|
||||
finalize_deployment: mock.Mock,
|
||||
abort_deployment: mock.Mock,
|
||||
) -> None:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
write_site(root)
|
||||
storage_class.return_value.get_manifest.return_value = None
|
||||
start_deployment.return_value = {"deployment_id": "deployment-id"}
|
||||
apply_plan.side_effect = static_site.DeployError("upload failed")
|
||||
args = static_site.argparse.Namespace(
|
||||
directory=root,
|
||||
zone="example-org",
|
||||
password="storage-password",
|
||||
endpoint="storage.bunnycdn.com",
|
||||
purge_endpoint="https://purge.example",
|
||||
pull_zone_id="",
|
||||
api_key="",
|
||||
dry_run=False,
|
||||
workers=4,
|
||||
revision="abc1234",
|
||||
idempotency_key="test-run-123",
|
||||
)
|
||||
|
||||
with self.assertRaisesRegex(static_site.DeployError, "upload failed"):
|
||||
static_site.deploy_bunny(args)
|
||||
|
||||
finalize_deployment.assert_not_called()
|
||||
abort_deployment.assert_called_once_with(
|
||||
"https://purge.example",
|
||||
"example-org",
|
||||
"storage-password",
|
||||
"deployment-id",
|
||||
"test-run-123",
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue