Add error to arg getset
This commit is contained in:
parent
5a300944c8
commit
9f9ef86b9e
@ -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) {
|
||||
|
@ -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{}
|
||||
|
Loading…
Reference in New Issue
Block a user