controllogic: add Graph.StateVars declarations (persisted via store JSON)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package controllogic
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestStoreRoundTripStateVars(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
st, err := NewStore(dir) // NewStore takes the storage DIRECTORY
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
g := Graph{
|
||||
ID: "g1",
|
||||
Name: "with-vars",
|
||||
StateVars: []StateVar{
|
||||
{Name: "count", Type: "number", Initial: "0"},
|
||||
{Name: "buf", Type: "array", Initial: "[1,2]", Elem: "number", Sizing: "capped", Capacity: 5},
|
||||
},
|
||||
}
|
||||
if err := st.Save(g); err != nil { // Save returns only error
|
||||
t.Fatal(err)
|
||||
}
|
||||
st2, err := NewStore(dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := st2.Get("g1") // Get returns (Graph, error); ErrNotFound if absent
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(got.StateVars) != 2 || got.StateVars[1].Name != "buf" || got.StateVars[1].Capacity != 5 {
|
||||
t.Fatalf("statevars not round-tripped: %#v", got.StateVars)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user