cloud/bmdb: add up/down migration test
This isn't very exhaustive, but it's enough to catch migration issues
which we already had.
Change-Id: Ie26b7646bb8b051a613e75cb69a1708f9288a0cc
Reviewed-on: https://review.monogon.dev/c/monogon/+/1137
Tested-by: Jenkins CI
Reviewed-by: Leopold Schabel <leo@monogon.tech>
diff --git a/cloud/bmaas/bmdb/migrations_test.go b/cloud/bmaas/bmdb/migrations_test.go
new file mode 100644
index 0000000..24d17a4
--- /dev/null
+++ b/cloud/bmaas/bmdb/migrations_test.go
@@ -0,0 +1,40 @@
+package bmdb
+
+import (
+ "testing"
+)
+
+// TestMigrateUpDown performs a full-up and full-down migration test on an
+// in-memory database twice.
+//
+// Doing this the first time allows us to check the up migrations are valid and
+// that the down migrations clean up enough after themselves for earlier down
+// migrations to success.
+//
+// Doing this the second time allows us to make sure the down migrations cleaned
+// up enough after themselves that they have left no table/type behind.
+func TestMigrateUpDown(t *testing.T) {
+ // Start with an empty database.
+ b := dut()
+ _, err := b.Open(false)
+ if err != nil {
+ t.Fatalf("Starting empty database failed: %v", err)
+ }
+
+ // Migrations go up.
+ if err := b.Database.MigrateUp(); err != nil {
+ t.Fatalf("Initial up migration failed: %v", err)
+ }
+ // Migrations go down.
+ if err := b.Database.MigrateDownDangerDanger(); err != nil {
+ t.Fatalf("Initial down migration failed: %v", err)
+ }
+ // Migrations go up.
+ if err := b.Database.MigrateUp(); err != nil {
+ t.Fatalf("Second up migration failed: %v", err)
+ }
+ // Migrations go down.
+ if err := b.Database.MigrateDownDangerDanger(); err != nil {
+ t.Fatalf("Second down migration failed: %v", err)
+ }
+}