Name no node in postgres's, ssh-client's and mesh-mail-web's fixtures (issue 1838)
This commit is contained in:
@@ -21,7 +21,7 @@ func TestQuoting(t *testing.T) {
|
||||
if got := Literal(`it's`); got != `'it''s'` {
|
||||
t.Fatal(got)
|
||||
}
|
||||
if got := RoleStatement(false, "mesh_ace_letta", "p'w"); got != `CREATE ROLE "mesh_ace_letta" WITH LOGIN PASSWORD 'p''w' VALID UNTIL 'infinity'` {
|
||||
if got := RoleStatement(false, "mesh_node-a_letta", "p'w"); got != `CREATE ROLE "mesh_node-a_letta" WITH LOGIN PASSWORD 'p''w' VALID UNTIL 'infinity'` {
|
||||
t.Fatal(got)
|
||||
}
|
||||
if got := RoleStatement(true, "r", "p"); !strings.HasPrefix(got, `ALTER ROLE "r" WITH LOGIN`) {
|
||||
@@ -61,7 +61,7 @@ func TestExtensionsFromAContribution(t *testing.T) {
|
||||
func TestAnExtensionTheServerDoesNotOfferIsRefusedByName(t *testing.T) {
|
||||
f, c := newFake(admin)
|
||||
f.answer(`FROM pg_available_extensions`, []string{"name"}, []string{"vector"}, []string{"pg_trgm"})
|
||||
err := c.EnsureExtensions(ctx, "mesh_ace_letta", []string{"vector", "made_up", "plv8"})
|
||||
err := c.EnsureExtensions(ctx, "mesh_node-a_letta", []string{"vector", "made_up", "plv8"})
|
||||
if err == nil || !strings.Contains(err.Error(), `"made_up"`) || !strings.Contains(err.Error(), `"plv8"`) {
|
||||
t.Fatalf("refusal does not name the extensions: %v", err)
|
||||
}
|
||||
@@ -73,28 +73,28 @@ func TestAnExtensionTheServerDoesNotOfferIsRefusedByName(t *testing.T) {
|
||||
func TestExtensionsAreInstalledAsTheAdminInTheConsumersDatabase(t *testing.T) {
|
||||
f, c := newFake(admin)
|
||||
f.answer(`FROM pg_available_extensions`, []string{"name"}, []string{"vector"})
|
||||
if err := c.EnsureExtensions(ctx, "mesh_ace_letta", []string{"vector"}); err != nil {
|
||||
if err := c.EnsureExtensions(ctx, "mesh_node-a_letta", []string{"vector"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
last := f.calls[len(f.calls)-1]
|
||||
if last.SQL != `CREATE EXTENSION IF NOT EXISTS "vector"` || last.Database != "mesh_ace_letta" || last.User != "postgres" || last.Password != "admin-secret" {
|
||||
if last.SQL != `CREATE EXTENSION IF NOT EXISTS "vector"` || last.Database != "mesh_node-a_letta" || last.User != "postgres" || last.Password != "admin-secret" {
|
||||
t.Fatalf("%+v", last)
|
||||
}
|
||||
noDrop(t, f.statements())
|
||||
|
||||
f.reset()
|
||||
if err := c.EnsureExtensions(ctx, "mesh_ace_letta", nil); err != nil || len(f.calls) != 0 {
|
||||
if err := c.EnsureExtensions(ctx, "mesh_node-a_letta", nil); err != nil || len(f.calls) != 0 {
|
||||
t.Fatalf("asked the server for nothing to do: %v %v", f.calls, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateIsIdempotent(t *testing.T) {
|
||||
f, c := newFake(admin)
|
||||
if err := c.CreateDatabaseAndRole(ctx, "mesh_ace_letta", "mesh_ace_letta", "pw"); err != nil {
|
||||
if err := c.CreateDatabaseAndRole(ctx, "mesh_node-a_letta", "mesh_node-a_letta", "pw"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sql := f.statements()
|
||||
if !has(sql, `^CREATE ROLE "mesh_ace_letta"`) || !has(sql, `^CREATE DATABASE "mesh_ace_letta" OWNER "mesh_ace_letta"$`) {
|
||||
if !has(sql, `^CREATE ROLE "mesh_node-a_letta"`) || !has(sql, `^CREATE DATABASE "mesh_node-a_letta" OWNER "mesh_node-a_letta"$`) {
|
||||
t.Fatal(strings.Join(sql, "\n"))
|
||||
}
|
||||
|
||||
@@ -102,14 +102,14 @@ func TestCreateIsIdempotent(t *testing.T) {
|
||||
f, c = newFake(admin)
|
||||
f.answer(`FROM pg_roles`, []string{"?column?"}, []string{"1"})
|
||||
f.answer(`FROM pg_database`, []string{"?column?"}, []string{"1"})
|
||||
if err := c.CreateDatabaseAndRole(ctx, "mesh_ace_letta", "mesh_ace_letta", "pw"); err != nil {
|
||||
if err := c.CreateDatabaseAndRole(ctx, "mesh_node-a_letta", "mesh_node-a_letta", "pw"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sql = f.statements()
|
||||
if !has(sql, `^ALTER ROLE "mesh_ace_letta" WITH LOGIN PASSWORD 'pw' VALID UNTIL 'infinity'`) || has(sql, `CREATE DATABASE`) {
|
||||
if !has(sql, `^ALTER ROLE "mesh_node-a_letta" WITH LOGIN PASSWORD 'pw' VALID UNTIL 'infinity'`) || has(sql, `CREATE DATABASE`) {
|
||||
t.Fatal(strings.Join(sql, "\n"))
|
||||
}
|
||||
if !has(sql, `^GRANT ALL PRIVILEGES ON DATABASE "mesh_ace_letta" TO "mesh_ace_letta"$`) {
|
||||
if !has(sql, `^GRANT ALL PRIVILEGES ON DATABASE "mesh_node-a_letta" TO "mesh_node-a_letta"$`) {
|
||||
t.Fatal(strings.Join(sql, "\n"))
|
||||
}
|
||||
noDrop(t, sql)
|
||||
|
||||
@@ -67,9 +67,9 @@ func (w *world) give(given ...map[string]any) {
|
||||
|
||||
func TestAddingExtensionsAppliesTheConsumerAgain(t *testing.T) {
|
||||
w := newWorld(t)
|
||||
w.give(map[string]any{"as": "mesh_ace_letta", "values": map[string]any{"name": "letta"}})
|
||||
w.give(map[string]any{"as": "mesh_node-a_letta", "values": map[string]any{"name": "letta"}})
|
||||
w.h.Reconcile(ctx)
|
||||
w.give(map[string]any{"as": "mesh_ace_letta", "values": map[string]any{"name": "letta", "extensions": []any{"vector"}}})
|
||||
w.give(map[string]any{"as": "mesh_node-a_letta", "values": map[string]any{"name": "letta", "extensions": []any{"vector"}}})
|
||||
w.h.Reconcile(ctx)
|
||||
if len(w.a.created) != 2 {
|
||||
t.Fatalf("created %d times", len(w.a.created))
|
||||
@@ -88,14 +88,14 @@ func TestProvisionerCreatesTheDatabaseThenItsExtensions(t *testing.T) {
|
||||
f.answer(`FROM pg_available_extensions`, []string{"name"}, []string{"vector"})
|
||||
var events []string
|
||||
a := provisioner{pg: c, announce: func(e string, _ map[string]string) { events = append(events, e) }}
|
||||
p := harness.Provision{As: "mesh_ace_letta", Password: "pw", Values: map[string]any{"name": "letta", "extensions": []any{"vector"}}}
|
||||
p := harness.Provision{As: "mesh_node-a_letta", Password: "pw", Values: map[string]any{"name": "letta", "extensions": []any{"vector"}}}
|
||||
if err := a.Create(ctx, p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sql := f.statements()
|
||||
// The extension once the database exists, and last the active mark (novox/hq ADR 0230).
|
||||
if !strings.HasPrefix(sql[len(sql)-2], `CREATE EXTENSION IF NOT EXISTS "vector"`) || !has(sql, `CREATE DATABASE "mesh_ace_letta"`) ||
|
||||
sql[len(sql)-1] != `COMMENT ON ROLE "mesh_ace_letta" IS '{"mesh":"consumer"}'` {
|
||||
if !strings.HasPrefix(sql[len(sql)-2], `CREATE EXTENSION IF NOT EXISTS "vector"`) || !has(sql, `CREATE DATABASE "mesh_node-a_letta"`) ||
|
||||
sql[len(sql)-1] != `COMMENT ON ROLE "mesh_node-a_letta" IS '{"mesh":"consumer"}'` {
|
||||
t.Fatal(strings.Join(sql, "\n"))
|
||||
}
|
||||
if strings.Join(events, ",") != "database.provisioned" {
|
||||
@@ -117,7 +117,7 @@ func TestProvisionerCreatesTheDatabaseThenItsExtensions(t *testing.T) {
|
||||
|
||||
f.reset()
|
||||
f.answer(`FROM pg_roles`, []string{"?column?"}, []string{"1"})
|
||||
if err := a.Retire(ctx, "mesh_ace_letta", nil, "test", time.Now()); err != nil {
|
||||
if err := a.Retire(ctx, "mesh_node-a_letta", nil, "test", time.Now()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
noDrop(t, f.statements())
|
||||
|
||||
@@ -28,7 +28,7 @@ const ProvisionName = "postgres-database"
|
||||
// consumers. What differs from keycloak is only this declaration (issue 849).
|
||||
//
|
||||
// It serves its consumers the port its server is published on, on its machine (servedPort), never the container's
|
||||
// own 5432: on a machine that publishes it elsewhere (6852:5432 on novox) nothing answers 5432 (issue 957).
|
||||
// own 5432: on a machine that publishes it elsewhere (6852:5432 on node-c) nothing answers 5432 (issue 957).
|
||||
func moved(consumersFile string, h *harness.Harness, servedPort int) (*harness.Moved, *provider.Provider, provider.Bus, error) {
|
||||
return harness.NewMoved(consumersFile, h, harness.MovedSpec{Module: "postgres", Provision: ProvisionName,
|
||||
Offer: provider.Offer{Credential: provider.PerConsumer, Serves: map[string]any{"port": servedPort}},
|
||||
|
||||
@@ -3,7 +3,7 @@ package main
|
||||
import "testing"
|
||||
|
||||
// postgres serves its consumers the port its server is published on, on its machine, as its own code reaches it:
|
||||
// on novox the manifest's 5432 is published as 6852, and a consumer handed 5432 reached nothing (issue 957).
|
||||
// on node-c the manifest's 5432 is published as 6852, and a consumer handed 5432 reached nothing (issue 957).
|
||||
func TestPostgresServesThePortItsServerIsPublishedOn(t *testing.T) {
|
||||
env := func(vars map[string]string) func(string) string { return func(k string) string { return vars[k] } }
|
||||
for _, c := range []struct {
|
||||
|
||||
@@ -9,8 +9,8 @@ package main
|
||||
// database and a retired one is still worth backing up, and because re-enabling must give it back as it
|
||||
// was. The mark is the role's comment, a JSON object the mesh owns:
|
||||
//
|
||||
// {"mesh":"consumer","node":"ace"} active
|
||||
// {"mesh":"consumer","node":"ace","retired":"2026-10-06T…Z","why":"…"} retired
|
||||
// {"mesh":"consumer","node":"node-a"} active
|
||||
// {"mesh":"consumer","node":"node-a","retired":"2026-10-06T…Z","why":"…"} retired
|
||||
//
|
||||
// Asked for again, the ordinary create sets LOGIN and the password again and writes the active mark.
|
||||
// Deleted — only through `cleanup delete` — the database is dropped, then the role, unless it still owns
|
||||
|
||||
@@ -12,15 +12,15 @@ import (
|
||||
|
||||
func TestRetiringLocksMarksAndDropsNothing(t *testing.T) {
|
||||
f, c := newFake(admin)
|
||||
f.answer(`shobj_description\(oid`, []string{"c"}, []string{`{"mesh":"consumer","node":"ace"}`})
|
||||
f.answer(`shobj_description\(oid`, []string{"c"}, []string{`{"mesh":"consumer","node":"node-a"}`})
|
||||
f.answer(`SELECT 1 FROM pg_roles`, []string{"?column?"}, []string{"1"})
|
||||
at := time.Date(2026, 10, 6, 12, 0, 0, 0, time.UTC)
|
||||
if err := c.RetireRole(ctx, "mesh_ace_letta", "the mesh stopped asking for it", at); err != nil {
|
||||
if err := c.RetireRole(ctx, "mesh_node-a_letta", "the mesh stopped asking for it", at); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sql := f.statements()
|
||||
if !has(sql, `ALTER ROLE "mesh_ace_letta" NOLOGIN`) || !has(sql, `pg_terminate_backend.*usename = 'mesh_ace_letta'`) ||
|
||||
!has(sql, `COMMENT ON ROLE "mesh_ace_letta" IS '\{"mesh":"consumer","node":"ace","retired":"2026-10-06T12:00:00Z","why":"the mesh stopped asking for it"\}'`) {
|
||||
if !has(sql, `ALTER ROLE "mesh_node-a_letta" NOLOGIN`) || !has(sql, `pg_terminate_backend.*usename = 'mesh_node-a_letta'`) ||
|
||||
!has(sql, `COMMENT ON ROLE "mesh_node-a_letta" IS '\{"mesh":"consumer","node":"node-a","retired":"2026-10-06T12:00:00Z","why":"the mesh stopped asking for it"\}'`) {
|
||||
t.Fatal(strings.Join(sql, "\n"))
|
||||
}
|
||||
noDrop(t, sql)
|
||||
@@ -38,14 +38,14 @@ func TestRetiringLocksMarksAndDropsNothing(t *testing.T) {
|
||||
func TestTheInventoryIsWhatTheMeshMadeByMarkOrShape(t *testing.T) {
|
||||
f, c := newFake(admin)
|
||||
f.answer(`FROM pg_roles r`, []string{"rolname", "rolcanlogin", "mark", "mesh_shaped", "size"},
|
||||
[]string{"active_marked", "t", `{"mesh":"consumer","node":"ace"}`, "f", "100"},
|
||||
[]string{"active_marked", "t", `{"mesh":"consumer","node":"node-a"}`, "f", "100"},
|
||||
[]string{"active_shaped", "t", "", "t", "200"},
|
||||
[]string{"retired_marked", "f", `{"mesh":"consumer","node":"ace","retired":"2026-10-06T12:00:00Z","why":"gone"}`, "t", "300"},
|
||||
[]string{"retired_marked", "f", `{"mesh":"consumer","node":"node-a","retired":"2026-10-06T12:00:00Z","why":"gone"}`, "t", "300"},
|
||||
[]string{"locked_before", "f", "", "t", "400"},
|
||||
[]string{"hal_registry", "t", "", "f", "500"},
|
||||
[]string{"jochens", "t", "", "t", ""},
|
||||
)
|
||||
f.answer(`_deleted_`, []string{"datname", "size"}, []string{"mesh_novox_gitea_deleted_20261005", "7771827"})
|
||||
f.answer(`_deleted_`, []string{"datname", "size"}, []string{"mesh_node-c_gitea_deleted_20261005", "7771827"})
|
||||
inv, err := c.Inventory(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -57,7 +57,7 @@ func TestTheInventoryIsWhatTheMeshMadeByMarkOrShape(t *testing.T) {
|
||||
t.Fatalf("%+v", inv.Retired)
|
||||
}
|
||||
r := inv.Retired[0]
|
||||
if r.Consumer != "retired_marked" || r.Node != "ace" || r.Why != "gone" || r.SizeBytes != 300 ||
|
||||
if r.Consumer != "retired_marked" || r.Node != "node-a" || r.Why != "gone" || r.SizeBytes != 300 ||
|
||||
r.RetiredAt.Format(time.RFC3339) != "2026-10-06T12:00:00Z" {
|
||||
t.Fatalf("%+v", r)
|
||||
}
|
||||
@@ -72,13 +72,13 @@ func TestTheInventoryIsWhatTheMeshMadeByMarkOrShape(t *testing.T) {
|
||||
func TestDeletingRefusesALoginThatCanConnect(t *testing.T) {
|
||||
f, c := newFake(admin)
|
||||
f.answer(`SELECT rolcanlogin`, []string{"rolcanlogin"}, []string{"t"})
|
||||
if _, err := c.DeleteRetired(ctx, harness.Retired{Consumer: "mesh_ace_baserow", Kind: harness.KindConsumer}); err == nil {
|
||||
if _, err := c.DeleteRetired(ctx, harness.Retired{Consumer: "mesh_node-a_baserow", Kind: harness.KindConsumer}); err == nil {
|
||||
t.Fatal("deleted an active consumer")
|
||||
}
|
||||
noDrop(t, f.statements())
|
||||
|
||||
f, c = newFake(admin)
|
||||
if _, err := c.DeleteRetired(ctx, harness.Retired{Consumer: "mesh_ace_baserow", Kind: KindSetAside}); err == nil {
|
||||
if _, err := c.DeleteRetired(ctx, harness.Retired{Consumer: "mesh_node-a_baserow", Kind: KindSetAside}); err == nil {
|
||||
t.Fatal("dropped a database not set aside")
|
||||
}
|
||||
noDrop(t, f.statements())
|
||||
@@ -88,20 +88,20 @@ func TestDeletingDropsTheDatabaseThenTheRole(t *testing.T) {
|
||||
f, c := newFake(admin)
|
||||
f.answer(`SELECT rolcanlogin`, []string{"rolcanlogin"}, []string{"f"})
|
||||
f.answer(`SELECT pg_database_size`, []string{"size"}, []string{"9000"})
|
||||
freed, err := c.DeleteRetired(ctx, harness.Retired{Consumer: "mesh_ace_letta", Kind: harness.KindConsumer})
|
||||
freed, err := c.DeleteRetired(ctx, harness.Retired{Consumer: "mesh_node-a_letta", Kind: harness.KindConsumer})
|
||||
if err != nil || freed != 9000 {
|
||||
t.Fatal(freed, err)
|
||||
}
|
||||
sql := strings.Join(f.statements(), "\n")
|
||||
db, role := strings.Index(sql, `DROP DATABASE "mesh_ace_letta"`), strings.Index(sql, `DROP ROLE "mesh_ace_letta"`)
|
||||
db, role := strings.Index(sql, `DROP DATABASE "mesh_node-a_letta"`), strings.Index(sql, `DROP ROLE "mesh_node-a_letta"`)
|
||||
if db < 0 || role < db {
|
||||
t.Fatal(sql)
|
||||
}
|
||||
// A role still owning a set-aside database is kept, and said.
|
||||
f, c = newFake(admin)
|
||||
f.answer(`SELECT rolcanlogin`, []string{"rolcanlogin"}, []string{"f"})
|
||||
f.answer(`SELECT datname FROM pg_database WHERE datdba`, []string{"datname"}, []string{"mesh_ace_letta_deleted_20261005"})
|
||||
if _, err := c.DeleteRetired(ctx, harness.Retired{Consumer: "mesh_ace_letta", Kind: harness.KindConsumer}); err == nil ||
|
||||
f.answer(`SELECT datname FROM pg_database WHERE datdba`, []string{"datname"}, []string{"mesh_node-a_letta_deleted_20261005"})
|
||||
if _, err := c.DeleteRetired(ctx, harness.Retired{Consumer: "mesh_node-a_letta", Kind: harness.KindConsumer}); err == nil ||
|
||||
!strings.Contains(err.Error(), "still owns") || has(f.statements(), `DROP ROLE`) {
|
||||
t.Fatal(err, f.statements())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user