36 lines
1.2 KiB
Go
36 lines
1.2 KiB
Go
package inventory
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/novox/mesh-controller/internal/chain"
|
|
)
|
|
|
|
// The first read of a chain that requires the layout lays the builds out itself when it may write, instead of refusing
|
|
// the controller's own start (issue 1121, 2026-10-18: the controller exited every five seconds).
|
|
func TestTheFirstReadOfAChainNotLaidOutLaysItOut(t *testing.T) {
|
|
ctx := context.Background()
|
|
inv, c := anInventoryOnTheChain(t)
|
|
inv.RequireLayout()
|
|
if _, found, _ := c.Builds.GetRaw(ctx, chain.LayoutMarkerKey); found {
|
|
t.Fatal("a fresh chain holds the marker already; the test proves nothing")
|
|
}
|
|
if _, err := inv.theChain(ctx); err != nil {
|
|
t.Fatalf("the first read was refused: %v", err)
|
|
}
|
|
if _, found, err := c.Builds.GetRaw(ctx, chain.LayoutMarkerKey); err != nil || !found {
|
|
t.Fatalf("the read did not lay the builds out: found %v, %v", found, err)
|
|
}
|
|
}
|
|
|
|
// anInventoryOnTheChain is an inventory with no store and a chain in memory: the chain's own paths, which never reach the
|
|
// store.
|
|
func anInventoryOnTheChain(t *testing.T) (*Inventory, *chain.Chain) {
|
|
t.Helper()
|
|
c := chain.InMemory(nil)
|
|
inv := &Inventory{state: &chainState{}}
|
|
inv.UseChain(c)
|
|
return inv, c
|
|
}
|