Download this file
| 1 | package plan3test |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "amadan.net/oficina/equipo/internal/equipo" |
| 7 | "amadan.net/rastrillo/rastrillo/migrate" |
| 8 | ) |
| 9 | |
| 10 | func TestInviteMigration(t *testing.T) { |
| 11 | f := inviteUpgradeFixture(t) |
| 12 | d := f.DB |
| 13 | result, err := migrate.Apply(ctx, d, equipo.BootSchema) |
| 14 | must(t, err) |
| 15 | if len(result.Applied) != 1 || result.Applied[0] != "equipo/0027_invitations" { |
| 16 | t.Fatal(result.Applied) |
| 17 | } |
| 18 | if f.count(t, "SELECT roster_epoch FROM teams") != 7 || f.count(t, "SELECT revision FROM members") != 4 || f.count(t, "SELECT count(*) FROM audit_events WHERE kind='old.audit'") != 1 { |
| 19 | t.Fatal("migration changed history") |
| 20 | } |
| 21 | if f.count(t, "SELECT count(*) FROM invitations") != 0 { |
| 22 | t.Fatal("migration issued invitations") |
| 23 | } |
| 24 | fresh := newFixture(t) |
| 25 | upgraded, err := migrate.Read(ctx, d.Writer()) |
| 26 | must(t, err) |
| 27 | clean, err := migrate.Read(ctx, fresh.DB.Writer()) |
| 28 | must(t, err) |
| 29 | if !upgraded.Equal(clean) { |
| 30 | t.Fatal(upgraded.Diff(clean)) |
| 31 | } |
| 32 | result, err = migrate.Apply(ctx, d, equipo.BootSchema) |
| 33 | must(t, err) |
| 34 | if len(result.Applied) != 0 { |
| 35 | t.Fatal("migration repeated") |
| 36 | } |
| 37 | } |
| 38 | |