mesh/delivery-group group feat/sdk1 rejected: composed together: the checker's verdict at the members' heads (428d048dd50a): unit: git.novox.be/novox/mesh-sdk/…
mesh/delivery closed: a newer head of the same pull request
mesh/check failed: unit: git.novox.be/novox/mesh-sdk/go/process.TestStatePutWritesAKeyWhole: a Put through a short blackout: 0, mesh-mail's state send…
Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
92 lines
3.7 KiB
Go
92 lines
3.7 KiB
Go
package catalogue
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A module says how each long-running resource is ready (novox/hq ADR 0240 rule 2, to-be 48 §8): `module
|
|
// check` refuses each part out of its bounds, each endpoint named by a port or an address, a tool the
|
|
// module does not serve, and a tool check alone — a test per refusal.
|
|
|
|
const healthDigest = "@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
|
|
// healthManifest is a module of one web container, one running service and one step, with the health
|
|
// given on the container (or on the resource named by on).
|
|
func healthManifest(t *testing.T, on string, health map[string]any, more ...map[string]any) []byte {
|
|
t.Helper()
|
|
resources := []map[string]any{
|
|
{"id": "server", "type": "container", "name": "app-server", "image": "registry.example/app" + healthDigest,
|
|
"ports": []any{"8080"}},
|
|
{"id": "daemon", "type": "service", "unit": "app.service", "state": "running"},
|
|
{"id": "seed", "type": "container", "name": "app-seed", "image": "registry.example/app" + healthDigest,
|
|
"run-once": true},
|
|
{"id": "sweep", "type": "container", "name": "app-sweep", "image": "registry.example/app" + healthDigest,
|
|
"schedule": "0 3 * * *"},
|
|
}
|
|
resources = append(resources, more...)
|
|
for _, r := range resources {
|
|
if r["id"] == on && health != nil {
|
|
r["health"] = health
|
|
}
|
|
}
|
|
m := map[string]any{"module": "app", "requires": []any{"postgres-database"}, "tools": []any{"app_status"},
|
|
"listens": []any{
|
|
map[string]any{"name": "web", "port": 8080, "from": "mesh"},
|
|
map[string]any{"name": "beacon", "port": 9999, "protocol": "udp", "from": "mesh"},
|
|
},
|
|
"resources": resources}
|
|
raw, err := json.Marshal(m)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return raw
|
|
}
|
|
|
|
func TestAWellFormedHealthIsAccepted(t *testing.T) {
|
|
for _, h := range []map[string]any{
|
|
{"kind": "http", "endpoint": "web", "path": "/healthz", "status": 200, "body": "ok", "needs": "postgres-database"},
|
|
{"kind": "tcp", "endpoint": "web", "interval": "10s", "timeout": "2s", "looks": 2, "grace": "0s"},
|
|
{"kind": "runtime"},
|
|
{"kind": "exec", "command": "pg_isready -q", "grace": "4m", "looks": 2, "interval": "30s"},
|
|
} {
|
|
if _, err := decodeForTest(healthManifest(t, "server", h)); err != nil {
|
|
t.Errorf("%v was refused: %v", h, err)
|
|
}
|
|
}
|
|
if _, err := decodeForTest(healthManifest(t, "daemon", map[string]any{"kind": "unit"})); err != nil {
|
|
t.Errorf("a service's own readiness was refused: %v", err)
|
|
}
|
|
// A tool beside a check of another kind on the module.
|
|
raw := healthManifest(t, "server", map[string]any{"kind": "http", "endpoint": "web"},
|
|
map[string]any{"id": "admin", "type": "service", "unit": "app-admin.service", "state": "running",
|
|
"health": map[string]any{"kind": "tool", "tool": "app_status"}})
|
|
if _, err := decodeForTest(raw); err != nil {
|
|
t.Errorf("a tool check beside an http check was refused: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestTheUndeclaredAreTheLongRunningWithoutHealth(t *testing.T) {
|
|
m, err := decodeForTest(healthManifest(t, "server", map[string]any{"kind": "runtime"}))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := strings.Join(Undeclared(m), ","); got != "daemon" {
|
|
t.Errorf("undeclared: %q; the step and the schedule are not long-running, the server declares", got)
|
|
}
|
|
}
|
|
|
|
func TestATooledHealthIsGrantedToTheEngine(t *testing.T) {
|
|
raw := healthManifest(t, "server", map[string]any{"kind": "http", "endpoint": "web"},
|
|
map[string]any{"id": "admin", "type": "service", "unit": "app-admin.service", "state": "running",
|
|
"health": map[string]any{"kind": "tool", "tool": "app_status"}})
|
|
m, err := decodeForTest(raw)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := HealthChecks(m); len(got) != 1 || got[0] != "app.app_status" {
|
|
t.Errorf("checks %v", got)
|
|
}
|
|
}
|