diff --git a/go/state/state.go b/go/state/state.go index e6a0617..bf84f23 100644 --- a/go/state/state.go +++ b/go/state/state.go @@ -39,12 +39,16 @@ func(st State) WithCacheSize(cacheSize uint32) State { return st } -func(st *State) PutArg(input string) { +func(st *State) PutArg(input string) error { st.Arg = &input + return nil } -func(st *State) PopArg() string { - return *st.Arg +func(st *State) PopArg() (string, error) { + if st.Arg == nil { + return "", fmt.Errorf("arg is not set") + } + return *st.Arg, nil } func(st *State) Down(input string) { diff --git a/go/vm/vm_test.go b/go/vm/vm_test.go index fda715d..0c1c855 100644 --- a/go/vm/vm_test.go +++ b/go/vm/vm_test.go @@ -16,6 +16,7 @@ import ( var dynVal = "three" type TestResource struct { + state *state.State } func getOne(input []byte, ctx context.Context) (string, error) { @@ -30,6 +31,15 @@ func getDyn(input []byte, ctx context.Context) (string, error) { return dynVal, nil } +type TestStatefulResolver struct { + state *state.State +} + + +func (r *TestResource) getEachArg(input []byte, ctx context.Context) (string, error) { + return r.state.PopArg() +} + func (r *TestResource) Get(sym string) (string, error) { switch sym { case "foo": @@ -70,6 +80,8 @@ func (r *TestResource) FuncFor(sym string) (resource.EntryFunc, error) { return getTwo, nil case "dyn": return getDyn, nil + case "arg": + return r.getEachArg, nil } return nil, fmt.Errorf("invalid function: '%s'", sym) } @@ -92,7 +104,7 @@ func TestRun(t *testing.T) { _ = r } -func TestRunLoad(t *testing.T) { +func TestRunLoadRender(t *testing.T) { st := state.NewState(5) st.Down("barbarbar") rs := TestResource{}