mirror of
https://github.com/kataras/iris.git
synced 2025-01-24 11:11:03 +01:00
a7b2a90e3b
Former-commit-id: 8f99121b81dc76c04d5910117885d9286873f26c
47 lines
1.1 KiB
Go
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{}{}))
|
|
|
|
}
|