Write each module's have and the node's own facts beside the report, grouped per module and keyed by the module the controller names (issue 1132)
The node-engine reads a resource's module and a declaration's builds, says it does in every report (reads_modules), groups the apply's outcome per module with every failing resource named, and writes have.<node>.<module> and have.<node>.node to the bucket only when a value differs, never ahead of or in place of the report (novox/hq ADR 0429 section 4).
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package declaration
|
||||
|
||||
import "testing"
|
||||
|
||||
// 1132/AC1: a resource says its module, and the declaration says each module's build; a resource that does
|
||||
// not say gets today's guess, so an older controller still works.
|
||||
func TestAResourceSaysItsModuleAndTheDeclarationItsBuilds(t *testing.T) {
|
||||
d, err := Parse([]byte(`{"declaration":1,
|
||||
"builds":{"novox.be":"b-9","web":"b-4"},
|
||||
"resources":[
|
||||
{"id":"novox.be.data","type":"directory","path":"/srv/a","module":"novox.be"},
|
||||
{"id":"web.conf","type":"file","path":"/etc/w","content":"x","module":"web"},
|
||||
{"id":"old.dir","type":"directory","path":"/srv/old"},
|
||||
{"id":"base","type":"directory","path":"/srv/base"}]}`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for id, want := range map[string]string{"novox.be.data": "novox.be", "web.conf": "web", "old.dir": "old"} {
|
||||
got, ok := d.ModuleOfID(id)
|
||||
if !ok || got != want {
|
||||
t.Errorf("%s belongs to %q (%v), want %q", id, got, ok, want)
|
||||
}
|
||||
}
|
||||
if m, ok := d.ModuleOfID("base"); ok {
|
||||
t.Errorf("a resource with no module and no dot belongs to %q, want none", m)
|
||||
}
|
||||
if d.Builds["web"] != "b-4" || d.Builds["novox.be"] != "b-9" || len(d.Builds) != 2 {
|
||||
t.Errorf("builds read as %v", d.Builds)
|
||||
}
|
||||
}
|
||||
|
||||
// 1132/AC1: the module the declaration gives wins over the guess, even when the id would guess another.
|
||||
func TestTheDeclaredModuleWinsOverTheGuess(t *testing.T) {
|
||||
d, err := Parse([]byte(`{"declaration":1,"resources":[
|
||||
{"id":"a.b.c","type":"directory","path":"/srv/a","module":"a.b"},
|
||||
{"id":"x.y","type":"directory","path":"/srv/x","module":"other"}]}`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if m, _ := d.ModuleOfID("x.y"); m != "other" {
|
||||
t.Errorf("x.y belongs to %q, want the declared %q", m, "other")
|
||||
}
|
||||
}
|
||||
|
||||
// 1132/AC1: every kind accepts the field.
|
||||
func TestEveryKindAcceptsAModule(t *testing.T) {
|
||||
for _, typ := range []Type{TypeDirectory, TypeFile, TypeUser, TypeNetwork, TypeAccess, TypeArchive, TypeProcess,
|
||||
TypeService, TypeOpening, TypePackage, TypeContainer, TypeAction} {
|
||||
r := newOf(typ)
|
||||
if r == nil {
|
||||
t.Fatalf("no kind %s", typ)
|
||||
}
|
||||
if _, ok := r.(interface{ DeclaredModule() string }); !ok {
|
||||
t.Errorf("%s does not say its module", typ)
|
||||
}
|
||||
if unknown := unknownFields([]byte(`{"id":"m.x","type":"`+string(typ)+`","module":"m"}`), r); len(unknown) != 0 {
|
||||
t.Errorf("%s refuses %v", typ, unknown)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user