- refactor test init flow

This commit is contained in:
gazebo
2019-03-20 22:28:51 +08:00
parent 120e0dde6c
commit 15c703b469
17 changed files with 76 additions and 129 deletions

View File

@@ -5,19 +5,11 @@ import (
"testing"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/globals/beegodb"
"github.com/astaxie/beego"
"git.rosy.net.cn/jx-callback/globals/testinit"
)
func init() {
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
// beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
globals.Init()
beegodb.Init()
api.Init()
testinit.Init()
}
func TestGetQiniuUploadToken(t *testing.T) {

View File

@@ -3,19 +3,11 @@ package promotion
import (
"testing"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/globals/beegodb"
"github.com/astaxie/beego"
"git.rosy.net.cn/jx-callback/globals/testinit"
)
func init() {
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
beego.BConfig.RunMode = "alpha" // InitBeegoBeforeTest会将runmode设置为test
globals.Init()
beegodb.Init()
api.Init()
testinit.Init()
}
func TestCreateLocalPromotionFromRemote(t *testing.T) {

View File

@@ -4,9 +4,7 @@ import (
"testing"
"git.rosy.net.cn/jx-callback/business/jxutils/cache"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/beegodb"
"github.com/astaxie/beego"
"git.rosy.net.cn/jx-callback/globals/testinit0"
)
var (
@@ -14,15 +12,7 @@ var (
)
func init() {
//E:/goprojects/src/git.rosy.net.cn/jx-callback/conf/app.conf
///Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
globals.Init()
beegodb.Init()
// api.Init()
testinit0.Init()
cacher = New("localhost", 6379, "")
}

View File

@@ -11,18 +11,11 @@ import (
"git.rosy.net.cn/jx-callback/business/model"
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/globals/beegodb"
"github.com/astaxie/beego"
"git.rosy.net.cn/jx-callback/globals/testinit"
)
func init() {
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
// beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
globals.Init()
beegodb.Init()
api.Init()
testinit.Init()
}
func TestScope(t *testing.T) {

View File

@@ -6,18 +6,11 @@ import (
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/globals/beegodb"
"github.com/astaxie/beego"
"git.rosy.net.cn/jx-callback/globals/testinit"
)
func init() {
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
// beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
globals.Init()
beegodb.Init()
api.Init()
testinit.Init()
}
func TestSelectEntities(t *testing.T) {

View File

@@ -0,0 +1,16 @@
package dao
import (
"testing"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/globals"
)
func TestGetStoreDetail(t *testing.T) {
storeDetail, err := GetStoreDetailByVendorStoreID(GetDB(), "11733077", 0)
if err != nil {
t.Fatal(err)
}
globals.SugarLogger.Debug(utils.Format4Output(storeDetail, false))
}

View File

@@ -7,19 +7,11 @@ import (
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/globals/beegodb"
"github.com/astaxie/beego"
"git.rosy.net.cn/jx-callback/globals/testinit"
)
func init() {
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
globals.Init()
beegodb.Init()
api.Init()
testinit.Init()
}
func TestCreateWaybill(t *testing.T) {

View File

@@ -6,19 +6,11 @@ import (
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/globals/beegodb"
"github.com/astaxie/beego"
"git.rosy.net.cn/jx-callback/globals/testinit"
)
func init() {
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
globals.Init()
beegodb.Init()
api.Init()
testinit.Init()
}
func TestCreateWaybill(t *testing.T) {

View File

@@ -2,10 +2,7 @@ package ebai
import (
_ "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/globals/beegodb"
"github.com/astaxie/beego"
"git.rosy.net.cn/jx-callback/globals/testinit"
)
const (
@@ -14,10 +11,5 @@ const (
)
func init() {
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
globals.Init()
beegodb.Init()
api.Init()
testinit.Init()
}

View File

@@ -4,21 +4,11 @@ import (
"testing"
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/globals/beegodb"
"github.com/astaxie/beego"
"git.rosy.net.cn/jx-callback/globals/testinit"
)
func init() {
//E:/goprojects/src/git.rosy.net.cn/jx-callback/conf/app.conf
///Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
globals.Init()
beegodb.Init()
api.Init()
testinit.Init()
}
func TestGetOrder(t *testing.T) {

View File

@@ -6,19 +6,11 @@ import (
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/globals/beegodb"
"github.com/astaxie/beego"
"git.rosy.net.cn/jx-callback/globals/testinit"
)
func init() {
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
// beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
globals.Init()
beegodb.Init()
api.Init()
testinit.Init()
}
func TestSwitch2SelfDeliver(t *testing.T) {

View File

@@ -5,19 +5,11 @@ import (
"git.rosy.net.cn/baseapi/utils"
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/globals/beegodb"
"github.com/astaxie/beego"
"git.rosy.net.cn/jx-callback/globals/testinit"
)
func init() {
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
// beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
globals.Init()
beegodb.Init()
api.Init()
testinit.Init()
}
func TestGetVendorCategories(t *testing.T) {

View File

@@ -6,20 +6,11 @@ import (
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils/tasks"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/globals/beegodb"
"github.com/astaxie/beego"
"git.rosy.net.cn/jx-callback/globals/testinit"
)
func init() {
//E:/goprojects/src/git.rosy.net.cn/jx-callback/conf/app.conf
///Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
globals.Init()
beegodb.Init()
api.Init()
testinit.Init()
if err := tasks.RefreshWeimobToken(); err != nil {
globals.SugarLogger.Errorf("RefreshWeimobToken failed with error:%s", err)

View File

@@ -43,13 +43,10 @@ func init() {
logger, _ := zap.NewDevelopment()
SugarLogger = logger.Sugar()
baseapi.Init(SugarLogger)
// todo 这里只是临时把这个放这里不然在其它引用globals的地方会导致得不到正确的值
// 但放这里又会导致单元测试的配置不正确,找不到配置文件
Init()
}
func Init() {
SugarLogger.Infof("globals RunMode=%s", beego.BConfig.RunMode)
ReallyCallPlatformAPI = (beego.BConfig.RunMode != "dev" && beego.BConfig.RunMode != "test")
ReallySendWeixinMsg = ReallyCallPlatformAPI && beego.BConfig.RunMode == "prod"
ReallyReplyComment = ReallyCallPlatformAPI && beego.BConfig.RunMode == "prod"

View File

@@ -0,0 +1,11 @@
package testinit
import (
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/globals/testinit1"
)
func Init() {
testinit1.Init()
api.Init()
}

View File

@@ -0,0 +1,22 @@
package testinit1
import (
"path/filepath"
"runtime"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/beegodb"
"github.com/astaxie/beego"
)
func Init() {
_, file, _, _ := runtime.Caller(0)
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator)+".."+string(filepath.Separator))))
beego.TestBeegoInit(apppath)
globals.SugarLogger.Infof("testinit RunMode=%s", beego.BConfig.RunMode)
beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
globals.Init()
beegodb.Init()
}

View File

@@ -32,10 +32,10 @@ var (
)
func Init() {
// globals.Init()
globals.Init()
beegodb.Init()
defsch.Init()
api.Init()
defsch.Init()
buildTime, err := time.ParseInLocation(time.RFC3339, BuildDate, time.UTC)
if err == nil {
buildTime = buildTime.Local()