package container
|
|
|
|
import (
|
|
"github.com/go-xorm/xorm"
|
|
"testing"
|
|
)
|
|
|
|
func TestTransactionHandlerFactory_New(t *testing.T) {
|
|
|
|
engine := &xorm.Engine{}
|
|
transactionHandlerFactory, err := NewTransactionHandlerFactory(engine)
|
|
if err != nil {
|
|
t.Fatalf("意外错误:%s", err.Error())
|
|
}
|
|
if transactionHandlerFactory == nil {
|
|
t.Fatalf("创建失败!")
|
|
}
|
|
defaultTransactionHandlerFactory, ok := transactionHandlerFactory.(*DefaultTransactionHandlerFactory)
|
|
if !ok {
|
|
t.Fatalf("会话管理器类型不正确!")
|
|
}
|
|
if defaultTransactionHandlerFactory.engine != engine {
|
|
t.Fatalf("xorm.Engine设置错误!")
|
|
}
|
|
}
|
|
|
|
func TestTransactionHandlerFactory_New_NullEngine(t *testing.T) {
|
|
|
|
_, err := NewTransactionHandlerFactory(nil)
|
|
if err == nil {
|
|
t.Fatalf("意外的没有错误!")
|
|
}
|
|
if err.Error() != "xorm.Engine不能为空!" {
|
|
t.Fatalf("意外错误:%s", err.Error())
|
|
}
|
|
}
|