feat: Replace mongo package with monc & mon (#2002)
* Replace mongo package with monc & mon * Add terminal whitespace * format code
This commit is contained in:
25
tools/goctl/test/common/echo.sh
Normal file
25
tools/goctl/test/common/echo.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
function console_red() {
|
||||
echo -e "\033[31m "$*" \033[0m"
|
||||
}
|
||||
|
||||
function console_green() {
|
||||
echo -e "\033[32m "$*" \033[0m"
|
||||
}
|
||||
|
||||
function console_yellow() {
|
||||
echo -e "\033[33m "$*" \033[0m"
|
||||
}
|
||||
|
||||
function console_blue() {
|
||||
echo -e "\033[34m "$*" \033[0m"
|
||||
}
|
||||
|
||||
function console_tip() {
|
||||
console_blue "========================== $* =============================="
|
||||
}
|
||||
|
||||
function console_step() {
|
||||
console_blue "<<<<<<<<<<<<<<<< $* >>>>>>>>>>>>>>>>"
|
||||
}
|
||||
12
tools/goctl/test/integration/model/mongo/Dockerfile
Normal file
12
tools/goctl/test/integration/model/mongo/Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
||||
FROM golang:1.18
|
||||
|
||||
ENV TZ Asia/Shanghai
|
||||
ENV GOPROXY https://goproxy.cn,direct
|
||||
|
||||
WORKDIR /app
|
||||
ADD goctl /usr/bin/goctl
|
||||
ADD cmd.sh .
|
||||
|
||||
RUN chmod +x /usr/bin/goctl
|
||||
RUN chmod +x cmd.sh
|
||||
CMD ["/bin/bash", "cmd.sh"]
|
||||
32
tools/goctl/test/integration/model/mongo/cmd.sh
Normal file
32
tools/goctl/test/integration/model/mongo/cmd.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
wd=$(dirname $0)
|
||||
project=test
|
||||
testDir=$wd/$project
|
||||
mkdir -p $testDir
|
||||
|
||||
cd $testDir
|
||||
|
||||
# go mod init
|
||||
go mod init $project
|
||||
|
||||
# generate cache code
|
||||
goctl model mongo -t User -c --dir cache
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# generate non-cache code
|
||||
goctl model mongo -t User --dir nocache
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# go mod tidy
|
||||
GOPROXY=https://goproxy.cn && go mod tidy
|
||||
|
||||
# code inspection
|
||||
go test -race ./...
|
||||
if [ $? -ne 0 ]; then
|
||||
echo
|
||||
fi
|
||||
38
tools/goctl/test/integration/model/mongo/mongo.sh
Normal file
38
tools/goctl/test/integration/model/mongo/mongo.sh
Normal file
@@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd $(dirname $0)
|
||||
|
||||
# source functions
|
||||
source ../../../common/echo.sh
|
||||
|
||||
console_tip "mongo test"
|
||||
|
||||
# build goctl
|
||||
console_step "goctl building"
|
||||
|
||||
buildFile=goctl
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $buildFile ../../../../goctl.go
|
||||
image=goctl-mongo:latest
|
||||
|
||||
# docker build
|
||||
console_step "docker building"
|
||||
docker build -t $image .
|
||||
if [ $? -ne 0 ]; then
|
||||
rm -f $buildFile
|
||||
console_red "docker build failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# run docker image
|
||||
console_step "docker running"
|
||||
docker run $image
|
||||
if [ $? -ne 0 ]; then
|
||||
rm -f $buildFile
|
||||
console_red "docker run failed"
|
||||
docker image rm -f $image
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f $buildFile
|
||||
console_green "PASS"
|
||||
docker image rm -f $image > /dev/null 2>&1
|
||||
6
tools/goctl/test/main.sh
Normal file
6
tools/goctl/test/main.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
# main.sh is the entry point for the goctl tests.
|
||||
|
||||
# testing mongo code generation.
|
||||
/bin/bash integration/model/mongo/mongo.sh
|
||||
Reference in New Issue
Block a user