- refactor test init flow
This commit is contained in:
@@ -5,19 +5,11 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
testinit.Init()
|
||||||
// beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
|
|
||||||
|
|
||||||
globals.Init()
|
|
||||||
beegodb.Init()
|
|
||||||
api.Init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetQiniuUploadToken(t *testing.T) {
|
func TestGetQiniuUploadToken(t *testing.T) {
|
||||||
|
|||||||
@@ -3,19 +3,11 @@ package promotion
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
testinit.Init()
|
||||||
beego.BConfig.RunMode = "alpha" // InitBeegoBeforeTest会将runmode设置为test
|
|
||||||
|
|
||||||
globals.Init()
|
|
||||||
beegodb.Init()
|
|
||||||
api.Init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateLocalPromotionFromRemote(t *testing.T) {
|
func TestCreateLocalPromotionFromRemote(t *testing.T) {
|
||||||
|
|||||||
14
business/jxutils/cache/redis/redis_test.go
vendored
14
business/jxutils/cache/redis/redis_test.go
vendored
@@ -4,9 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/cache"
|
"git.rosy.net.cn/jx-callback/business/jxutils/cache"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals/testinit0"
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -14,15 +12,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
//E:/goprojects/src/git.rosy.net.cn/jx-callback/conf/app.conf
|
testinit0.Init()
|
||||||
///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()
|
|
||||||
|
|
||||||
cacher = New("localhost", 6379, "")
|
cacher = New("localhost", 6379, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,18 +11,11 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
testinit.Init()
|
||||||
// beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
|
|
||||||
|
|
||||||
globals.Init()
|
|
||||||
beegodb.Init()
|
|
||||||
api.Init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestScope(t *testing.T) {
|
func TestScope(t *testing.T) {
|
||||||
|
|||||||
@@ -6,18 +6,11 @@ import (
|
|||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
testinit.Init()
|
||||||
// beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
|
|
||||||
|
|
||||||
globals.Init()
|
|
||||||
beegodb.Init()
|
|
||||||
api.Init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSelectEntities(t *testing.T) {
|
func TestSelectEntities(t *testing.T) {
|
||||||
|
|||||||
16
business/model/dao/store_test.go
Normal file
16
business/model/dao/store_test.go
Normal 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))
|
||||||
|
}
|
||||||
@@ -7,19 +7,11 @@ import (
|
|||||||
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner"
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
testinit.Init()
|
||||||
beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
|
|
||||||
|
|
||||||
globals.Init()
|
|
||||||
beegodb.Init()
|
|
||||||
api.Init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateWaybill(t *testing.T) {
|
func TestCreateWaybill(t *testing.T) {
|
||||||
|
|||||||
@@ -6,19 +6,11 @@ import (
|
|||||||
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner"
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
testinit.Init()
|
||||||
beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
|
|
||||||
|
|
||||||
globals.Init()
|
|
||||||
beegodb.Init()
|
|
||||||
api.Init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateWaybill(t *testing.T) {
|
func TestCreateWaybill(t *testing.T) {
|
||||||
|
|||||||
@@ -2,10 +2,7 @@ package ebai
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
_ "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch"
|
_ "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -14,10 +11,5 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
testinit.Init()
|
||||||
beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
|
|
||||||
|
|
||||||
globals.Init()
|
|
||||||
beegodb.Init()
|
|
||||||
api.Init()
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,21 +4,11 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
//E:/goprojects/src/git.rosy.net.cn/jx-callback/conf/app.conf
|
testinit.Init()
|
||||||
///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()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetOrder(t *testing.T) {
|
func TestGetOrder(t *testing.T) {
|
||||||
|
|||||||
@@ -6,19 +6,11 @@ import (
|
|||||||
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner"
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
testinit.Init()
|
||||||
// beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
|
|
||||||
|
|
||||||
globals.Init()
|
|
||||||
beegodb.Init()
|
|
||||||
api.Init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSwitch2SelfDeliver(t *testing.T) {
|
func TestSwitch2SelfDeliver(t *testing.T) {
|
||||||
|
|||||||
@@ -5,19 +5,11 @@ import (
|
|||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
testinit.Init()
|
||||||
// beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
|
|
||||||
|
|
||||||
globals.Init()
|
|
||||||
beegodb.Init()
|
|
||||||
api.Init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetVendorCategories(t *testing.T) {
|
func TestGetVendorCategories(t *testing.T) {
|
||||||
|
|||||||
@@ -6,20 +6,11 @@ import (
|
|||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasks"
|
"git.rosy.net.cn/jx-callback/business/jxutils/tasks"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
|
||||||
"github.com/astaxie/beego"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
//E:/goprojects/src/git.rosy.net.cn/jx-callback/conf/app.conf
|
testinit.Init()
|
||||||
///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()
|
|
||||||
|
|
||||||
if err := tasks.RefreshWeimobToken(); err != nil {
|
if err := tasks.RefreshWeimobToken(); err != nil {
|
||||||
globals.SugarLogger.Errorf("RefreshWeimobToken failed with error:%s", err)
|
globals.SugarLogger.Errorf("RefreshWeimobToken failed with error:%s", err)
|
||||||
|
|||||||
@@ -43,13 +43,10 @@ func init() {
|
|||||||
logger, _ := zap.NewDevelopment()
|
logger, _ := zap.NewDevelopment()
|
||||||
SugarLogger = logger.Sugar()
|
SugarLogger = logger.Sugar()
|
||||||
baseapi.Init(SugarLogger)
|
baseapi.Init(SugarLogger)
|
||||||
|
|
||||||
// todo 这里只是临时把这个放这里,不然在其它引用globals的地方会导致得不到正确的值
|
|
||||||
// 但放这里又会导致单元测试的配置不正确,找不到配置文件
|
|
||||||
Init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
|
SugarLogger.Infof("globals RunMode=%s", beego.BConfig.RunMode)
|
||||||
ReallyCallPlatformAPI = (beego.BConfig.RunMode != "dev" && beego.BConfig.RunMode != "test")
|
ReallyCallPlatformAPI = (beego.BConfig.RunMode != "dev" && beego.BConfig.RunMode != "test")
|
||||||
ReallySendWeixinMsg = ReallyCallPlatformAPI && beego.BConfig.RunMode == "prod"
|
ReallySendWeixinMsg = ReallyCallPlatformAPI && beego.BConfig.RunMode == "prod"
|
||||||
ReallyReplyComment = ReallyCallPlatformAPI && beego.BConfig.RunMode == "prod"
|
ReallyReplyComment = ReallyCallPlatformAPI && beego.BConfig.RunMode == "prod"
|
||||||
|
|||||||
11
globals/testinit/testinit.go
Normal file
11
globals/testinit/testinit.go
Normal 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()
|
||||||
|
}
|
||||||
22
globals/testinit1/testinit1.go
Normal file
22
globals/testinit1/testinit1.go
Normal 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()
|
||||||
|
}
|
||||||
4
main.go
4
main.go
@@ -32,10 +32,10 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
// globals.Init()
|
globals.Init()
|
||||||
beegodb.Init()
|
beegodb.Init()
|
||||||
defsch.Init()
|
|
||||||
api.Init()
|
api.Init()
|
||||||
|
defsch.Init()
|
||||||
buildTime, err := time.ParseInLocation(time.RFC3339, BuildDate, time.UTC)
|
buildTime, err := time.ParseInLocation(time.RFC3339, BuildDate, time.UTC)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
buildTime = buildTime.Local()
|
buildTime = buildTime.Local()
|
||||||
|
|||||||
Reference in New Issue
Block a user