blink-so[bot] 9085b30390 feat: add GCP disk snapshot module for Coder workspaces
This module provides disk snapshot functionality for Coder workspaces running on GCP:

- Automatic snapshots when workspaces are stopped
- Configurable retention (default: 3 snapshots)
- User parameter to select from available snapshots
- Defaults to newest snapshot on workspace start
- Automatic cleanup of old snapshots beyond retention
- Uses GCP labels for workspace/owner filtering

Co-authored-by: M Atif Ali <matifali@coder.com>
2026-02-05 06:45:28 +00:00

91 lines
2.7 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import {
runTerraformApply,
runTerraformInit,
} from "~test";
describe("gcp-disk-snapshot", async () => {
await runTerraformInit(import.meta.dir);
it("required variables with test mode", async () => {
await runTerraformApply(import.meta.dir, {
disk_self_link: "projects/test-project/zones/us-central1-a/disks/test-disk",
default_image: "debian-cloud/debian-12",
zone: "us-central1-a",
project: "test-project",
test_mode: true,
});
});
it("missing variable: disk_self_link", async () => {
await expect(
runTerraformApply(import.meta.dir, {
default_image: "debian-cloud/debian-12",
zone: "us-central1-a",
project: "test-project",
test_mode: true,
}),
).rejects.toThrow();
});
it("missing variable: default_image", async () => {
await expect(
runTerraformApply(import.meta.dir, {
disk_self_link: "projects/test-project/zones/us-central1-a/disks/test-disk",
zone: "us-central1-a",
project: "test-project",
test_mode: true,
}),
).rejects.toThrow();
});
it("missing variable: zone", async () => {
await expect(
runTerraformApply(import.meta.dir, {
disk_self_link: "projects/test-project/zones/us-central1-a/disks/test-disk",
default_image: "debian-cloud/debian-12",
project: "test-project",
test_mode: true,
}),
).rejects.toThrow();
});
it("missing variable: project", async () => {
await expect(
runTerraformApply(import.meta.dir, {
disk_self_link: "projects/test-project/zones/us-central1-a/disks/test-disk",
default_image: "debian-cloud/debian-12",
zone: "us-central1-a",
test_mode: true,
}),
).rejects.toThrow();
});
it("supports optional variables", async () => {
await runTerraformApply(import.meta.dir, {
disk_self_link: "projects/test-project/zones/us-central1-a/disks/test-disk",
default_image: "debian-cloud/debian-12",
zone: "us-central1-a",
project: "test-project",
test_mode: true,
snapshot_retention_count: 5,
storage_locations: JSON.stringify(["us-central1"]),
labels: JSON.stringify({
environment: "test",
team: "engineering",
}),
});
});
it("custom retention count", async () => {
await runTerraformApply(import.meta.dir, {
disk_self_link: "projects/test-project/zones/us-central1-a/disks/test-disk",
default_image: "debian-cloud/debian-12",
zone: "us-central1-a",
project: "test-project",
test_mode: true,
snapshot_retention_count: 10,
});
});
});