Builds: design 47 G A-313, A-314 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package steprun
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
|
)
|
|
|
|
type fakeOutputs struct{ m map[string][]byte }
|
|
|
|
func (f fakeOutputs) Put(name string, data []byte, _ string) (buscalls.ObjectInfo, error) {
|
|
f.m[name] = data
|
|
return buscalls.ObjectInfo{}, nil
|
|
}
|
|
func (f fakeOutputs) Get(name string) (buscalls.ObjectData, error) {
|
|
d, ok := f.m[name]
|
|
if !ok {
|
|
return buscalls.ObjectData{}, errors.New("object not found")
|
|
}
|
|
return buscalls.ObjectData{Data: d}, nil
|
|
}
|
|
|
|
// Design 47 G A-254: what a holder keeps through KeepOutputIn it reads again through ReadOutputFrom; with no store both refuse by name.
|
|
func TestOutputsKeptAreRead(t *testing.T) {
|
|
st := fakeOutputs{m: map[string][]byte{}}
|
|
if err := KeepOutputIn(st)("output.a1", []byte("x")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got, err := ReadOutputFrom(st)("output.a1"); err != nil || string(got) != "x" {
|
|
t.Fatalf("read %q, %v", got, err)
|
|
}
|
|
if _, err := ReadOutputFrom(st)("output.none"); err == nil {
|
|
t.Fatal("an absent answer was read")
|
|
}
|
|
if err := KeepOutputIn(nil)("o", nil); err == nil || !strings.Contains(err.Error(), "steps-objects") {
|
|
t.Fatalf("no store kept an answer, or did not name the steps state's objects store: %v", err)
|
|
}
|
|
if _, err := ReadOutputFrom(nil)("o"); err == nil {
|
|
t.Fatal("no store read an answer")
|
|
}
|
|
}
|