package container
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestNoSessionBrokerBuilder_New(t *testing.T) {
|
|
|
|
builder := NewNoSessionBrokerBuilder()
|
|
if builder == nil {
|
|
t.Fatalf("创建失败!")
|
|
}
|
|
}
|
|
|
|
func TestNoSessionBrokerBuilder_Check(t *testing.T) {
|
|
|
|
methodName := "String"
|
|
method, ok := testServiceType.MethodByName(methodName)
|
|
if !ok {
|
|
t.Fatalf("意外的没找到方法:%s", methodName)
|
|
}
|
|
builder := NewNoSessionBrokerBuilder()
|
|
err := builder.Check(method.Type)
|
|
if err != nil {
|
|
t.Fatalf("意外错误:%s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestNoSessionBrokerBuilder_Check_WithSession(t *testing.T) {
|
|
|
|
methodName := "StringWithSession"
|
|
method, ok := testServiceType.MethodByName(methodName)
|
|
if !ok {
|
|
t.Fatalf("意外的没找到方法:%s", methodName)
|
|
}
|
|
builder := NewNoSessionBrokerBuilder()
|
|
err := builder.Check(method.Type)
|
|
if err == nil {
|
|
t.Fatalf("意外的没有错误!")
|
|
}
|
|
if err.Error() != fmt.Sprintf("第1个参数不能是*xorm.Session") {
|
|
t.Fatalf("意外错误:%s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestNoSessionBrokerBuilder_Check_NullMethodType(t *testing.T) {
|
|
|
|
builder := NewNoSessionBrokerBuilder()
|
|
err := builder.Check(nil)
|
|
if err == nil {
|
|
t.Fatalf("意外的没有错误!")
|
|
}
|
|
if err.Error() != fmt.Sprintf("方法类型不能为空!") {
|
|
t.Fatalf("意外错误:%s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestNoSessionBrokerBuilder_Build_NullCaller(t *testing.T) {
|
|
|
|
builder := NewNoSessionBrokerBuilder()
|
|
_, err := builder.Build(nil, nil)
|
|
if err == nil {
|
|
t.Fatalf("意外的没有错误!")
|
|
}
|
|
if err.Error() != fmt.Sprintf("调用器不能为空!") {
|
|
t.Fatalf("意外错误:%s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestNoSessionBrokerBuilder_Build(t *testing.T) {
|
|
|
|
methodName := "String"
|
|
caller, err := serviceInstance.GetCaller(methodName)
|
|
if err != nil {
|
|
t.Fatalf("意外错误:%s", err.Error())
|
|
}
|
|
builder := NewNoSessionBrokerBuilder()
|
|
caller1, err := builder.Build(nil, caller)
|
|
if !CallerEqual(caller, caller1) {
|
|
t.Fatalf("调用器创建错误!")
|
|
}
|
|
}
|