+ CI
This commit is contained in:
parent
76a87aeb7a
commit
743251d024
10 changed files with 267 additions and 1 deletions
48
.travis.yml
Normal file
48
.travis.yml
Normal file
|
|
@ -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)
|
||||||
96
Makefile
Normal file
96
Makefile
Normal file
|
|
@ -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$
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
# 象传应用引擎
|
# 象传应用引擎
|
||||||
|
|
||||||
|
[](https://travis-ci.com/github/YaoApp/xiang)
|
||||||
|
[](https://codecov.io/gh/YaoApp/xiang)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
象传应用引擎,是一款低代码应用运行引擎,采用 Golang 语言开发。
|
象传应用引擎,是一款低代码应用运行引擎,采用 Golang 语言开发。
|
||||||
|
|
|
||||||
1
go.mod
1
go.mod
|
|
@ -7,6 +7,7 @@ require (
|
||||||
github.com/hashicorp/go-hclog v0.16.2 // indirect
|
github.com/hashicorp/go-hclog v0.16.2 // indirect
|
||||||
github.com/hashicorp/go-plugin v1.4.2 // indirect
|
github.com/hashicorp/go-plugin v1.4.2 // indirect
|
||||||
github.com/json-iterator/go v1.1.11 // indirect
|
github.com/json-iterator/go v1.1.11 // indirect
|
||||||
|
github.com/stretchr/testify v1.7.0
|
||||||
github.com/yaoapp/kun v0.6.1
|
github.com/yaoapp/kun v0.6.1
|
||||||
golang.org/x/sys v0.0.0-20210903071746-97244b99971b // indirect
|
golang.org/x/sys v0.0.0-20210903071746-97244b99971b // indirect
|
||||||
)
|
)
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -12,6 +12,7 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
|
||||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||||
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
|
|
@ -82,6 +83,7 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
|
||||||
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
|
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
|
||||||
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
|
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
|
||||||
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
|
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||||
|
|
@ -90,6 +92,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/yaoapp/kun v0.6.1 h1:gbjP5wmAuJLe1RGZ2evH4rPCVWykf0iqbksaHikF/GI=
|
github.com/yaoapp/kun v0.6.1 h1:gbjP5wmAuJLe1RGZ2evH4rPCVWykf0iqbksaHikF/GI=
|
||||||
github.com/yaoapp/kun v0.6.1/go.mod h1:igsTcWDnzpp0HtRN7sBP+XOEN2tzoC5hk2MyoPFs3xA=
|
github.com/yaoapp/kun v0.6.1/go.mod h1:igsTcWDnzpp0HtRN7sBP+XOEN2tzoC5hk2MyoPFs3xA=
|
||||||
|
|
@ -194,6 +197,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
|
|
||||||
1
hot.go
1
hot.go
|
|
@ -1 +0,0 @@
|
||||||
package main
|
|
||||||
6
load.go
Normal file
6
load.go
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
// Load 根据配置加载 API, FLow, Model, Plugin
|
||||||
|
func Load() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
12
load_test.go
Normal file
12
load_test.go
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestLoad(t *testing.T) {
|
||||||
|
err := Load()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
84
unit/service.sh
Executable file
84
unit/service.sh
Executable file
|
|
@ -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
|
||||||
13
xiang_test.go
Normal file
13
xiang_test.go
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMain(t *testing.T) {
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
main()
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue