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 "io"
5 "log/slog"
6 "path/filepath"
7 "testing"
8
9 "amadan.net/oficina/equipo/internal/equipo"
10 "amadan.net/rastrillo/rastrillo/db"
11 "amadan.net/rastrillo/rastrillo/migrate"
12)
13
14func TestCoordinatorMessageSourcesUpgrade(t *testing.T) {
15 path := filepath.Join(t.TempDir(), "sources.db")
16 d, err := db.Open(path, slog.New(slog.NewTextHandler(io.Discard, nil)))
17 must(t, err)
18 defer d.Close()
19 old := &migrate.Set{}
20 for _, m := range equipo.BootSchema.All() {
21 if m.ID != "equipo/0021_coordinator_sources" {
22 old.Add(m)
23 }
24 }
25 _, err = migrate.Apply(ctx, d, old)
26 must(t, err)
27 _, err = d.Writer().Exec("INSERT INTO conversation_messages(id,body) VALUES('legacy','retained')")
28 must(t, err)
29 result, err := migrate.Apply(ctx, d, equipo.BootSchema)
30 must(t, err)
31 if len(result.Applied) != 1 || result.Applied[0] != "equipo/0021_coordinator_sources" {
32 t.Fatal(result.Applied)
33 }
34 var body string
35 var empty bool
36 must(t, d.Writer().QueryRow("SELECT body,source_refs IS NULL FROM conversation_messages WHERE id='legacy'").Scan(&body, &empty))
37 if body != "retained" || !empty {
38 t.Fatal("legacy message changed")
39 }
40 fresh := newFixture(t)
41 upgraded, err := migrate.Read(ctx, d.Writer())
42 must(t, err)
43 baseline, err := migrate.Read(ctx, fresh.DB.Writer())
44 must(t, err)
45 if !upgraded.Equal(baseline) {
46 t.Fatal(upgraded.Diff(baseline))
47 }
48}
49