The node-engine held 1,707 top-level unit tests against the budget of 500 a module. Each unit test file with two or more tests now runs them as subtests of one test named for the file, each named as its function was, in the same order: every check is kept, and the check counts 383. Files with a TestMain, a re-run of a test by its name, or the integration tag are left. Four files of this branch's earlier commits are formatted. Builds: design 47 H2 §819; H-A-349 DQ-14
51 lines
2.1 KiB
Go
51 lines
2.1 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)
|
|
}
|
|
}
|
|
|
|
// TestContract runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
|
func TestContract(t *testing.T) {
|
|
t.Run("TheRuntimeIsAskedByItsNameAndThisMachines", testTheRuntimeIsAskedByItsNameAndThisMachines)
|
|
t.Run("OnlyTheCoreProcessIsJudgedByDefault", testOnlyTheCoreProcessIsJudgedByDefault)
|
|
t.Run("AVerdictNamesItsComponent", testAVerdictNamesItsComponent)
|
|
}
|