package main import ( "encoding/json" "os" "strings" "testing" ) func manifest(t *testing.T) map[string]any { t.Helper() raw, err := os.ReadFile("../../module.json") if err != nil { t.Fatal(err) } var m map[string]any if err := json.Unmarshal(raw, &m); err != nil { t.Fatal(err) } return m } // 1516/AC6: minio claims object-store (scope mesh) serving link, invokes seat:mesh-controller.seats, builds the Go // bundle, and no tool named minio_presigned_url remains. func TestManifestClaimsTheSeat(t *testing.T) { m := manifest(t) seats, _ := m["seats"].([]any) if len(seats) != 1 || seats[0].(map[string]any)["name"] != "object-store" || seats[0].(map[string]any)["scope"] != "mesh" || len(seats[0].(map[string]any)["serves"].([]any)) != 1 || seats[0].(map[string]any)["serves"].([]any)[0] != "link" { t.Fatalf("the seat object-store is not declared in seats (the mesh defines no seat a module does not declare): %v", seats) } claims := m["claims"].([]any) if len(claims) != 1 { t.Fatalf("claims: %v", claims) } c := claims[0].(map[string]any) serves := c["serves"].([]any) if c["name"] != "object-store" || c["scope"] != "mesh" || len(serves) != 1 || serves[0] != "link" { t.Fatalf("claim: %v", c) } inv := m["invokes"].([]any) if len(inv) != 1 || inv[0] != "seat:mesh-controller.seats" { t.Fatalf("invokes: %v", inv) } var goBundle map[string]any for _, a := range m["build"].(map[string]any)["artifacts"].([]any) { if a.(map[string]any)["from"] == "cmd/object-store" { goBundle = a.(map[string]any) } } if goBundle == nil || goBundle["language"] != "go" || goBundle["kind"] != "bundle" { t.Fatalf("no Go bundle for cmd/object-store: %v", goBundle) } env := goBundle["env"].(map[string]any) for _, word := range []string{ConfigWord, LinksWord, ReceivesWord} { if env[word] == nil { t.Errorf("the Go bundle's env lacks %s", word) } } for _, f := range []string{"../../tools/index.ts", "../../client.ts"} { raw, err := os.ReadFile(f) if err != nil { t.Fatal(err) } if strings.Contains(string(raw), "minio_presigned_url") || strings.Contains(string(raw), "presignedUrl") { t.Errorf("%s still has the root-signed link", f) } } } // 1516/AC1: the file the Go tool reads is rendered from files/object-store.json with the facts the s3-bucket binding // renders for a consumer: at is the providing machine's `at`, port the S3 endpoint's port (brother's files/store.json // is the writer of that shape: scheme, at, port, region). func TestStoreFileSaysWhatTheBindingSays(t *testing.T) { raw, err := os.ReadFile("../../files/object-store.json") if err != nil { t.Fatal(err) } var f map[string]string if err := json.Unmarshal(raw, &f); err != nil { t.Fatal(err) } if f["at"] != "${machine:at}" || f["port"] != "${port:9000}" || f["scheme"] != "http" || f["region"] != "eu-west" { t.Fatalf("object-store.json: %v", f) } brother, err := os.ReadFile("../../../brother/files/store.json") if err != nil { t.Fatal(err) } var b map[string]string if err := json.Unmarshal(brother, &b); err != nil { t.Fatal(err) } for _, k := range []string{"scheme", "at", "port", "region"} { if _, ok := b[k]; !ok { t.Errorf("brother's store.json has no %s: the shape moved", k) } if _, ok := f[k]; !ok { t.Errorf("object-store.json has no %s", k) } } // The same values: minio's serves.s3-bucket.port is the port its S3 listen declares. m := manifest(t) if port := m["serves"].(map[string]any)["s3-bucket"].(map[string]any)["port"]; port != float64(9000) { t.Errorf("serves port %v", port) } }