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 "database/sql"
6 "testing"
7
8 _ "modernc.org/sqlite"
9)
10
11func TestLiveChangesFailedInstallRollsBack(t *testing.T) {
12 d, err := sql.Open("sqlite", ":memory:")
13 if err != nil {
14 t.Fatal(err)
15 }
16 defer d.Close()
17 tx, err := d.BeginTx(context.Background(), nil)
18 if err != nil {
19 t.Fatal(err)
20 }
21 defer tx.Rollback()
22 // Missing application tables force installation to fail after its temp table.
23 for range 2 {
24 if err := installLiveChanges(context.Background(), tx); err == nil {
25 t.Fatal("partial installation accepted")
26 }
27 var count int
28 if err := tx.QueryRow("SELECT count(*) FROM sqlite_temp_master WHERE name LIKE 'equipo_live_%'").Scan(&count); err != nil {
29 t.Fatal(err)
30 }
31 if count != 0 {
32 t.Fatalf("failed install left %d temporary objects", count)
33 }
34 }
35 // The installation failure must not roll back the caller's transaction.
36 if _, err := tx.Exec("CREATE TABLE caller_work(id INTEGER)"); err != nil {
37 t.Fatal(err)
38 }
39 if err := tx.Commit(); err != nil {
40 t.Fatal(err)
41 }
42}
43