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
|
return st
|
||||||
}
|
}
|
||||||
|
|
||||||
func(st *State) PutArg(input string) {
|
func(st *State) PutArg(input string) error {
|
||||||
st.Arg = &input
|
st.Arg = &input
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(st *State) PopArg() string {
|
func(st *State) PopArg() (string, error) {
|
||||||
return *st.Arg
|
if st.Arg == nil {
|
||||||
|
return "", fmt.Errorf("arg is not set")
|
||||||
|
}
|
||||||
|
return *st.Arg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(st *State) Down(input string) {
|
func(st *State) Down(input string) {
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
var dynVal = "three"
|
var dynVal = "three"
|
||||||
|
|
||||||
type TestResource struct {
|
type TestResource struct {
|
||||||
|
state *state.State
|
||||||
}
|
}
|
||||||
|
|
||||||
func getOne(input []byte, ctx context.Context) (string, error) {
|
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
|
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) {
|
func (r *TestResource) Get(sym string) (string, error) {
|
||||||
switch sym {
|
switch sym {
|
||||||
case "foo":
|
case "foo":
|
||||||
@ -70,6 +80,8 @@ func (r *TestResource) FuncFor(sym string) (resource.EntryFunc, error) {
|
|||||||
return getTwo, nil
|
return getTwo, nil
|
||||||
case "dyn":
|
case "dyn":
|
||||||
return getDyn, nil
|
return getDyn, nil
|
||||||
|
case "arg":
|
||||||
|
return r.getEachArg, nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("invalid function: '%s'", sym)
|
return nil, fmt.Errorf("invalid function: '%s'", sym)
|
||||||
}
|
}
|
||||||
@ -92,7 +104,7 @@ func TestRun(t *testing.T) {
|
|||||||
_ = r
|
_ = r
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunLoad(t *testing.T) {
|
func TestRunLoadRender(t *testing.T) {
|
||||||
st := state.NewState(5)
|
st := state.NewState(5)
|
||||||
st.Down("barbarbar")
|
st.Down("barbarbar")
|
||||||
rs := TestResource{}
|
rs := TestResource{}
|
||||||
|
Loading…
Reference in New Issue
Block a user