From 5983992642c33831eed65e031acadb53cf4a1511 Mon Sep 17 00:00:00 2001 From: q191201771 <191201771@qq.com> Date: Wed, 19 Apr 2023 23:29:58 +0800 Subject: [PATCH] [chore] all shell file go to script folder --- .github/workflows/ci.yml | 4 +- Makefile | 32 +++++--- run_docker.sh | 4 - build.sh => script/build.sh | 26 +++--- script/build_docker_image.sh | 13 +++ check_versions.sh => script/check_versions.sh | 34 ++++---- script/clean.sh | 15 ++++ gen_release.sh => script/gen_release.sh | 29 ++++--- gen_tag.sh => script/gen_tag.sh | 15 +++- script/run_docker.sh | 14 ++++ showdeps.sh => script/showdeps.sh | 11 ++- script/test.sh | 79 +++++++++++++++++++ test.sh | 72 ----------------- 13 files changed, 216 insertions(+), 132 deletions(-) delete mode 100755 run_docker.sh rename build.sh => script/build.sh (76%) mode change 100755 => 100644 create mode 100644 script/build_docker_image.sh rename check_versions.sh => script/check_versions.sh (57%) create mode 100644 script/clean.sh rename gen_release.sh => script/gen_release.sh (67%) mode change 100755 => 100644 rename gen_tag.sh => script/gen_tag.sh (69%) mode change 100755 => 100644 create mode 100644 script/run_docker.sh rename showdeps.sh => script/showdeps.sh (69%) mode change 100755 => 100644 create mode 100644 script/test.sh delete mode 100755 test.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bef2ecf..5e198aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,10 +24,10 @@ jobs: go-version: ${{ matrix.go }} - name: Build - run: ./build.sh + run: make build - name: Test - run: ./test.sh + run: make test - name: Upload coverage to Codecov run: bash <(curl -s https://codecov.io/bash) diff --git a/Makefile b/Makefile index 1d0a221..ecc1ede 100644 --- a/Makefile +++ b/Makefile @@ -1,36 +1,42 @@ .PHONY: build build: - export GO111MODULE=on && export GOPROXY=https://goproxy.cn,https://goproxy.io,direct && ./build.sh + ./script/build.sh .PHONY: build_for_linux build_for_linux: - export CGO_ENABLED=0 && export GOS=linux && ./build.sh + export CGO_ENABLED=0 && export GOS=linux && ./script/build.sh .PHONY: build_for_linux_amd64 build_for_linux_amd64: - export CGO_ENABLED=0 && export GOS=linux && export GOARCH=amd64 && ./build.sh + export CGO_ENABLED=0 && export GOS=linux && export GOARCH=amd64 && ./script/build.sh .PHONY: build_for_linux_arm64 build_for_linux_arm64: - export CGO_ENABLED=0 && export GOS=linux && export GOARCH=arm64 && ./build.sh + export CGO_ENABLED=0 && export GOS=linux && export GOARCH=arm64 && ./script/build.sh .PHONY: test test: - ./test.sh - -.PHONY: deps -deps: - go get -t -v ./... + ./script/test.sh .PHONY: image image: - docker build -f Dockerfile -t lal:latest . + ./script/build_docker_image.sh .PHONY: clean clean: - rm -rf ./bin ./lal_record ./logs coverage.txt - find ./pkg -name 'lal_record' | xargs rm -rf - find ./pkg -name 'logs' | xargs rm -rf + ./script/clean.sh + +.PHONY: check_versions +check_versions: + ./script/check_versions.sh + +.PHONY: gen_release +gen_release: + ./script/gen_release.sh + +.PHONY: gen_tag +gen_tag: + ./script/gen_tag.sh .PHONY: all all: build test diff --git a/run_docker.sh b/run_docker.sh deleted file mode 100755 index 17cf6a1..0000000 --- a/run_docker.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -make image -docker run -it -p 8084:8084 -p 8080:8080 -p 1935:1935 -p 5544:5544 -p 8083:8083 lal /lal/bin/lalserver diff --git a/build.sh b/script/build.sh old mode 100755 new mode 100644 similarity index 76% rename from build.sh rename to script/build.sh index 99d9fea..82502be --- a/build.sh +++ b/script/build.sh @@ -1,14 +1,18 @@ #!/usr/bin/env bash #set -x - go env -w GO111MODULE=on +go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct +export GO111MODULE=on +export GOPROXY=https://goproxy.cn,https://goproxy.io,direct +THIS_FILE=$(readlink -f $0) +THIS_DIR=$(dirname $THIS_FILE) +ROOT_DIR=${THIS_DIR}/.. -ROOT_DIR=`pwd` -OUT_DIR=bin +OUT_DIR=${ROOT_DIR}/bin -if [ ! -d ${ROOT_DIR}/${OUT_DIR} ]; then - mkdir ${ROOT_DIR}/${OUT_DIR} +if [ ! -d ${OUT_DIR} ]; then + mkdir ${OUT_DIR} fi #GitTag=`git tag --sort=version:refname | tail -n 1` @@ -33,14 +37,14 @@ LDFlags=" \ #-X 'github.com/q191201771/lal/pkg/logic.webUITpl=${WebUITpl}' \ echo "build" ${ROOT_DIR}/app/lalserver "..." -cd ${ROOT_DIR}/app/lalserver && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/${OUT_DIR}/lalserver -#cd ${ROOT_DIR}/app/lalserver && go build -race -ldflags "$LDFlags" -o ${ROOT_DIR}/${OUT_DIR}/lalserver.debug +cd ${ROOT_DIR}/app/lalserver && go build -ldflags "$LDFlags" -o ${OUT_DIR}/lalserver +#cd ${ROOT_DIR}/app/lalserver && go build -race -ldflags "$LDFlags" -o ${OUT_DIR}/lalserver.debug for file in `ls ${ROOT_DIR}/app/demo` do if [ -d ${ROOT_DIR}/app/demo/${file} ]; then echo "build" ${ROOT_DIR}/app/demo/${file} "..." - cd ${ROOT_DIR}/app/demo/${file} && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/${OUT_DIR}/${file} + cd ${ROOT_DIR}/app/demo/${file} && go build -ldflags "$LDFlags" -o ${OUT_DIR}/${file} fi done @@ -49,11 +53,11 @@ if [ -d "./playground" ]; then do if [ -d ${ROOT_DIR}/playground/${file} ]; then echo "build" ${ROOT_DIR}/playgound/${file} "..." - cd ${ROOT_DIR}/playground/${file} && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/${OUT_DIR}/${file} + cd ${ROOT_DIR}/playground/${file} && go build -ldflags "$LDFlags" -o ${OUT_DIR}/${file} fi done fi -${ROOT_DIR}/${OUT_DIR}/lalserver -v && -ls -lrt ${ROOT_DIR}/${OUT_DIR} && +${OUT_DIR}/lalserver -v && +ls -lrt ${OUT_DIR} && echo 'build done.' diff --git a/script/build_docker_image.sh b/script/build_docker_image.sh new file mode 100644 index 0000000..91d9a66 --- /dev/null +++ b/script/build_docker_image.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +#set -x +go env -w GO111MODULE=on +go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct +export GO111MODULE=on +export GOPROXY=https://goproxy.cn,https://goproxy.io,direct +THIS_FILE=$(readlink -f $0) +THIS_DIR=$(dirname $THIS_FILE) +ROOT_DIR=${THIS_DIR}/.. + +cd ${ROOT_DIR} +docker build -f Dockerfile -t lal:latest . diff --git a/check_versions.sh b/script/check_versions.sh similarity index 57% rename from check_versions.sh rename to script/check_versions.sh index a38dc86..ef13da7 100644 --- a/check_versions.sh +++ b/script/check_versions.sh @@ -14,7 +14,7 @@ # 已检查的git commit hash id, 或者tag号 # 本地代码会和该版本对比 # 该变量由我手动更新 -checked_git_ver="v0.35.4" +checked_git_ver="v0.35.41" #checked_git_ver="5dec8415a6cbe76d0ef230a36f25666da024e368" # 关注的文件 @@ -36,8 +36,14 @@ pkg/logic/http_an__lal.html ####################################################################################################################### -#curr_git_ver=`git log --pretty=oneline -n 1 | awk -F ' ' '{print $1}'` -#echo '[ok] current git version: '$curr_git_ver +#set -x +go env -w GO111MODULE=on +go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct +export GO111MODULE=on +export GOPROXY=https://goproxy.cn,https://goproxy.io,direct +THIS_FILE=$(readlink -f $0) +THIS_DIR=$(dirname $THIS_FILE) +ROOT_DIR=${THIS_DIR}/.. compare_with_git_ver=$checked_git_ver @@ -57,22 +63,22 @@ done; echo '----------doc conf----------' -cat pkg/base/t_version.go | grep 'ConfVersion =' -cat ../lalext/lal_website/ConfigBrief.md| grep 'conf_version' | grep ':' +cat ${ROOT_DIR}/pkg/base/t_version.go | grep 'ConfVersion =' +cat ${ROOT_DIR}/../lalext/lal_website/ConfigBrief.md| grep 'conf_version' | grep ':' echo '----------doc http api----------' -cat pkg/base/t_version.go | grep 'HttpApiVersion =' -cat ../lalext/lal_website/HTTPAPI.md| grep 'HttpApiVersion' | grep ':' +cat ${ROOT_DIR}/pkg/base/t_version.go | grep 'HttpApiVersion =' +cat ${ROOT_DIR}/../lalext/lal_website/HTTPAPI.md| grep 'HttpApiVersion' | grep ':' echo '----------doc http notify----------' -cat pkg/base/t_version.go | grep 'HttpNotifyVersion =' -cat ../lalext/lal_website/HTTPNotify.md| grep 'HttpNotifyVersion' | grep ':' +cat ${ROOT_DIR}/pkg/base/t_version.go | grep 'HttpNotifyVersion =' +cat ${ROOT_DIR}/../lalext/lal_website/HTTPNotify.md| grep 'HttpNotifyVersion' | grep ':' echo '----------doc http web ui----------' -cat pkg/base/t_version.go | grep 'HttpWebUiVersion =' -cat ../lalext/lal_website/http_web_ui.md| grep 'HttpWebUiVersion' | grep ':' +cat ${ROOT_DIR}/pkg/base/t_version.go | grep 'HttpWebUiVersion =' +cat ${ROOT_DIR}/../lalext/lal_website/http_web_ui.md| grep 'HttpWebUiVersion' | grep ':' echo '----------doc go version----------' -cat go.mod | grep 'go' | grep -v 'module' | grep -v 'require' -cat README.md | grep 'make sure that Go version' -cat ../lalext/lal_website/ThirdDeps.md | grep 'Go版本需要' +cat ${ROOT_DIR}/go.mod | grep 'go' | grep -v 'module' | grep -v 'require' +cat ${ROOT_DIR}/README.md | grep 'make sure that Go version' +cat ${ROOT_DIR}/../lalext/lal_website/ThirdDeps.md | grep 'Go版本需要' diff --git a/script/clean.sh b/script/clean.sh new file mode 100644 index 0000000..c8f7dca --- /dev/null +++ b/script/clean.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +#set -x +go env -w GO111MODULE=on +go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct +export GO111MODULE=on +export GOPROXY=https://goproxy.cn,https://goproxy.io,direct +THIS_FILE=$(readlink -f $0) +THIS_DIR=$(dirname $THIS_FILE) +ROOT_DIR=${THIS_DIR}/.. + +cd ${ROOT_DIR} +rm -rf ./release ./bin ./lal_record ./logs coverage.txt +find ./pkg -name 'lal_record' | xargs rm -rf +find ./pkg -name 'logs' | xargs rm -rf diff --git a/gen_release.sh b/script/gen_release.sh old mode 100755 new mode 100644 similarity index 67% rename from gen_release.sh rename to script/gen_release.sh index 3f4b884..b22635a --- a/gen_release.sh +++ b/script/gen_release.sh @@ -15,36 +15,43 @@ MAPPING_GOOS=("linux" "windows" "darwin" "darwin" "linux" "linux") MAPPING_GOARCH=( "amd64" "amd64" "amd64" "arm64" "arm" "arm64") MAPPING_EXE=("lalserver" "lalserver.exe" "lalserver" "lalserver" "lalserver" "lalserver") +####################################################################################################################### #set -x +go env -w GO111MODULE=on +go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct +export GO111MODULE=on +export GOPROXY=https://goproxy.cn,https://goproxy.io,direct +THIS_FILE=$(readlink -f $0) +THIS_DIR=$(dirname $THIS_FILE) +ROOT_DIR=${THIS_DIR}/.. -ROOT_DIR=`pwd` -OUT_DIR=release +OUT_DIR=${ROOT_DIR}/release v=`git tag --sort=version:refname | tail -n 1` prefix=lal_${v}_ -rm -rf ${ROOT_DIR}/${OUT_DIR} +rm -rf ${OUT_DIR} # 创建目录 for name in ${NAMES[@]}; do - mkdir -p ${ROOT_DIR}/${OUT_DIR}/${prefix}${name}/bin - mkdir -p ${ROOT_DIR}/${OUT_DIR}/${prefix}${name}/conf + mkdir -p ${OUT_DIR}/${prefix}${name}/bin + mkdir -p ${OUT_DIR}/${prefix}${name}/conf done # README.txt for name in ${NAMES[@]}; do - echo ${v} >> ${ROOT_DIR}/${OUT_DIR}/${prefix}${name}/README.txt - echo 'github: https://github.com/q191201771/lal ' >> ${ROOT_DIR}/${OUT_DIR}/${prefix}${name}/README.txt - echo 'doc: https://pengrl.com/lal ' >> ${ROOT_DIR}/${OUT_DIR}/${prefix}${name}/README.txt + echo ${v} >> ${OUT_DIR}/${prefix}${name}/README.txt + echo 'github: https://github.com/q191201771/lal ' >> ${OUT_DIR}/${prefix}${name}/README.txt + echo 'doc: https://pengrl.com/lal ' >> ${OUT_DIR}/${prefix}${name}/README.txt done # conf/ for name in ${NAMES[@]}; do - cp conf/lalserver.conf.json conf/cert.pem conf/key.pem ${ROOT_DIR}/${OUT_DIR}/${prefix}${name}/conf + cp conf/lalserver.conf.json conf/cert.pem conf/key.pem ${OUT_DIR}/${prefix}${name}/conf done # 编译不同架构和操作系统 @@ -72,11 +79,11 @@ do printf "build %s(%s %s)...\n" "${NAMES[$i]}" "${MAPPING_GOOS[$i]}" "${MAPPING_GOARCH[$i]}" export GOOS=${MAPPING_GOOS[$i]} export GOARCH=${MAPPING_GOARCH[$i]} - cd ${ROOT_DIR}/app/lalserver && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/${OUT_DIR}/${prefix}${NAMES[$i]}/bin/${MAPPING_EXE[$i]} + cd ${ROOT_DIR}/app/lalserver && go build -ldflags "$LDFlags" -o ${OUT_DIR}/${prefix}${NAMES[$i]}/bin/${MAPPING_EXE[$i]} done # 打zip包 -cd ${ROOT_DIR}/${OUT_DIR} +cd ${OUT_DIR} for name in ${NAMES[@]}; do zip -r ${prefix}${name}.zip ${prefix}${name} diff --git a/gen_tag.sh b/script/gen_tag.sh old mode 100755 new mode 100644 similarity index 69% rename from gen_tag.sh rename to script/gen_tag.sh index 6a16723..2493bd7 --- a/gen_tag.sh +++ b/script/gen_tag.sh @@ -11,9 +11,16 @@ # 3. 执行gen_tag.sh #set -x +go env -w GO111MODULE=on +go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct +export GO111MODULE=on +export GOPROXY=https://goproxy.cn,https://goproxy.io,direct +THIS_FILE=$(readlink -f $0) +THIS_DIR=$(dirname $THIS_FILE) +ROOT_DIR=${THIS_DIR}/.. # CHANGELOG.md中的版本号 -NewVersion=`cat CHANGELOG.md| grep '#### v' | head -n 1 | awk '{print $2}'` +NewVersion=`cat ${ROOT_DIR}/CHANGELOG.md| grep '#### v' | head -n 1 | awk '{print $2}'` echo 'newest version in CHANGELOG.md: ' $NewVersion # git tag中的版本号 @@ -21,7 +28,7 @@ GitTag=`git tag --sort=version:refname | tail -n 1` echo "newest version in git tag: " $GitTag # 源码中的版本号 -FileVersion=`cat pkg/base/t_version.go | grep 'const LalVersion' | awk -F\" '{print $2}'` +FileVersion=`cat ${ROOT_DIR}/pkg/base/t_version.go | grep 'const LalVersion' | awk -F\" '{print $2}'` echo "newest version in t_version.go: " $FileVersion # CHANGELOG.md和源码中的不一致,更新源码,并提交修改 @@ -29,8 +36,8 @@ if [ "$NewVersion" == "$FileVersion" ];then echo 'same tag, noop.' else echo 'update t_version.go' - gsed -i "/^const LalVersion/cconst LalVersion = \"${NewVersion}\"" pkg/base/t_version.go - git add pkg/base/t_version.go + gsed -i "/^const LalVersion/cconst LalVersion = \"${NewVersion}\"" ${ROOT_DIR}/pkg/base/t_version.go + git add ${ROOT_DIR}/pkg/base/t_version.go git commit -m "${NewVersion} -> t_version.go" git push fi diff --git a/script/run_docker.sh b/script/run_docker.sh new file mode 100644 index 0000000..0fba5a4 --- /dev/null +++ b/script/run_docker.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +#set -x +go env -w GO111MODULE=on +go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct +export GO111MODULE=on +export GOPROXY=https://goproxy.cn,https://goproxy.io,direct +THIS_FILE=$(readlink -f $0) +THIS_DIR=$(dirname $THIS_FILE) +ROOT_DIR=${THIS_DIR}/.. + +cd ${ROOT_DIR} +docker build -f Dockerfile -t lal:latest . +docker run -it -p 8084:8084 -p 8080:8080 -p 1935:1935 -p 5544:5544 -p 8083:8083 lal /lal/bin/lalserver diff --git a/showdeps.sh b/script/showdeps.sh old mode 100755 new mode 100644 similarity index 69% rename from showdeps.sh rename to script/showdeps.sh index 932542e..c57d081 --- a/showdeps.sh +++ b/script/showdeps.sh @@ -6,7 +6,16 @@ # hls httpflv rtmp rtprtcp sdp # base aac avc hevc -for d in $(go list ./pkg/...); do +#set -x +go env -w GO111MODULE=on +go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct +export GO111MODULE=on +export GOPROXY=https://goproxy.cn,https://goproxy.io,direct +THIS_FILE=$(readlink -f $0) +THIS_DIR=$(dirname $THIS_FILE) +ROOT_DIR=${THIS_DIR}/.. + +for d in $(go list ${ROOT_DIR}/pkg/...); do echo "-----"$d"-----" # 只看依赖lal自身的哪些package # package依赖自身这个package的过滤掉 diff --git a/script/test.sh b/script/test.sh new file mode 100644 index 0000000..88c3107 --- /dev/null +++ b/script/test.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +#set -x +go env -w GO111MODULE=on +go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct +export GO111MODULE=on +export GOPROXY=https://goproxy.cn,https://goproxy.io,direct +THIS_FILE=$(readlink -f $0) +THIS_DIR=$(dirname $THIS_FILE) +ROOT_DIR=${THIS_DIR}/.. + +cd ${ROOT_DIR} + +echo '-----add_src_license-----' +if command -v add_src_license >/dev/null 2>&1; then + add_src_license -d ${ROOT_DIR} -e 191201771@qq.com -n Chef +else + echo 'CHEFNOTICEME add_src_license not exist!' +fi + +echo '-----gofmt-----' +if command -v gofmt >/dev/null 2>&1; then + gofmt -s -l -w ${ROOT_DIR} +else + echo 'CHEFNOTICEME gofmt not exist!' +fi + +echo '-----goimports-----' +if command -v goimports >/dev/null 2>&1; then + goimports -l ${ROOT_DIR} + goimports -w ${ROOT_DIR} +else + echo 'CHEFNOTICEME goimports not exist!' +fi + +echo '-----go vet-----' +for d in $(go list ${ROOT_DIR}/... | grep -v vendor); do + if command -v go >/dev/null 2>&1; then + go vet $d + else + echo 'CHEFNOTICEME go vet not exist' + fi +done + +# 跑 go test 生成测试覆盖率 +echo "-----CI coverage-----" + +## 从网上下载测试用的flv文件 +if [ ! -s "${ROOT_DIR}/testdata/test.flv" ]; then + if [ ! -d "${ROOT_DIR}/testdata" ]; then + mkdir "${ROOT_DIR}/testdata" + fi + wget https://github.com/q191201771/doc/raw/master/av/wontcry30s.flv -O ${ROOT_DIR}/testdata/test.flv + if [ ! -s "${ROOT_DIR}/testdata/test.flv" ]; then + wget https://pengrl.com/images/other/wontcry30s.flv -O ${ROOT_DIR}/testdata/test.flv + fi +fi + +## 拷贝测试依赖的文件 +cp ${ROOT_DIR}/conf/lalserver.conf.json.tmpl ${ROOT_DIR}/testdata/lalserver.conf.json +mkdir ${ROOT_DIR}/testdata/conf +cp ${ROOT_DIR}/conf/cert.pem ${ROOT_DIR}/conf/key.pem ${ROOT_DIR}/testdata/conf/ +cp ${ROOT_DIR}/conf/cert.pem ${ROOT_DIR}/conf/key.pem ${ROOT_DIR}/testdata/conf/ + +## 执行所有pkg里的单元测试,并生成测试覆盖文件 +echo "" > coverage.txt +for d in $(go list ${ROOT_DIR}/... | grep -v vendor | grep pkg); do + go test -race -coverprofile=profile.out -covermode=atomic $d + if [ -f profile.out ]; then + cat profile.out >> coverage.txt + rm profile.out + fi +done + +## 删除测试生成的垃圾文件 +find ${ROOT_DIR}/pkg -name 'lal_record' | xargs rm -rf +find ${ROOT_DIR}/pkg -name 'logs' | xargs rm -rf + +echo 'done.' diff --git a/test.sh b/test.sh deleted file mode 100755 index 13c6c4e..0000000 --- a/test.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env bash - -#set -x - -go env -w GO111MODULE=on - -echo '-----add_src_license-----' -if command -v add_src_license >/dev/null 2>&1; then - add_src_license -d ./ -e 191201771@qq.com -n Chef -else - echo 'CHEFNOTICEME add_src_license not exist!' -fi - -echo '-----gofmt-----' -if command -v gofmt >/dev/null 2>&1; then - gofmt -s -l -w ./ -else - echo 'CHEFNOTICEME gofmt not exist!' -fi - -echo '-----goimports-----' -if command -v goimports >/dev/null 2>&1; then - goimports -l ./ - goimports -w ./ -else - echo 'CHEFNOTICEME goimports not exist!' -fi - -echo '-----go vet-----' -for d in $(go list ./... | grep -v vendor); do - if command -v go >/dev/null 2>&1; then - go vet $d - else - echo 'CHEFNOTICEME go vet not exist' - fi -done - -# 跑 go test 生成测试覆盖率 -echo "-----CI coverage-----" - -## 从网上下载测试用的flv文件 -if [ ! -s "./testdata/test.flv" ]; then - if [ ! -d "./testdata" ]; then - mkdir "./testdata" - fi - wget https://github.com/q191201771/doc/raw/master/av/wontcry30s.flv -O ./testdata/test.flv - if [ ! -s "./testdata/test.flv" ]; then - wget https://pengrl.com/images/other/wontcry30s.flv -O ./testdata/test.flv - fi -fi - -## 拷贝测试依赖的文件 -cp ./conf/lalserver.conf.json.tmpl ./testdata/lalserver.conf.json -mkdir "./testdata/conf" -cp ./conf/cert.pem ./conf/key.pem ./testdata/conf/ -cp ./conf/cert.pem ./conf/key.pem ./testdata/conf/ - -## 执行所有pkg里的单元测试,并生成测试覆盖文件 -echo "" > coverage.txt -for d in $(go list ./... | grep -v vendor | grep pkg); do - go test -race -coverprofile=profile.out -covermode=atomic $d - if [ -f profile.out ]; then - cat profile.out >> coverage.txt - rm profile.out - fi -done - -## 删除测试生成的垃圾文件 -find ./pkg -name 'lal_record' | xargs rm -rf -find ./pkg -name 'logs' | xargs rm -rf - -echo 'done.'