[add] migrate flow
This commit is contained in:
parent
725162b0f5
commit
4139a751a9
8 changed files with 111 additions and 12 deletions
4
.github/workflows/unit-test.yml
vendored
4
.github/workflows/unit-test.yml
vendored
|
|
@ -62,7 +62,7 @@ jobs:
|
|||
mongo: ["6.0"]
|
||||
steps:
|
||||
- name: Setup Cache
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
~/.cache/go-build
|
||||
|
|
@ -185,6 +185,6 @@ jobs:
|
|||
make test
|
||||
|
||||
- name: Codecov Report
|
||||
uses: codecov/codecov-action@v2
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
|
||||
|
|
|
|||
2
Makefile
2
Makefile
|
|
@ -9,7 +9,7 @@ COMMIT := $(shell git log | head -n 1 | awk '{print substr($$2, 0, 12)}')
|
|||
NOW := $(shell date +"%FT%T%z")
|
||||
|
||||
# ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
||||
TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api' | grep -vE 'examples|tests*|config|widgets')
|
||||
TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api|model|flow' | grep -vE 'examples|tests*|config|widgets')
|
||||
TESTTAGS ?= ""
|
||||
|
||||
# TESTWIDGETS := $(shell $(GO) list ./widgets/...)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
test.Prepare(t)
|
||||
test.Prepare(t, config.Conf)
|
||||
defer test.Clean()
|
||||
|
||||
Load(config.Conf)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,10 @@ import (
|
|||
// Load 加载业务逻辑编排
|
||||
func Load(cfg config.Config) error {
|
||||
exts := []string{"*.flow.yao", "*.flow.json", "*.flow.jsonc"}
|
||||
return application.App.Walk("apis", func(root, file string, isdir bool) error {
|
||||
return application.App.Walk("flows", func(root, file string, isdir bool) error {
|
||||
if isdir {
|
||||
return nil
|
||||
}
|
||||
_, err := flow.Load(file, share.ID(root, file))
|
||||
return err
|
||||
}, exts...)
|
||||
|
|
|
|||
|
|
@ -6,17 +6,30 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou/flow"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/test"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
test.Prepare(t, config.Conf)
|
||||
defer test.Clean()
|
||||
|
||||
Load(config.Conf)
|
||||
check(t)
|
||||
}
|
||||
|
||||
func check(t *testing.T) {
|
||||
keys := []string{}
|
||||
for key := range flow.Flows {
|
||||
keys = append(keys, key)
|
||||
ids := map[string]bool{}
|
||||
for id := range flow.Flows {
|
||||
ids[id] = true
|
||||
}
|
||||
assert.Equal(t, 26, len(keys))
|
||||
assert.True(t, ids["tests.basic"])
|
||||
assert.True(t, ids["tests.session"])
|
||||
|
||||
// wskeys := []string{}
|
||||
// for key := range websocket.Upgraders {
|
||||
// wskeys = append(wskeys, key)
|
||||
// }
|
||||
|
||||
// assert.Equal(t, 5, len(keys))
|
||||
// assert.Equal(t, 1, len(wskeys))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/yaoapp/gou/application"
|
||||
"github.com/yaoapp/gou/model"
|
||||
"github.com/yaoapp/yao/config"
|
||||
|
|
@ -9,6 +11,10 @@ import (
|
|||
|
||||
// Load 加载数据模型
|
||||
func Load(cfg config.Config) error {
|
||||
|
||||
model.WithCrypt([]byte(fmt.Sprintf(`{"key":"%s"}`, cfg.DB.AESKey)), "AES")
|
||||
model.WithCrypt([]byte(`{}`), "PASSWORD")
|
||||
|
||||
exts := []string{"*.mod.yao", "*.mod.json", "*.mod.jsonc"}
|
||||
return application.App.Walk("models", func(root, file string, isdir bool) error {
|
||||
if isdir {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
test.Prepare(t)
|
||||
test.Prepare(t, config.Conf)
|
||||
defer test.Clean()
|
||||
|
||||
Load(config.Conf)
|
||||
|
|
|
|||
81
test/test.go
81
test/test.go
|
|
@ -1,14 +1,22 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/yaoapp/gou/application"
|
||||
"github.com/yaoapp/gou/model"
|
||||
"github.com/yaoapp/gou/query"
|
||||
"github.com/yaoapp/gou/query/gou"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/xun/capsule"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/share"
|
||||
)
|
||||
|
||||
// Prepare test environment
|
||||
func Prepare(t *testing.T) {
|
||||
func Prepare(t *testing.T, cfg config.Config) {
|
||||
root := os.Getenv("YAO_TEST_APPLICATION")
|
||||
var app application.Application
|
||||
var err error
|
||||
|
|
@ -28,7 +36,76 @@ func Prepare(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
application.Load(app)
|
||||
|
||||
dbconnect(t, cfg)
|
||||
load(t, cfg)
|
||||
}
|
||||
|
||||
// Clean the test environment
|
||||
func Clean() {}
|
||||
func Clean() {
|
||||
dbclose()
|
||||
}
|
||||
|
||||
func dbclose() {
|
||||
if capsule.Global != nil {
|
||||
capsule.Global.Connections.Range(func(key, value any) bool {
|
||||
if conn, ok := value.(*capsule.Connection); ok {
|
||||
conn.Close()
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func dbconnect(t *testing.T, cfg config.Config) {
|
||||
|
||||
// connect db
|
||||
switch cfg.DB.Driver {
|
||||
case "sqlite3":
|
||||
capsule.AddConn("primary", "sqlite3", cfg.DB.Primary[0]).SetAsGlobal()
|
||||
break
|
||||
default:
|
||||
capsule.AddConn("primary", "mysql", cfg.DB.Primary[0]).SetAsGlobal()
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func load(t *testing.T, cfg config.Config) {
|
||||
loadModel(t, cfg)
|
||||
loadQuery(t, cfg)
|
||||
}
|
||||
|
||||
func loadModel(t *testing.T, cfg config.Config) {
|
||||
model.WithCrypt([]byte(fmt.Sprintf(`{"key":"%s"}`, cfg.DB.AESKey)), "AES")
|
||||
model.WithCrypt([]byte(`{}`), "PASSWORD")
|
||||
|
||||
exts := []string{"*.mod.yao", "*.mod.json", "*.mod.jsonc"}
|
||||
err := application.App.Walk("models", func(root, file string, isdir bool) error {
|
||||
if isdir {
|
||||
return nil
|
||||
}
|
||||
_, err := model.Load(file, share.ID(root, file))
|
||||
return err
|
||||
}, exts...)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func loadQuery(t *testing.T, cfg config.Config) {
|
||||
|
||||
// query engine
|
||||
query.Register("query-test", &gou.Query{
|
||||
Query: capsule.Query(),
|
||||
GetTableName: func(s string) string {
|
||||
if mod, has := model.Models[s]; has {
|
||||
return mod.MetaData.Table.Name
|
||||
}
|
||||
exception.New("[query] %s not found", 404, s).Throw()
|
||||
return s
|
||||
},
|
||||
AESKey: cfg.DB.AESKey,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue