oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package equipo
2
3import (
4 "amadan.net/rastrillo/rastrillo/migrate"
5 "context"
6 "testing"
7)
8
9func TestCopyMigrationDefaultsAndOldWriters(t *testing.T) {
10 all := Schema.All()
11 at := -1
12 for i, m := range all {
13 if m.ID == "equipo/0081_copy_specialist" {
14 at = i
15 }
16 }
17 if at < 0 {
18 t.Fatal("Copy migration missing")
19 }
20 ctx := context.Background()
21 d, err := migrate.Replay(ctx, all[:at])
22 if err != nil {
23 t.Fatal(err)
24 }
25 defer d.Close()
26 for _, sql := range []string{"INSERT INTO chat_projects(id,repo,state) VALUES ('p','amadan.net/oficina/sample','active')", "INSERT INTO chat_tasks(id,project_id) VALUES ('t','p')", "INSERT INTO chat_steps(id,task_id,specialist,round) VALUES ('s','t','engineering',2)"} {
27 if _, err := d.ExecContext(ctx, sql); err != nil {
28 t.Fatal(err)
29 }
30 }
31 if _, err := d.ExecContext(ctx, all[at].SQL); err != nil {
32 t.Fatal(err)
33 }
34 var owner string
35 var revision, round int
36 if err := d.QueryRowContext(ctx, "SELECT COALESCE(copy_owner,''),COALESCE(copy_revision,0) FROM chat_projects WHERE id='p'").Scan(&owner, &revision); err != nil || owner != "" || revision != 0 {
37 t.Fatalf("migration granted authority: %q %d %v", owner, revision, err)
38 }
39 if err := d.QueryRowContext(ctx, "SELECT repair_round FROM chat_tasks WHERE id='t'").Scan(&round); err != nil || round != 2 {
40 t.Fatalf("repair allowance reset: %d %v", round, err)
41 }
42 // An old binary can keep writing its known columns with the new tables retained.
43 if _, err := d.ExecContext(ctx, "INSERT INTO chat_projects(id,repo,state) VALUES ('old-writer','amadan.net/oficina/old','active')"); err != nil {
44 t.Fatal(err)
45 }
46 var granted int
47 if err := d.QueryRowContext(ctx, "SELECT count(*) FROM chat_projects WHERE COALESCE(copy_owner,'')<>''").Scan(&granted); err != nil || granted != 0 {
48 t.Fatalf("old writer granted authority: %d %v", granted, err)
49 }
50 var indexes int
51 if err := d.QueryRowContext(ctx, "SELECT count(*) FROM sqlite_master WHERE type='index' AND tbl_name='chat_copy_reviews' AND name IN ('idx_copy_reviews_task','idx_copy_reviews_attempt')").Scan(&indexes); err != nil || indexes != 2 {
52 t.Fatalf("Copy lookup indexes missing: %d %v", indexes, err)
53 }
54
55}
56