package resolution import ( "strings" "testing" mcat "git.novox.be/novox/mesh-sdk/go/catalogue" ) const barCollector = `{"module":"bars","version":"1","moved":true, "collections":[{"name":"blocks","comment":"#"}], "build":{"artifacts":[{"name":"files","kind":"archive","from":"files"}]}, "resources":[{"id":"conf","type":"file","path":"/etc/bars.conf","template":"files/bars"}]}` func TestASelectorIsRefusedWhenMalformedOrNamingACollectionNotCollected(t *testing.T) { for placeholder, want := range map[string]string{ "${collected:blocks:bar}": "", // no equals sign: a collection named blocks:bar "${collected:blocks:bar=top,bar=bottom}": "names bar twice", "${collected:blocks:bar=}": "is not =", "${collected:other:bar=top}": `does not collect "other"`, } { raw := strings.Replace(barCollector, `"template":"files/bars"`, `"content":"`+placeholder+`"`, 1) raw = strings.Replace(raw, `"build":{"artifacts":[{"name":"files","kind":"archive","from":"files"}]},`, "", 1) raw = strings.Replace(raw, `"moved":true,`, "", 1) m, err := decodeForTest([]byte(raw)) if err == nil { _, err = Declaration((mcat.Resolution{Node: "n", Modules: []mcat.Manifest{m}}), mcat.Rendering{}) } if want == "" { continue } if err == nil || !strings.Contains(err.Error(), want) { t.Errorf("%s: %v, want %q", placeholder, err, want) } } }