package steprun import ( "errors" "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 KeepOutputIn(nil)("o", nil) == nil { t.Fatal("no store kept an answer") } if _, err := ReadOutputFrom(nil)("o"); err == nil { t.Fatal("no store read an answer") } }