iris/mvc2/binder_in_service_test.go
kataras a7b2a90e3b cm
Former-commit-id: 8f99121b81dc76c04d5910117885d9286873f26c
2017-12-04 05:08:05 +02:00

47 lines
1.1 KiB
Go

package mvc2
import (
"reflect"
"testing"
)
type (
testService interface {
say(string)
}
testServiceImpl struct {
prefix string
}
)
func (s *testServiceImpl) say(message string) string {
return s.prefix + ": " + message
}
func TestMakeServiceInputBinder(t *testing.T) {
expectedService := &testServiceImpl{"say"}
b := MustMakeServiceInputBinder(expectedService)
// in
var (
intType = reflect.TypeOf(1)
availableBinders = []*InputBinder{b}
)
// 1
testCheck(t, "test1", true, testGetBindersForInput(t, availableBinders,
[]interface{}{expectedService}, reflect.TypeOf(expectedService)))
// 2
testCheck(t, "test2-fail", false, testGetBindersForInput(t, availableBinders,
[]interface{}{42}))
// 3
testCheck(t, "test3-fail", false, testGetBindersForInput(t, availableBinders,
[]interface{}{42}, intType))
// 4
testCheck(t, "test4-fail", false, testGetBindersForInput(t, availableBinders,
[]interface{}{42}))
// 5 - check if nothing passed, so no valid binders at all.
testCheck(t, "test5", true, testGetBindersForInput(t, availableBinders,
[]interface{}{}))
}