You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

46 lines
1.0 KiB

package container
import (
"fmt"
"reflect"
"testing"
)
func TestInstance_GetCaller(t *testing.T) {
var content = "content"
instance := Instance(reflect.ValueOf(&TestServiceImplement{content}))
caller, err := instance.GetCaller("String")
if err != nil {
t.Fatalf("意外错误:%s", err.Error())
}
result := caller([]reflect.Value{})
if len(result) != 2 {
t.Fatalf("调用器返回结果数量错误!")
}
if result[0].Interface() != content {
t.Fatalf("调用器返回内容错误!")
}
}
func TestInstance_GetCaller_EmptyMethodNameError(t *testing.T) {
_, err := serviceInstance.GetCaller("")
if err == nil {
t.Fatalf("意外的没有错误!")
}
if err.Error() != fmt.Sprintf("方法名不能为空!") {
t.Fatalf("意外错误:%s", err.Error())
}
}
func TestInstance_GetCaller_MissingMethodError(t *testing.T) {
_, err := serviceInstance.GetCaller("NoMethod")
if err == nil {
t.Fatalf("意外的没有错误!")
}
if err.Error() != fmt.Sprintf("未找到方法!") {
t.Fatalf("意外错误:%s", err.Error())
}
}