Files
mesh-sdk/go/views/contract_fake_test.go
T
jschoubben 3a438786e3 G V-8: the finding writer takes the generated finding type through views.FindingBody and exports CheckFinding
views.FindingBody becomes the interface of the accessors the seat generator emits
(Kind/SetKind per field, one Subject/SetSubject pair); the writer is given the contract's
constructors of the finding, finding-cleared, findings-stated and findings-asked bodies and
holds none of their layouts. WriterFindings takes only the constructor and lays the views
reader's four findings out itself (scope module, id escaped, urgent for view-too-large,
source views, subject the module on its node). views.CheckFinding(b) error is the one check
of the key's parts, the kind and the owner and waiting-on forms, run before every write.

Builds: design 47 G §686, §687, §689, §640, §688, A-1 (.work/47-G/dev2-ledger.md)
Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
2026-11-11 21:33:23 +01:00

127 lines
4.7 KiB
Go

package views_test
import (
"time"
"git.novox.be/novox/mesh-sdk/go/views"
)
// The test's own stand-in for the types the seat generator emits for the seat `mesh-conditions` (design 47 G §686,
// §640): mesh-sdk keeps no such layout, so the writer's tests bring one, with the accessors the generator emits.
type testSubject struct {
Also []string `json:"also,omitempty"`
ID string `json:"id"`
Machine string `json:"machine,omitempty"`
Scope string `json:"scope"`
}
type testFinding struct {
AtVal time.Time `json:"at"`
Explanation string `json:"explanation,omitempty"`
HeadlineVal string `json:"headline,omitempty"`
IDField string `json:"id"`
KindField string `json:"kind"`
ObserverVal string `json:"observer"`
Owner string `json:"owner,omitempty"`
Run string `json:"run,omitempty"`
ScopeField string `json:"scope"`
SeverityVal string `json:"severity"`
SinceVal time.Time `json:"since"`
SourceVal string `json:"source"`
SubjectVal testSubject `json:"subject"`
SummaryVal string `json:"summary"`
WaitingOn string `json:"waiting-on,omitempty"`
}
var _ views.FindingBody = (*testFinding)(nil)
func (f *testFinding) Kind() string { return f.KindField }
func (f *testFinding) SetKind(v string) { f.KindField = v }
func (f *testFinding) Scope() string { return f.ScopeField }
func (f *testFinding) SetScope(v string) { f.ScopeField = v }
func (f *testFinding) ID() string { return f.IDField }
func (f *testFinding) SetID(v string) { f.IDField = v }
func (f *testFinding) At() time.Time { return f.AtVal }
func (f *testFinding) Since() time.Time { return f.SinceVal }
func (f *testFinding) SetSince(v time.Time) { f.SinceVal = v }
func (f *testFinding) Severity() string { return f.SeverityVal }
func (f *testFinding) SetSeverity(v string) { f.SeverityVal = v }
func (f *testFinding) Summary() string { return f.SummaryVal }
func (f *testFinding) SetSummary(v string) { f.SummaryVal = v }
func (f *testFinding) Headline() string { return f.HeadlineVal }
func (f *testFinding) SetHeadline(v string) { f.HeadlineVal = v }
func (f *testFinding) Source() string { return f.SourceVal }
func (f *testFinding) SetSource(v string) { f.SourceVal = v }
func (f *testFinding) Observer() string { return f.ObserverVal }
func (f *testFinding) SetObserver(v string) { f.ObserverVal = v }
func (f *testFinding) SetAt(v time.Time) { f.AtVal = v }
func (f *testFinding) SetSubject(a []string, id, m, s string) {
f.SubjectVal = testSubject{Also: a, ID: id, Machine: m, Scope: s}
}
func (f *testFinding) Subject() ([]string, string, string, string) {
return f.SubjectVal.Also, f.SubjectVal.ID, f.SubjectVal.Machine, f.SubjectVal.Scope
}
type testCleared struct {
At time.Time `json:"at"`
ID string `json:"id"`
Kind string `json:"kind"`
Scope string `json:"scope"`
Why string `json:"why"`
}
func (c *testCleared) SetKind(v string) { c.Kind = v }
func (c *testCleared) SetScope(v string) { c.Scope = v }
func (c *testCleared) SetID(v string) { c.ID = v }
func (c *testCleared) SetAt(v time.Time) { c.At = v }
func (c *testCleared) SetWhy(v string) { c.Why = v }
type testPending struct {
Bound string `json:"bound"`
Key string `json:"key"`
Since time.Time `json:"since"`
}
type testStated struct {
Asked string `json:"asked,omitempty"`
At time.Time `json:"at"`
Findings []testFinding `json:"findings"`
Kinds []string `json:"kinds,omitempty"`
Pending []testPending `json:"pending"`
}
func newTestStated() *testStated {
return &testStated{Findings: []testFinding{}, Pending: []testPending{}}
}
func (s *testStated) SetAt(v time.Time) { s.At = v }
func (s *testStated) SetAsked(v string) { s.Asked = v }
func (s *testStated) SetKinds(v []string) { s.Kinds = v }
func (s *testStated) AddFinding(b views.FindingBody) {
s.Findings = append(s.Findings, *b.(*testFinding))
}
func (s *testStated) AddPending(k string, since time.Time, bound string) {
s.Pending = append(s.Pending, testPending{Bound: bound, Key: k, Since: since})
}
type testAsked struct {
AskID string `json:"ask"`
Mod string `json:"module,omitempty"`
}
func (a *testAsked) Ask() string { return a.AskID }
func (a *testAsked) Module() string { return a.Mod }
var bodies = struct {
NewFinding func() views.FindingBody
NewCleared func() views.ClearedBody
NewStated func() views.StatedBody
NewAsked func() views.AskedBody
}{
func() views.FindingBody { return &testFinding{} },
func() views.ClearedBody { return &testCleared{} },
func() views.StatedBody { return newTestStated() },
func() views.AskedBody { return &testAsked{} },
}