blob: 24d17a4810afb89d4b64756c0d5d9a06ca571feb [file] [log] [blame]
Serge Bazanski48e9bab2023-02-20 15:28:59 +01001package bmdb
2
3import (
4 "testing"
5)
6
7// TestMigrateUpDown performs a full-up and full-down migration test on an
8// in-memory database twice.
9//
10// Doing this the first time allows us to check the up migrations are valid and
11// that the down migrations clean up enough after themselves for earlier down
12// migrations to success.
13//
14// Doing this the second time allows us to make sure the down migrations cleaned
15// up enough after themselves that they have left no table/type behind.
16func TestMigrateUpDown(t *testing.T) {
17 // Start with an empty database.
18 b := dut()
19 _, err := b.Open(false)
20 if err != nil {
21 t.Fatalf("Starting empty database failed: %v", err)
22 }
23
24 // Migrations go up.
25 if err := b.Database.MigrateUp(); err != nil {
26 t.Fatalf("Initial up migration failed: %v", err)
27 }
28 // Migrations go down.
29 if err := b.Database.MigrateDownDangerDanger(); err != nil {
30 t.Fatalf("Initial down migration failed: %v", err)
31 }
32 // Migrations go up.
33 if err := b.Database.MigrateUp(); err != nil {
34 t.Fatalf("Second up migration failed: %v", err)
35 }
36 // Migrations go down.
37 if err := b.Database.MigrateDownDangerDanger(); err != nil {
38 t.Fatalf("Second down migration failed: %v", err)
39 }
40}