forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
267 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
os: linux | ||
dist: xenial | ||
language: go | ||
|
||
services: | ||
- docker | ||
|
||
jobs: | ||
fast_finish: true | ||
include: | ||
- name: MySQL8.0-1.17.x | ||
go: 1.17.x | ||
env: | ||
- GOU_TEST_API_ROOT="$TRAVIS_BUILD_DIR/app/apis" GOU_TEST_FLW_ROOT="$TRAVIS_BUILD_DIR/app/flows" GOU_TEST_MOD_ROOT="$TRAVIS_BUILD_DIR/app/models" GOU_TEST_PLG_ROOT="$HOME/data/gou-unit/plugins" GOU_TEST_PLG_LOG="$HOME/data/gou-unit/logs" GOU_TEST_DSN="root:123456@tcp(127.0.0.1:3308)/xun?charset=utf8mb4&parseTime=True&loc=Local" GOT_TEST_AES_KEY="^*aNBue!loLTTiP*4i&BSK7s#QRbe0^g" CODECOV_TOKEN='4b4d73e7-65b3-4d04-9353-11d71f38d904' | ||
before_install: | ||
- unit/service.sh mysql8.0 # Start MySQL 8.0 service | ||
- name: MySQL5.7-1.17.x | ||
go: 1.17.x | ||
env: | ||
- GOU_TEST_API_ROOT="$TRAVIS_BUILD_DIR/app/apis" GOU_TEST_FLW_ROOT="$TRAVIS_BUILD_DIR/app/flows" GOU_TEST_MOD_ROOT="$TRAVIS_BUILD_DIR/app/models" GOU_TEST_PLG_ROOT="$HOME/data/gou-unit/plugins" GOU_TEST_PLG_LOG="$HOME/data/gou-unit/logs" GOU_TEST_DSN="root:123456@tcp(127.0.0.1:3306)/xun?charset=utf8mb4&parseTime=True&loc=Local" GOT_TEST_AES_KEY="^*aNBue!loLTTiP*4i&BSK7s#QRbe0^g" CODECOV_TOKEN='4b4d73e7-65b3-4d04-9353-11d71f38d904' | ||
before_install: | ||
- unit/service.sh mysql5.7 # Start MySQL 5.7 service | ||
- name: MySQL5.6-1.17.x | ||
go: 1.17.x | ||
env: | ||
- GOU_TEST_API_ROOT="$TRAVIS_BUILD_DIR/app/apis" GOU_TEST_FLW_ROOT="$TRAVIS_BUILD_DIR/app/flows" GOU_TEST_MOD_ROOT="$TRAVIS_BUILD_DIR/app/models" GOU_TEST_PLG_ROOT="$HOME/data/gou-unit/plugins" GOU_TEST_PLG_LOG="$HOME/data/gou-unit/logs" GOU_TEST_DSN="root:123456@tcp(127.0.0.1:3307)/xun?charset=utf8mb4&parseTime=True&loc=Local" GOT_TEST_AES_KEY="^*aNBue!loLTTiP*4i&BSK7s#QRbe0^g" CODECOV_TOKEN='4b4d73e7-65b3-4d04-9353-11d71f38d904' | ||
before_install: | ||
- unit/service.sh mysql5.6 # Start MySQL 5.6 service | ||
git: | ||
depth: 10 | ||
install: | ||
- if [[ "${GO111MODULE}" = "on" ]]; then go mod download; fi | ||
- if [[ "${GO111MODULE}" = "on" ]]; then export PATH="${GOPATH}/bin:${GOROOT}/bin:${PATH}"; fi | ||
- if [[ "${GO111MODULE}" = "on" ]]; then make tools; fi | ||
|
||
go_import_path: github.com/yaoapp/gou | ||
|
||
script: | ||
- export | ||
- make vet | ||
- make fmt-check | ||
- make misspell-check | ||
- make plugin | ||
# - make migrate | ||
- make test | ||
|
||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
GO ?= go | ||
GOFMT ?= gofmt "-s" | ||
PACKAGES ?= $(shell $(GO) list ./...) | ||
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) | ||
TESTTAGS ?= "" | ||
|
||
.PHONY: test | ||
test: | ||
echo "mode: count" > coverage.out | ||
for d in $(TESTFOLDER); 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-check | ||
fmt-check: | ||
@diff=$$($(GOFMT) -d $(GOFILES)); \ | ||
if [ -n "$$diff" ]; then \ | ||
echo "Please run 'make fmt' and commit the result:"; \ | ||
echo "$${diff}"; \ | ||
exit 1; \ | ||
fi; | ||
|
||
vet: | ||
$(GO) vet $(VETPACKAGES) | ||
|
||
.PHONY: lint | ||
lint: | ||
@hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ | ||
$(GO) get -u golang.org/x/lint/golint; \ | ||
fi | ||
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done; | ||
|
||
.PHONY: misspell-check | ||
misspell-check: | ||
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ | ||
$(GO) get -u github.com/client9/misspell/cmd/misspell; \ | ||
fi | ||
misspell -error $(GOFILES) | ||
|
||
.PHONY: misspell | ||
misspell: | ||
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ | ||
$(GO) get -u github.com/client9/misspell/cmd/misspell; \ | ||
fi | ||
misspell -w $(GOFILES) | ||
|
||
.PHONY: tools | ||
tools: | ||
go install golang.org/x/lint/golint; \ | ||
go install github.com/client9/misspell/cmd/misspell; | ||
|
||
.PHONY: plugin | ||
plugin: | ||
rm -rf $(HOME)/data/gou-unit/plugins | ||
rm -rf $(HOME)/data/gou-unit/logs | ||
mkdir -p $(HOME)/data/gou-unit/plugins | ||
mkdir -p $(HOME)/data/gou-unit/logs | ||
GOOS=linux GOARCH=amd64 go build -o $(HOME)/data/gou-unit/plugins/user ./app/plugins/user | ||
chmod +x $(HOME)/data/gou-unit/plugins/user | ||
ls -l $(HOME)/data/gou-unit/plugins | ||
ls -l $(HOME)/data/gou-unit/logs | ||
$(HOME)/data/gou-unit/plugins/user 2>&1 || true | ||
plugin-mac: | ||
rm -rf ./app/plugins/user/dist | ||
go build -o ./app/plugins/dist/user ./app/plugins/user | ||
chmod +x ./app/plugins/dist/user | ||
|
||
# .PHONY: migrate | ||
# migrate: | ||
# $(GO) test -tags $(TESTTAGS) -run TestModelMigrate$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package main | ||
|
||
// Load 根据配置加载 API, FLow, Model, Plugin | ||
func Load() error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLoad(t *testing.T) { | ||
err := Load() | ||
assert.Nil(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/bin/bash | ||
StartMySQL5.7() { | ||
docker pull mysql:5.7.25 | ||
docker run --name=mysql5.7 -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7.25 --default-authentication-plugin=mysql_native_password | ||
Waiting "mysql5.7" "Version: '5.7.25' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)" 30 | ||
docker logs mysql5.7 | ||
docker exec mysql5.7 mysql -uroot -p123456 -e "CREATE DATABASE xun CHARACTER SET utf8 COLLATE utf8_general_ci" | ||
docker exec mysql5.7 mysql -uroot -p123456 -e "CREATE USER xun@'%' IDENTIFIED BY '123456'" | ||
docker exec mysql5.7 mysql -uroot -p123456 -e "GRANT SELECT ON xun.* TO 'xun'@'%'"; | ||
} | ||
|
||
StartMySQL8.0() { | ||
docker pull mysql:8.0.26 | ||
docker run --name=mysql8.0 -d -p 3308:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:8.0.26 --default-authentication-plugin=mysql_native_password | ||
Waiting "mysql8.0" "Version: '8.0.26' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL" 30 | ||
docker logs mysql8.0 | ||
docker exec mysql8.0 mysql -uroot -p123456 -e "CREATE DATABASE xun CHARACTER SET utf8 COLLATE utf8_general_ci" | ||
docker exec mysql8.0 mysql -uroot -p123456 -e "CREATE USER xun@'%' IDENTIFIED BY '123456'" | ||
docker exec mysql8.0 mysql -uroot -p123456 -e "GRANT SELECT ON xun.* TO 'xun'@'%'"; | ||
} | ||
|
||
|
||
StartMySQL5.6() { | ||
docker pull mysql:5.6.51 | ||
docker run --name=mysql5.6 -d -p 3307:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.6.51 --default-authentication-plugin=mysql_native_password | ||
Waiting "mysql5.6" "Version: '5.6.51' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)" 30 | ||
docker logs mysql5.6 | ||
docker exec mysql5.6 mysql -uroot -p123456 -e "CREATE DATABASE xun CHARACTER SET utf8 COLLATE utf8_general_ci" | ||
docker exec mysql5.6 mysql -uroot -p123456 -e "CREATE USER xun@'%' IDENTIFIED BY '123456'" | ||
docker exec mysql5.6 mysql -uroot -p123456 -e "GRANT SELECT ON xun.* TO 'xun'@'%'"; | ||
} | ||
|
||
|
||
StartPostgres9.6() { | ||
docker pull postgres:9.6 | ||
docker run --name=postgres9.6 -d -p 5432:5432 -e POSTGRES_PASSWORD=123456 postgres:9.6 | ||
Waiting "postgres9.6" "PostgreSQL init process complete; ready for start up" 30 | ||
docker logs postgres9.6 | ||
docker exec postgres9.6 su - postgres -c "psql -c 'CREATE DATABASE xun'" | ||
docker exec postgres9.6 su - postgres -c "psql -c \"CREATE USER xun WITH PASSWORD '123456'\"" | ||
docker exec postgres9.6 su - postgres -c "psql -c 'GRANT ALL PRIVILEGES ON DATABASE \"xun\" to xun;'" | ||
} | ||
|
||
IsReady() { | ||
name=$1 | ||
checkstr=$2 | ||
res=$(docker logs $1 2>&1 | grep "$checkstr") | ||
if [ "$res" == "" ]; then | ||
echo "0" | ||
else | ||
echo "1" | ||
fi | ||
} | ||
|
||
Waiting() { | ||
name=$1 | ||
checkstr=$2 | ||
let timeout=$3 | ||
echo -n "Starting $name ." | ||
isready=$(IsReady "$name" "$checkstr") | ||
timing=0 | ||
while [ "$isready" == "0" ]; | ||
do | ||
sleep 1 | ||
isready=$(IsReady "$name" "$checkstr") | ||
let timing=${timing}+1 | ||
echo -n "." | ||
if [ $timing -eq $timeout ]; then | ||
echo " failed. timout($timeout)" >&2 | ||
docker logs $name >&2 | ||
exit 1 | ||
fi | ||
done | ||
echo " done" | ||
} | ||
|
||
command=$1 | ||
case $command in | ||
mysql8.0) StartMySQL8.0;; | ||
mysql5.7) StartMySQL5.7;; | ||
mysql5.6) StartMySQL5.6;; | ||
postgres9.6) StartPostgres9.6;; | ||
*) $(echo "please input command" >&2) ;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMain(t *testing.T) { | ||
assert.NotPanics(t, func() { | ||
main() | ||
}) | ||
} |