39 lines
1.6 KiB
Go
39 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/declaration"
|
|
"github.com/novox/mesh-host/internal/apply"
|
|
)
|
|
|
|
// 1132/AC1, AC3: the report carries one fact per module the declaration names, with the build the controller sent for
|
|
// it; a module not yet taken on an adopted node is not one.
|
|
func TestTheReportCarriesOneFactPerModuleWithItsBuild(t *testing.T) {
|
|
d, err := declaration.Parse([]byte(`{"declaration":1,"builds":{"a":"b-1","b":"b-2"},"resources":[
|
|
{"id":"a.dir","type":"directory","path":"/srv/a","module":"a"},
|
|
{"id":"b.dir","type":"directory","path":"/srv/b","module":"b"}]}`))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
failure := &apply.Error{Resource: "b.dir", Err: errors.New("no space"), Failures: []apply.Failure{{Resource: "b.dir", Err: errors.New("no space")}}}
|
|
facts := moduleFacts(d, apply.Report{}, failure)
|
|
if len(facts) != 2 || facts[0].Module != "a" || facts[0].Build != "b-1" || facts[0].Failed ||
|
|
facts[1].Module != "b" || facts[1].Build != "b-2" || !facts[1].Failed || facts[1].Detail == "" {
|
|
t.Fatalf("facts %+v", facts)
|
|
}
|
|
adopted, err := declaration.Parse([]byte(`{"declaration":1,"adoption":{"taken":["a"],"untaken":{"b":["b.dir"]}},"resources":[
|
|
{"id":"a.dir","type":"directory","path":"/srv/a","module":"a"},
|
|
{"id":"b.dir","type":"directory","path":"/srv/b","module":"b"}]}`))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if facts := moduleFacts(adopted, apply.Report{}, nil); len(facts) != 1 || facts[0].Module != "a" {
|
|
t.Fatalf("an untaken module is a fact: %+v", facts)
|
|
}
|
|
if moduleFacts(nil, apply.Report{}, nil) != nil {
|
|
t.Fatal("facts without a declaration")
|
|
}
|
|
}
|