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 "context"
5 "testing"
6
7 "amadan.net/rastrillo/rastrillo/migrate"
8)
9
10// Migration 0112 keeps every project's minted site app as its site
11// binding's app, with no place, created nothing and no key: a project
12// without an app gets no binding.
13func TestPlacesMigrationCopiesSiteApps(t *testing.T) {
14 ctx := context.Background()
15 var before []migrate.Migration
16 var places migrate.Migration
17 for _, m := range Schema.All() {
18 if m.ID == "equipo/0112_places" {
19 places = m
20 break
21 }
22 before = append(before, m)
23 }
24 if places.SQL == "" {
25 t.Fatal("no migration 0112")
26 }
27 d, err := migrate.Replay(ctx, before)
28 if err != nil {
29 t.Fatal(err)
30 }
31 defer d.Close()
32 if _, err := d.ExecContext(ctx, `INSERT INTO chat_projects (id, repo, state, site_app, created_at, updated_at) VALUES ('p1', 'amadan.net/paulca/old', 'active', 'site-old-abcdef', '2026-11-01', '2026-11-02'), ('p2', 'amadan.net/paulca/nearys', 'active', NULL, '2026-11-01', '2026-11-01'), ('p3', 'amadan.net/paulca/blank', 'active', '', '2026-11-01', '2026-11-01')`); err != nil {
33 t.Fatal(err)
34 }
35 if _, err := d.ExecContext(ctx, places.SQL); err != nil {
36 t.Fatal(err)
37 }
38 rows, err := d.QueryContext(ctx, `SELECT project_id, kind, place_id, app, revision, app_created_at IS NULL, coalesce(deploy_name, '') FROM chat_project_places ORDER BY project_id`)
39 if err != nil {
40 t.Fatal(err)
41 }
42 defer rows.Close()
43 var got []string
44 for rows.Next() {
45 var project, kind, place, app, deploy string
46 var revision int64
47 var uncreated bool
48 if err := rows.Scan(&project, &kind, &place, &app, &revision, &uncreated, &deploy); err != nil {
49 t.Fatal(err)
50 }
51 if kind != "site" || place != "" || revision != 1 || !uncreated || deploy != "" {
52 t.Fatalf("binding %s %s %q rev %d created %t deploy %q", project, kind, place, revision, !uncreated, deploy)
53 }
54 got = append(got, project+"="+app)
55 }
56 if len(got) != 1 || got[0] != "p1=site-old-abcdef" {
57 t.Fatalf("bindings %v", got)
58 }
59}
60