oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package sends
2
3import (
4 "io"
5 "log/slog"
6 "os"
7 "path/filepath"
8 "testing"
9
10 "amadan.net/rastrillo/rastrillo/budget"
11 "amadan.net/rastrillo/rastrillo/db"
12)
13
14func TestMain(m *testing.M) { os.Exit(budget.Main(m)) }
15func TestRequestsStayWithViewer(t *testing.T) {
16 d, err := db.Open(filepath.Join(t.TempDir(), "requests.db"), slog.New(slog.NewTextHandler(io.Discard, nil)))
17 if err != nil {
18 t.Fatal(err)
19 }
20 defer d.Close()
21 for _, q := range []string{
22 `CREATE TABLE conversation_requests(principal text,operation text,request_id text,result text)`,
23 `INSERT INTO conversation_requests VALUES('alice','send','alice-request','{"ID":"alice-message"}'),('bob','send','bob-request','{"ID":"bob-message"}')`,
24 } {
25 if _, err := d.Writer().Exec(q); err != nil {
26 t.Fatal(err)
27 }
28 }
29 ids := []string{"alice-message", "bob-message"}
30 result, err := Requests(d.G, "alice", ids, func(id string) string { return id })
31 if err != nil {
32 t.Fatal(err)
33 }
34 if len(result) != 1 || result["alice-message"] != "alice-request" {
35 t.Fatalf("another viewer's request exposed: %v", result)
36 }
37 if err = d.Close(); err != nil {
38 t.Fatal(err)
39 }
40 if _, err = Requests(d.G, "alice", ids, func(id string) string { return id }); err == nil {
41 t.Fatal("lookup failure became an empty success")
42 }
43}
44