Skip to content

Commit

Permalink
调整单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Sep 14, 2021
1 parent 30852f4 commit 7917f1f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VETPACKAGES ?= $(shell $(GO) list ./... | grep -v /examples/)
GOFILES := $(shell find . -name "*.go")

# 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 ?= ""

# 运行单元测试
Expand Down
14 changes: 14 additions & 0 deletions cmd/help.go
Original file line number Diff line number Diff line change
@@ -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()
},
}
6 changes: 6 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ var rootCmd = &cobra.Command{
Short: "象传应用引擎命令行工具",
Long: `象传应用引擎命令行工具`,
Args: cobra.MinimumNArgs(1),
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
},
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintln(os.Stderr, "参数错误", args)
os.Exit(1)
Expand All @@ -27,6 +30,9 @@ func init() {
infoCmd,
startCmd,
)

rootCmd.SetHelpCommand(helpCmd)

}

// Execute 运行Root
Expand Down
5 changes: 2 additions & 3 deletions config_test.go → global/config_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package global

import (
"os"
Expand All @@ -7,11 +7,10 @@ import (

"github.com/stretchr/testify/assert"
"github.com/yaoapp/kun/any"
"github.com/yaoapp/xiang/global"
)

func TestNewConfig(t *testing.T) {
cfg := global.NewConfig()
cfg := NewConfig()
var vBool = func(name string) bool {
if name == "true" || name == "1" {
return true
Expand Down
21 changes: 21 additions & 0 deletions global/init_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
13 changes: 6 additions & 7 deletions load_test.go → global/load_test.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package main
package global

import (
"path"
"testing"

"github.com/stretchr/testify/assert"
"github.com/yaoapp/xiang/global"
)

func TestLoad(t *testing.T) {
assert.NotPanics(t, func() {
global.Load(global.Conf)
Load(Conf)
})
}

// 从文件系统载入引擎文件
func TestLoadEngineFS(t *testing.T) {
root := "fs://" + path.Join(global.Conf.Source, "/xiang")
root := "fs://" + path.Join(Conf.Source, "/xiang")
assert.NotPanics(t, func() {
global.LoadEngine(root)
LoadEngine(root)
})

}
Expand All @@ -27,13 +26,13 @@ func TestLoadEngineFS(t *testing.T) {
func TestLoadEngineBin(t *testing.T) {
root := "bin://xiang"
assert.NotPanics(t, func() {
global.LoadEngine(root)
LoadEngine(root)
})
}

// 从文件系统载入应用脚本
func TestLoadAppFS(t *testing.T) {
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 changes: 0 additions & 37 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,10 @@
package main

import (
"github.com/yaoapp/gou"
"github.com/yaoapp/kun/utils"
"github.com/yaoapp/xiang/cmd"
)

// 主程序
func main() {
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)
}
}

0 comments on commit 7917f1f

Please sign in to comment.