44 lines
1.7 KiB
Go
44 lines
1.7 KiB
Go
package witness
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/novox/mesh-host/internal/link"
|
|
)
|
|
|
|
// The contract, held (novox/hq to-be 45 §8).
|
|
|
|
// The runtime is asked by its own name and this machine's: only this machine's runtime can answer.
|
|
func TestTheRuntimeIsAskedByItsNameAndThisMachines(t *testing.T) {
|
|
if got := link.PingSubject("runner-x", "anchor"); got != "$SRV.PING.runner-x.anchor" {
|
|
t.Fatalf("the host asks %s; the runtime answers $SRV.PING.node-tools.<node>", got)
|
|
}
|
|
}
|
|
|
|
// What is judged by default is the mesh's core process on every machine, by the name it is composed under, and
|
|
// nothing else: the controller ended (issue 1126), so its name is judged as any other.
|
|
func TestOnlyTheCoreProcessIsJudgedByDefault(t *testing.T) {
|
|
// The tool runner's process by its id and name, whatever its module is called (ADR 0601 §4); a process named so by
|
|
// another id, or another process, is not.
|
|
for id, want := range map[string]string{"runner-x.runtime": ByPing, "node-tools.runtime": ByNone, "runner-x.server": ByNone,
|
|
"mesh-controller.runtime": ByNone} {
|
|
if got := Default(id, "runner-x"); got != want {
|
|
t.Errorf("%s is judged by %q, want %q", id, got, want)
|
|
}
|
|
}
|
|
if NodeToolsWithin != 60*time.Second || PingWithin != 5*time.Second {
|
|
t.Fatal("the bounds are to-be 45 §8's: the runtime within sixty seconds, a PING answered within five")
|
|
}
|
|
}
|
|
|
|
// A verdict on the wire names its component as the controller's condition does.
|
|
func TestAVerdictNamesItsComponent(t *testing.T) {
|
|
raw, _ := json.Marshal(link.Rollback{Component: Component(ByPing), Outcome: link.RolledBack})
|
|
if !strings.Contains(string(raw), `"component":"node-tools"`) {
|
|
t.Fatalf("a verdict names its component as %s", raw)
|
|
}
|
|
}
|