[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
|
DEMO_APP: ${{ github.WORKSPACE }}/../app
|
||||||
|
|
||||||
|
YAO_TEST_APPLICATION: ${{ github.WORKSPACE }}/../app
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
UnitTest:
|
UnitTest:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
|
|
@ -128,14 +130,13 @@ jobs:
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
repository: yaoapp/gou
|
repository: yaoapp/gou
|
||||||
ref: dc3d98411f61e21cf775e4c82d92d5ac2acfc03c
|
|
||||||
path: gou
|
path: gou
|
||||||
|
|
||||||
- name: Checkout V8Go
|
- name: Checkout V8Go
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: rogchap/v8go
|
repository: yaoapp/v8go
|
||||||
ref: 5e91d3d9dcabd2986f901b6b31590e49fc3c4dd8
|
ref: aac4923ed74083e58ae7b42b1acb0fa0d11a26cb
|
||||||
path: v8go
|
path: v8go
|
||||||
|
|
||||||
- name: Checkout Demo App
|
- 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
|
DEMO_APP: ${{ github.WORKSPACE }}/../app
|
||||||
|
|
||||||
|
YAO_TEST_APPLICATION: ${{ github.WORKSPACE }}/../app
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
unit-test:
|
unit-test:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
|
|
@ -70,33 +72,32 @@ jobs:
|
||||||
${{ runner.os }}-go-
|
${{ runner.os }}-go-
|
||||||
|
|
||||||
- name: Checkout Kun
|
- name: Checkout Kun
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: ${{ env.REPO_KUN }}
|
repository: ${{ env.REPO_KUN }}
|
||||||
path: kun
|
path: kun
|
||||||
|
|
||||||
- name: Checkout Xun
|
- name: Checkout Xun
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: ${{ env.REPO_XUN }}
|
repository: ${{ env.REPO_XUN }}
|
||||||
path: xun
|
path: xun
|
||||||
|
|
||||||
- name: Checkout Gou
|
- name: Checkout Gou
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: ${{ env.REPO_GOU }}
|
repository: ${{ env.REPO_GOU }}
|
||||||
ref: dc3d98411f61e21cf775e4c82d92d5ac2acfc03c
|
|
||||||
path: gou
|
path: gou
|
||||||
|
|
||||||
- name: Checkout V8Go
|
- name: Checkout V8Go
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: rogchap/v8go
|
repository: yaoapp/v8go
|
||||||
ref: 5e91d3d9dcabd2986f901b6b31590e49fc3c4dd8
|
ref: aac4923ed74083e58ae7b42b1acb0fa0d11a26cb
|
||||||
path: v8go
|
path: v8go
|
||||||
|
|
||||||
- name: Checkout Demo App
|
- name: Checkout Demo App
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: yaoapp/yao-dev-app
|
repository: yaoapp/yao-dev-app
|
||||||
path: app
|
path: app
|
||||||
|
|
@ -112,7 +113,7 @@ jobs:
|
||||||
ls -l ../
|
ls -l ../
|
||||||
|
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Start Redis
|
- name: Start Redis
|
||||||
uses: supercharge/redis-github-action@1.4.0
|
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")
|
NOW := $(shell date +"%FT%T%z")
|
||||||
|
|
||||||
# ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
# 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 ?= ""
|
TESTTAGS ?= ""
|
||||||
|
|
||||||
TESTWIDGETS := $(shell $(GO) list ./widgets/...)
|
# TESTWIDGETS := $(shell $(GO) list ./widgets/...)
|
||||||
|
|
||||||
# Unit Test
|
# Unit Test
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
|
|
@ -40,35 +40,35 @@ test:
|
||||||
fi; \
|
fi; \
|
||||||
done
|
done
|
||||||
|
|
||||||
# Unit Test
|
# # Unit Test
|
||||||
.PHONY: test-widgets
|
# .PHONY: test-widgets
|
||||||
test-widgets:
|
# test-widgets:
|
||||||
echo "mode: count" > coverage.out
|
# echo "mode: count" > coverage.out
|
||||||
for d in $(TESTWIDGETS); do \
|
# 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; \
|
# $(GO) test -tags $(TESTTAGS) -v -covermode=count -coverprofile=profile.out -coverpkg=$$(echo $$d | sed "s/\/test$$//g") $$d > tmp.out; \
|
||||||
cat tmp.out; \
|
# cat tmp.out; \
|
||||||
if grep -q "^--- FAIL" tmp.out; then \
|
# if grep -q "^--- FAIL" tmp.out; then \
|
||||||
rm tmp.out; \
|
# rm tmp.out; \
|
||||||
exit 1; \
|
# exit 1; \
|
||||||
elif grep -q "build failed" tmp.out; then \
|
# elif grep -q "build failed" tmp.out; then \
|
||||||
rm tmp.out; \
|
# rm tmp.out; \
|
||||||
exit 1; \
|
# exit 1; \
|
||||||
elif grep -q "setup failed" tmp.out; then \
|
# elif grep -q "setup failed" tmp.out; then \
|
||||||
rm tmp.out; \
|
# rm tmp.out; \
|
||||||
exit 1; \
|
# exit 1; \
|
||||||
elif grep -q "runtime error" tmp.out; then \
|
# elif grep -q "runtime error" tmp.out; then \
|
||||||
rm tmp.out; \
|
# rm tmp.out; \
|
||||||
exit 1; \
|
# exit 1; \
|
||||||
fi; \
|
# fi; \
|
||||||
if [ -f profile.out ]; then \
|
# if [ -f profile.out ]; then \
|
||||||
cat profile.out | grep -v "mode:" >> coverage.out; \
|
# cat profile.out | grep -v "mode:" >> coverage.out; \
|
||||||
rm profile.out; \
|
# rm profile.out; \
|
||||||
fi; \
|
# fi; \
|
||||||
done
|
# done
|
||||||
|
|
||||||
.PHONY: fmt
|
# .PHONY: fmt
|
||||||
fmt:
|
# fmt:
|
||||||
$(GOFMT) -w $(GOFILES)
|
# $(GOFMT) -w $(GOFILES)
|
||||||
|
|
||||||
.PHONY: fmt-check
|
.PHONY: fmt-check
|
||||||
fmt-check:
|
fmt-check:
|
||||||
|
|
@ -80,8 +80,6 @@ fmt-check:
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
vet:
|
vet:
|
||||||
$(GO) env -w GONOPROXY=github.com/yaoapp/gou
|
|
||||||
$(GO) env -w GOPRIVATE=github.com/yaoapp/gou
|
|
||||||
$(GO) vet $(VETPACKAGES)
|
$(GO) vet $(VETPACKAGES)
|
||||||
|
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,9 @@ import (
|
||||||
func Load(cfg config.Config) error {
|
func Load(cfg config.Config) error {
|
||||||
exts := []string{"*.http.yao", "*.http.json", "*.http.jsonc"}
|
exts := []string{"*.http.yao", "*.http.json", "*.http.jsonc"}
|
||||||
return application.App.Walk("apis", func(root, file string, isdir bool) error {
|
return application.App.Walk("apis", func(root, file string, isdir bool) error {
|
||||||
|
if isdir {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
_, err := api.Load(file, share.ID(root, file))
|
_, err := api.Load(file, share.ID(root, file))
|
||||||
return err
|
return err
|
||||||
}, exts...)
|
}, exts...)
|
||||||
|
|
|
||||||
|
|
@ -5,26 +5,31 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/yaoapp/gou/api"
|
"github.com/yaoapp/gou/api"
|
||||||
"github.com/yaoapp/gou/websocket"
|
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
|
"github.com/yaoapp/yao/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoad(t *testing.T) {
|
func TestLoad(t *testing.T) {
|
||||||
|
test.Prepare(t)
|
||||||
|
defer test.Clean()
|
||||||
|
|
||||||
Load(config.Conf)
|
Load(config.Conf)
|
||||||
check(t)
|
check(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func check(t *testing.T) {
|
func check(t *testing.T) {
|
||||||
keys := []string{}
|
ids := map[string]bool{}
|
||||||
for key := range api.APIs {
|
for id := range api.APIs {
|
||||||
keys = append(keys, key)
|
ids[id] = true
|
||||||
}
|
}
|
||||||
|
assert.True(t, ids["user"])
|
||||||
|
assert.True(t, ids["user.pet"])
|
||||||
|
|
||||||
wskeys := []string{}
|
// wskeys := []string{}
|
||||||
for key := range websocket.Upgraders {
|
// for key := range websocket.Upgraders {
|
||||||
wskeys = append(wskeys, key)
|
// wskeys = append(wskeys, key)
|
||||||
}
|
// }
|
||||||
|
|
||||||
assert.Equal(t, 5, len(keys))
|
// assert.Equal(t, 5, len(keys))
|
||||||
assert.Equal(t, 1, len(wskeys))
|
// 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