ADR 0593 §7: the composer with its refusals leaves mesh-sdk, so mesh-sdk carries no composition rule. The catalogue functions only the node-engine's composition reaches (Resolve, Resolution's Compose, Declaration, DataItems, LeftOut, Rules and the rest, the settings, placeholder and template refusals, the rendering helpers) are copied with their tests into internal/compose/resolution; a method of a mesh-sdk shape becomes a function taking it first. The composition calls its own copies, and the captured catalogue its tests read lives here now, shared by mesh-compose's tests. Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
49 lines
2.0 KiB
Go
49 lines
2.0 KiB
Go
package resolution
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
const handedProvider = `{"module":"db","version":"1","moved":true,
|
|
"provides":[{"name":"postgres-database","scope":"mesh","identity":{"max":63,"in":"a PostgreSQL role"}}],
|
|
"build":{"artifacts":[{"name":"files","kind":"archive","from":"files"}]},
|
|
"resources":[
|
|
{"id":"state","type":"directory","mode":"0700","place":"."},
|
|
{"id":"consumers","type":"file","path":"${dir:state}/consumers.json","mode":"0600","template":"files/consumers.json"}]}`
|
|
|
|
const consumersText = "${consumers:postgres-database}"
|
|
|
|
func builtProvider(text string) []mcat.Built {
|
|
return []mcat.Built{{Name: "files", Kind: mcat.ArtifactArchive,
|
|
Reference: mcat.ArtifactStoreScheme + "db/files/blobs/sha256:" + strings.Repeat("f", 64),
|
|
Digest: "sha256:" + strings.Repeat("f", 64), Texts: map[string]string{"consumers.json": text}}}
|
|
}
|
|
|
|
func TestWhatAConsumersPlaceholderMayNotBeIsRefused(t *testing.T) {
|
|
for why, c := range map[string]struct{ raw, text, want string }{
|
|
"a provision the module does not provide": {handedProvider, "${consumers:cache}", "does not provide"},
|
|
"a module providing nothing": {strings.Replace(handedProvider, `"provides":[{"name":"postgres-database","scope":"mesh","identity":{"max":63,"in":"a PostgreSQL role"}}],`,
|
|
"", 1), consumersText, "does not provide"},
|
|
"a file others may read": {strings.Replace(handedProvider, `"mode":"0600","template"`,
|
|
`"mode":"0640","template"`, 1), consumersText, "0600"},
|
|
"a file the program keeps": {strings.Replace(handedProvider, `"mode":"0600","template"`,
|
|
`"mode":"0600","create-once":true,"template"`, 1), consumersText, "owned"},
|
|
} {
|
|
m, err := decodeForTest([]byte(c.raw))
|
|
if err != nil {
|
|
t.Fatalf("%s: %v", why, err)
|
|
}
|
|
resolved, err := m.Resolve(builtProvider(c.text))
|
|
if err == nil {
|
|
r := notifierOn(t, resolved)
|
|
_, err = Compose(r, handingTo("store:5000"))
|
|
}
|
|
if err == nil || !strings.Contains(err.Error(), c.want) {
|
|
t.Errorf("%s: %v, want a refusal saying %q", why, err, c.want)
|
|
}
|
|
}
|
|
}
|