oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package plan3test
2
3import (
4 "amadan.net/oficina/equipo/internal/equipo"
5 "amadan.net/rastrillo/rastrillo/db"
6 "amadan.net/rastrillo/rastrillo/migrate"
7 "io"
8 "log/slog"
9 "path/filepath"
10 "testing"
11)
12
13func TestTeamsMigration(t *testing.T) {
14 d, err := db.Open(filepath.Join(t.TempDir(), "teams.db"), slog.New(slog.NewTextHandler(io.Discard, nil)))
15 must(t, err)
16 t.Cleanup(func() { must(t, d.Close()) })
17 old := &migrate.Set{}
18 for _, m := range equipo.BootSchema.All() {
19 if m.ID != "equipo/0029_team_links" {
20 old.Add(m)
21 }
22 }
23 _, err = migrate.Apply(ctx, d, old)
24 must(t, err)
25 _, err = d.Writer().Exec("INSERT INTO personal_settings(team_id,person,landing,revision) VALUES('saved','saved@example.com','work',7)")
26 must(t, err)
27 result, err := migrate.Apply(ctx, d, equipo.BootSchema)
28 must(t, err)
29 if len(result.Applied) != 1 || result.Applied[0] != "equipo/0029_team_links" {
30 t.Fatal(result.Applied)
31 }
32 var landing string
33 var revision int
34 must(t, d.Writer().QueryRow("SELECT landing,revision FROM personal_settings WHERE person='saved@example.com'").Scan(&landing, &revision))
35 if landing != "work" || revision != 7 {
36 t.Fatal("lost existing landing setting")
37 }
38 fresh := newFixture(t)
39 up, err := migrate.Read(ctx, d.Writer())
40 must(t, err)
41 clean, err := migrate.Read(ctx, fresh.DB.Writer())
42 must(t, err)
43 if !up.Equal(clean) {
44 t.Fatal(up.Diff(clean))
45 }
46 result, err = migrate.Apply(ctx, d, equipo.BootSchema)
47 must(t, err)
48 if len(result.Applied) != 0 {
49 t.Fatal("migration repeated")
50 }
51}
52