[add] migrate api
This commit is contained in:
parent
a807899f95
commit
d014be2e3c
6 changed files with 97 additions and 55 deletions
9
.github/workflows/pr-test.yml
vendored
9
.github/workflows/pr-test.yml
vendored
|
|
@ -45,6 +45,8 @@ env:
|
|||
|
||||
DEMO_APP: ${{ github.WORKSPACE }}/../app
|
||||
|
||||
YAO_TEST_APPLICATION: ${{ github.WORKSPACE }}/../app
|
||||
|
||||
jobs:
|
||||
UnitTest:
|
||||
runs-on: ubuntu-20.04
|
||||
|
|
@ -128,14 +130,13 @@ jobs:
|
|||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: yaoapp/gou
|
||||
ref: dc3d98411f61e21cf775e4c82d92d5ac2acfc03c
|
||||
path: gou
|
||||
|
||||
- name: Checkout V8Go
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: rogchap/v8go
|
||||
ref: 5e91d3d9dcabd2986f901b6b31590e49fc3c4dd8
|
||||
repository: yaoapp/v8go
|
||||
ref: aac4923ed74083e58ae7b42b1acb0fa0d11a26cb
|
||||
path: v8go
|
||||
|
||||
- name: Checkout Demo App
|
||||
|
|
|
|||
19
.github/workflows/unit-test.yml
vendored
19
.github/workflows/unit-test.yml
vendored
|
|
@ -49,6 +49,8 @@ env:
|
|||
|
||||
DEMO_APP: ${{ github.WORKSPACE }}/../app
|
||||
|
||||
YAO_TEST_APPLICATION: ${{ github.WORKSPACE }}/../app
|
||||
|
||||
jobs:
|
||||
unit-test:
|
||||
runs-on: ubuntu-20.04
|
||||
|
|
@ -70,33 +72,32 @@ jobs:
|
|||
${{ runner.os }}-go-
|
||||
|
||||
- name: Checkout Kun
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: ${{ env.REPO_KUN }}
|
||||
path: kun
|
||||
|
||||
- name: Checkout Xun
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: ${{ env.REPO_XUN }}
|
||||
path: xun
|
||||
|
||||
- name: Checkout Gou
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: ${{ env.REPO_GOU }}
|
||||
ref: dc3d98411f61e21cf775e4c82d92d5ac2acfc03c
|
||||
path: gou
|
||||
|
||||
- name: Checkout V8Go
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: rogchap/v8go
|
||||
ref: 5e91d3d9dcabd2986f901b6b31590e49fc3c4dd8
|
||||
repository: yaoapp/v8go
|
||||
ref: aac4923ed74083e58ae7b42b1acb0fa0d11a26cb
|
||||
path: v8go
|
||||
|
||||
- name: Checkout Demo App
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: yaoapp/yao-dev-app
|
||||
path: app
|
||||
|
|
@ -112,7 +113,7 @@ jobs:
|
|||
ls -l ../
|
||||
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Start Redis
|
||||
uses: supercharge/redis-github-action@1.4.0
|
||||
|
|
|
|||
62
Makefile
62
Makefile
|
|
@ -9,10 +9,10 @@ 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 -vE 'examples|tests*|config|widgets')
|
||||
TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api' | grep -vE 'examples|tests*|config|widgets')
|
||||
TESTTAGS ?= ""
|
||||
|
||||
TESTWIDGETS := $(shell $(GO) list ./widgets/...)
|
||||
# TESTWIDGETS := $(shell $(GO) list ./widgets/...)
|
||||
|
||||
# Unit Test
|
||||
.PHONY: test
|
||||
|
|
@ -40,35 +40,35 @@ test:
|
|||
fi; \
|
||||
done
|
||||
|
||||
# Unit Test
|
||||
.PHONY: test-widgets
|
||||
test-widgets:
|
||||
echo "mode: count" > coverage.out
|
||||
for d in $(TESTWIDGETS); do \
|
||||
$(GO) test -tags $(TESTTAGS) -v -covermode=count -coverprofile=profile.out -coverpkg=$$(echo $$d | sed "s/\/test$$//g") $$d > tmp.out; \
|
||||
cat tmp.out; \
|
||||
if grep -q "^--- FAIL" tmp.out; then \
|
||||
rm tmp.out; \
|
||||
exit 1; \
|
||||
elif grep -q "build failed" tmp.out; then \
|
||||
rm tmp.out; \
|
||||
exit 1; \
|
||||
elif grep -q "setup failed" tmp.out; then \
|
||||
rm tmp.out; \
|
||||
exit 1; \
|
||||
elif grep -q "runtime error" tmp.out; then \
|
||||
rm tmp.out; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
if [ -f profile.out ]; then \
|
||||
cat profile.out | grep -v "mode:" >> coverage.out; \
|
||||
rm profile.out; \
|
||||
fi; \
|
||||
done
|
||||
# # Unit Test
|
||||
# .PHONY: test-widgets
|
||||
# test-widgets:
|
||||
# echo "mode: count" > coverage.out
|
||||
# for d in $(TESTWIDGETS); do \
|
||||
# $(GO) test -tags $(TESTTAGS) -v -covermode=count -coverprofile=profile.out -coverpkg=$$(echo $$d | sed "s/\/test$$//g") $$d > tmp.out; \
|
||||
# cat tmp.out; \
|
||||
# if grep -q "^--- FAIL" tmp.out; then \
|
||||
# rm tmp.out; \
|
||||
# exit 1; \
|
||||
# elif grep -q "build failed" tmp.out; then \
|
||||
# rm tmp.out; \
|
||||
# exit 1; \
|
||||
# elif grep -q "setup failed" tmp.out; then \
|
||||
# rm tmp.out; \
|
||||
# exit 1; \
|
||||
# elif grep -q "runtime error" tmp.out; then \
|
||||
# rm tmp.out; \
|
||||
# exit 1; \
|
||||
# fi; \
|
||||
# if [ -f profile.out ]; then \
|
||||
# cat profile.out | grep -v "mode:" >> coverage.out; \
|
||||
# rm profile.out; \
|
||||
# fi; \
|
||||
# done
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
$(GOFMT) -w $(GOFILES)
|
||||
# .PHONY: fmt
|
||||
# fmt:
|
||||
# $(GOFMT) -w $(GOFILES)
|
||||
|
||||
.PHONY: fmt-check
|
||||
fmt-check:
|
||||
|
|
@ -80,8 +80,6 @@ fmt-check:
|
|||
fi;
|
||||
|
||||
vet:
|
||||
$(GO) env -w GONOPROXY=github.com/yaoapp/gou
|
||||
$(GO) env -w GOPRIVATE=github.com/yaoapp/gou
|
||||
$(GO) vet $(VETPACKAGES)
|
||||
|
||||
.PHONY: lint
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@ import (
|
|||
func Load(cfg config.Config) error {
|
||||
exts := []string{"*.http.yao", "*.http.json", "*.http.jsonc"}
|
||||
return application.App.Walk("apis", func(root, file string, isdir bool) error {
|
||||
if isdir {
|
||||
return nil
|
||||
}
|
||||
_, err := api.Load(file, share.ID(root, file))
|
||||
return err
|
||||
}, exts...)
|
||||
|
|
|
|||
|
|
@ -5,26 +5,31 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou/api"
|
||||
"github.com/yaoapp/gou/websocket"
|
||||
"github.com/yaoapp/yao/config"
|
||||
"github.com/yaoapp/yao/test"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
test.Prepare(t)
|
||||
defer test.Clean()
|
||||
|
||||
Load(config.Conf)
|
||||
check(t)
|
||||
}
|
||||
|
||||
func check(t *testing.T) {
|
||||
keys := []string{}
|
||||
for key := range api.APIs {
|
||||
keys = append(keys, key)
|
||||
ids := map[string]bool{}
|
||||
for id := range api.APIs {
|
||||
ids[id] = true
|
||||
}
|
||||
assert.True(t, ids["user"])
|
||||
assert.True(t, ids["user.pet"])
|
||||
|
||||
wskeys := []string{}
|
||||
for key := range websocket.Upgraders {
|
||||
wskeys = append(wskeys, key)
|
||||
}
|
||||
// wskeys := []string{}
|
||||
// for key := range websocket.Upgraders {
|
||||
// wskeys = append(wskeys, key)
|
||||
// }
|
||||
|
||||
assert.Equal(t, 5, len(keys))
|
||||
assert.Equal(t, 1, len(wskeys))
|
||||
// assert.Equal(t, 5, len(keys))
|
||||
// assert.Equal(t, 1, len(wskeys))
|
||||
}
|
||||
|
|
|
|||
34
test/test.go
Normal file
34
test/test.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/yaoapp/gou/application"
|
||||
)
|
||||
|
||||
// Prepare test environment
|
||||
func Prepare(t *testing.T) {
|
||||
root := os.Getenv("YAO_TEST_APPLICATION")
|
||||
var app application.Application
|
||||
var err error
|
||||
|
||||
if root == "bin:application.pkg" {
|
||||
key := os.Getenv("YAO_TEST_PRIVATE_KEY")
|
||||
app, err = application.OpenFromBin(root, key) // Load app from Bin
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
application.Load(app)
|
||||
return
|
||||
}
|
||||
|
||||
app, err = application.OpenFromDisk(root) // Load app from Disk
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
application.Load(app)
|
||||
}
|
||||
|
||||
// Clean the test environment
|
||||
func Clean() {}
|
||||
Loading…
Add table
Reference in a new issue