test dynfunc package; standardize and refactor api #14

Merged
xdrm-brackets merged 19 commits from test/dynamic into 0.3.0 2020-04-04 10:09:20 +00:00
3 changed files with 8 additions and 2 deletions
Showing only changes of commit 8fa18cd61b - Show all commits

View File

@ -17,6 +17,9 @@ const ErrNoServiceForHandler = cerr("no service found for this handler")
// ErrMissingHandlerArgumentParam - missing params arguments for handler // ErrMissingHandlerArgumentParam - missing params arguments for handler
const ErrMissingHandlerArgumentParam = cerr("missing handler argument : parameter struct") const ErrMissingHandlerArgumentParam = cerr("missing handler argument : parameter struct")
// ErrUnexpectedInput - input argument is not expected
const ErrUnexpectedInput = cerr("unexpected input struct")
// ErrMissingHandlerOutput - missing output for handler // ErrMissingHandlerOutput - missing output for handler
const ErrMissingHandlerOutput = cerr("handler must have at least 1 output") const ErrMissingHandlerOutput = cerr("handler must have at least 1 output")

View File

@ -44,6 +44,9 @@ func (s spec) checkInput(fnv reflect.Value) error {
// no input -> ok // no input -> ok
if len(s.Input) == 0 { if len(s.Input) == 0 {
if fnt.NumIn() > 0 {
return ErrUnexpectedInput
}
return nil return nil
} }

View File

@ -21,11 +21,11 @@ func TestInputCheck(t *testing.T) {
Fn: func() {}, Fn: func() {},
Err: nil, Err: nil,
}, },
// func can have any arguments if not specified // func must have noarguments if none specified
{ {
Input: map[string]reflect.Type{}, Input: map[string]reflect.Type{},
Fn: func(int, string) {}, Fn: func(int, string) {},
Err: nil, Err: ErrUnexpectedInput,
}, },
// missing input struct in func // missing input struct in func
{ {