调整单元测试
This commit is contained in:
parent
30852f481c
commit
7917f1fcae
7 changed files with 50 additions and 48 deletions
2
Makefile
2
Makefile
|
|
@ -5,7 +5,7 @@ VETPACKAGES ?= $(shell $(GO) list ./... | grep -v /examples/)
|
||||||
GOFILES := $(shell find . -name "*.go")
|
GOFILES := $(shell find . -name "*.go")
|
||||||
|
|
||||||
# ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
# ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
||||||
TESTFOLDER := $(shell $(GO) list ./... | grep -E './xiang$$' | grep -v examples)
|
TESTFOLDER := $(shell $(GO) list ./... | grep -E 'xiang$$|global$$' | grep -v examples)
|
||||||
TESTTAGS ?= ""
|
TESTTAGS ?= ""
|
||||||
|
|
||||||
# 运行单元测试
|
# 运行单元测试
|
||||||
|
|
|
||||||
14
cmd/help.go
Normal file
14
cmd/help.go
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var helpCmd = &cobra.Command{
|
||||||
|
Use: "help",
|
||||||
|
Short: "显示命令帮助文档",
|
||||||
|
Long: `显示命令帮助文档`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
cmd.Help()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
@ -12,6 +12,9 @@ var rootCmd = &cobra.Command{
|
||||||
Short: "象传应用引擎命令行工具",
|
Short: "象传应用引擎命令行工具",
|
||||||
Long: `象传应用引擎命令行工具`,
|
Long: `象传应用引擎命令行工具`,
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
|
CompletionOptions: cobra.CompletionOptions{
|
||||||
|
DisableDefaultCmd: true,
|
||||||
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
fmt.Fprintln(os.Stderr, "参数错误", args)
|
fmt.Fprintln(os.Stderr, "参数错误", args)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
@ -27,6 +30,9 @@ func init() {
|
||||||
infoCmd,
|
infoCmd,
|
||||||
startCmd,
|
startCmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
rootCmd.SetHelpCommand(helpCmd)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute 运行Root
|
// Execute 运行Root
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package global
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -7,11 +7,10 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/yaoapp/kun/any"
|
"github.com/yaoapp/kun/any"
|
||||||
"github.com/yaoapp/xiang/global"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewConfig(t *testing.T) {
|
func TestNewConfig(t *testing.T) {
|
||||||
cfg := global.NewConfig()
|
cfg := NewConfig()
|
||||||
var vBool = func(name string) bool {
|
var vBool = func(name string) bool {
|
||||||
if name == "true" || name == "1" {
|
if name == "true" || name == "1" {
|
||||||
return true
|
return true
|
||||||
21
global/init_test.go
Normal file
21
global/init_test.go
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
package global
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/yaoapp/gou"
|
||||||
|
)
|
||||||
|
|
||||||
|
var cfg Config
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
|
||||||
|
// Run test suites
|
||||||
|
exitVal := m.Run()
|
||||||
|
|
||||||
|
// we can do clean up code here
|
||||||
|
gou.KillPlugins()
|
||||||
|
|
||||||
|
os.Exit(exitVal)
|
||||||
|
}
|
||||||
|
|
@ -1,24 +1,23 @@
|
||||||
package main
|
package global
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/yaoapp/xiang/global"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoad(t *testing.T) {
|
func TestLoad(t *testing.T) {
|
||||||
assert.NotPanics(t, func() {
|
assert.NotPanics(t, func() {
|
||||||
global.Load(global.Conf)
|
Load(Conf)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从文件系统载入引擎文件
|
// 从文件系统载入引擎文件
|
||||||
func TestLoadEngineFS(t *testing.T) {
|
func TestLoadEngineFS(t *testing.T) {
|
||||||
root := "fs://" + path.Join(global.Conf.Source, "/xiang")
|
root := "fs://" + path.Join(Conf.Source, "/xiang")
|
||||||
assert.NotPanics(t, func() {
|
assert.NotPanics(t, func() {
|
||||||
global.LoadEngine(root)
|
LoadEngine(root)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -27,13 +26,13 @@ func TestLoadEngineFS(t *testing.T) {
|
||||||
func TestLoadEngineBin(t *testing.T) {
|
func TestLoadEngineBin(t *testing.T) {
|
||||||
root := "bin://xiang"
|
root := "bin://xiang"
|
||||||
assert.NotPanics(t, func() {
|
assert.NotPanics(t, func() {
|
||||||
global.LoadEngine(root)
|
LoadEngine(root)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从文件系统载入应用脚本
|
// 从文件系统载入应用脚本
|
||||||
func TestLoadAppFS(t *testing.T) {
|
func TestLoadAppFS(t *testing.T) {
|
||||||
assert.NotPanics(t, func() {
|
assert.NotPanics(t, func() {
|
||||||
global.LoadApp(global.Conf.RootAPI, global.Conf.RootFLow, global.Conf.RootModel, global.Conf.RootPlugin)
|
LoadApp(Conf.RootAPI, Conf.RootFLow, Conf.RootModel, Conf.RootPlugin)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
37
main.go
37
main.go
|
|
@ -1,47 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/yaoapp/gou"
|
|
||||||
"github.com/yaoapp/kun/utils"
|
|
||||||
"github.com/yaoapp/xiang/cmd"
|
"github.com/yaoapp/xiang/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 主程序
|
// 主程序
|
||||||
func main() {
|
func main() {
|
||||||
cmd.Execute()
|
cmd.Execute()
|
||||||
|
|
||||||
// fmt.Printf("象传应用引擎 %s %s\n", VERSION, DOMAIN)
|
|
||||||
// cfg := NewConfig()
|
|
||||||
|
|
||||||
// // 加载脚本
|
|
||||||
// capsule.AddConn("primary", "mysql", cfg.Database.Primary[0]).SetAsGlobal()
|
|
||||||
|
|
||||||
// // 加密密钥
|
|
||||||
// gou.LoadCrypt(fmt.Sprintf(`{"key":"%s"}`, cfg.Database.AESKey), "AES")
|
|
||||||
// gou.LoadCrypt(`{}`, "PASSWORD")
|
|
||||||
|
|
||||||
// // 加载模型
|
|
||||||
// Load(cfg)
|
|
||||||
|
|
||||||
// // 启动服务
|
|
||||||
// for _, api := range gou.APIs {
|
|
||||||
// for _, p := range api.HTTP.Paths {
|
|
||||||
// utils.Dump(api.Name + ":" + p.Path)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
// gou.ServeHTTP(gou.Server{
|
|
||||||
// Host: cfg.Service.Host,
|
|
||||||
// Port: cfg.Service.Port,
|
|
||||||
// Allows: cfg.Service.Allow,
|
|
||||||
// Root: "/api",
|
|
||||||
// })
|
|
||||||
}
|
|
||||||
|
|
||||||
// Migrate 数据迁移
|
|
||||||
func Migrate() {
|
|
||||||
for name, mod := range gou.Models {
|
|
||||||
utils.Dump(name)
|
|
||||||
mod.Migrate(true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue