mirror of
https://github.com/kataras/iris.git
synced 2025-12-20 03:17:04 +00:00
cm
Former-commit-id: 8f99121b81dc76c04d5910117885d9286873f26c
This commit is contained in:
46
mvc2/binder_in_service_test.go
Normal file
46
mvc2/binder_in_service_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
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{}{}))
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user