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
74 lines
2.5 KiB
Go
74 lines
2.5 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// The subject the engine hears for a store settling is the event its manifest consumes: the grants part grants an account
|
|
// what its manifest consumes and nothing named in code (novox/hq ADR 0625 §4).
|
|
func testTheSettledEventIsTheManifestsConsume(t *testing.T) {
|
|
raw, err := os.ReadFile("../../module.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var m struct {
|
|
Consumes []string `json:"consumes"`
|
|
}
|
|
if err := json.Unmarshal(raw, &m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
emitter, event, _ := strings.Cut(strings.TrimPrefix(settledEvent, "mesh.mod."), ".event.")
|
|
if !slices.Contains(m.Consumes, emitter+"."+event) {
|
|
t.Errorf("the engine hears %s, its manifest consumes %v", settledEvent, m.Consumes)
|
|
}
|
|
}
|
|
|
|
// The manifest claims the seat node-engine, says its findings on its own stream and hears the keeper's ask and the
|
|
// node-engine seat's running (design 47 G §364, §387, §199).
|
|
func testTheManifestClaimsItsSeatAndSaysItsFindings(t *testing.T) {
|
|
raw, err := os.ReadFile("../../module.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var m struct {
|
|
Version string `json:"version"`
|
|
Consumes []string `json:"consumes"`
|
|
Claims []struct {
|
|
Name string `json:"name"`
|
|
Scope string `json:"scope"`
|
|
} `json:"claims"`
|
|
Streams []struct {
|
|
Name string `json:"name"`
|
|
Events []string `json:"events"`
|
|
} `json:"streams"`
|
|
}
|
|
if err := json.Unmarshal(raw, &m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(m.Claims) != 1 || m.Claims[0].Name != "node-engine" || m.Claims[0].Scope != "node" {
|
|
t.Errorf("claims = %+v, want the node seat node-engine", m.Claims)
|
|
}
|
|
if len(m.Streams) != 1 || m.Streams[0].Name != "mesh-host-findings" ||
|
|
!slices.Equal(m.Streams[0].Events, []string{"finding-written.*", "finding-cleared.*", "findings-stated.*"}) {
|
|
t.Errorf("streams = %+v, want mesh-host-findings with the three finding events", m.Streams)
|
|
}
|
|
for _, c := range []string{"mesh-conditions.findings-asked", "node-engine.running"} {
|
|
if !slices.Contains(m.Consumes, c) {
|
|
t.Errorf("consumes %v lacks %s", m.Consumes, c)
|
|
}
|
|
}
|
|
if m.Version != "0.1" {
|
|
t.Errorf("version = %q, want MAJOR.MINOR 0.1 (§368, §411)", m.Version)
|
|
}
|
|
}
|
|
|
|
// TestSettledManifest runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
|
func TestSettledManifest(t *testing.T) {
|
|
t.Run("TheSettledEventIsTheManifestsConsume", testTheSettledEventIsTheManifestsConsume)
|
|
t.Run("TheManifestClaimsItsSeatAndSaysItsFindings", testTheManifestClaimsItsSeatAndSaysItsFindings)
|
|
}
|