62 lines
2.2 KiB
Go
62 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// CAT-BI1 (design 51 *Publishing*): the module publishes and copies through the image seat's verbs, which its manifest
|
|
// invokes, hears the seat's outcomes through its consumes, and holds no registry: no registry file, no artifact-store
|
|
// requirement, and none of its files names the store's assignment or binds it (issue 1703: the module is moved, and only
|
|
// what the mesh fills reaches its files).
|
|
func TestTheModuleInvokesTheImageSeatAndHoldsNoRegistry(t *testing.T) {
|
|
var m struct {
|
|
Requires []string `json:"requires"`
|
|
Invokes []string `json:"invokes"`
|
|
Consumes []string `json:"consumes"`
|
|
}
|
|
raw, err := os.ReadFile(filepath.Join(moduleDir, "module.json"))
|
|
if err != nil || json.Unmarshal(raw, &m) != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if want := []string{"seat:container-image-registry.publish", "seat:container-image-registry.publish-part",
|
|
"seat:container-image-registry.mirror", "seat:mesh-module-assigner.assignments"}; !slices.Equal(m.Invokes, want) {
|
|
t.Errorf("invokes = %v, want %v", m.Invokes, want)
|
|
}
|
|
// The builder's version.numbered for the late publish (ADR 0617 §1), and the seat's outcomes a copy waits on.
|
|
consumes := []string{NumberedPattern}
|
|
for _, e := range OutcomeEvents {
|
|
consumes = append(consumes, "container-image-registry."+e)
|
|
}
|
|
if !slices.Equal(m.Consumes, consumes) {
|
|
t.Errorf("consumes = %v, want %v", m.Consumes, consumes)
|
|
}
|
|
if slices.Contains(m.Requires, "artifact-store") {
|
|
t.Errorf("requires = %v: the module holds no store", m.Requires)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(moduleDir, "files", "registry")); !os.IsNotExist(err) {
|
|
t.Errorf("files/registry is still there: %v", err)
|
|
}
|
|
files := []string{filepath.Join(moduleDir, "module.json")}
|
|
entries, err := os.ReadDir(filepath.Join(moduleDir, "files"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, e := range entries {
|
|
files = append(files, filepath.Join(moduleDir, "files", e.Name()))
|
|
}
|
|
for _, f := range files {
|
|
body, err := os.ReadFile(f)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if strings.Contains(string(body), "${bound:artifact-store") || strings.Contains(string(body), "mesh-artifact-store") {
|
|
t.Errorf("%s names the artifact store", f)
|
|
}
|
|
}
|
|
}
|