-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathgotest.sh
More file actions
executable file
·75 lines (61 loc) · 1.7 KB
/
Copy pathgotest.sh
File metadata and controls
executable file
·75 lines (61 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env sh
###########################################
# go test #
# for Windows/Mac/Linux #
# #
# Version: 1.0 #
# Author: yangbing@camera360.com #
# Date: 2019/07/05 #
###########################################
# 要go test 包名字,如果是mod模式下 module_name/package_name,可修改
arr_test_path_dir_name=(
Command
Controller
Lib
Model
Service
Struct
Test
)
go_app_path=`pwd`
exec_mod="default"
if [[ $# > 0 ]];then
go_app_path=$1
fi
if [[ $# > 1 ]];then
exec_mod="custom"
fi
# PgoTestAppBasePath提供给pgo框架使用,必须设置,conf配置文件夹的上一级目录
export PgoTestAppBasePath=$go_app_path
exec_default () {
test_path_dir=$go_app_path
cover_dir=${test_path_dir}/coverage
if [[ ! -d $cover_dir ]];then
mkdir $cover_dir
fi
if [[ ! -d ${go_app_path}/src ]];then
test_path_dir=${go_app_path}/src
fi
pkg_str=""
cover_pkg=""
for test_path_name in ${arr_test_path_dir_name[@]}
do
pkg_str=${pkg_str}" "${test_path_name}"/..."
if [[ ${cover_pkg} == "" ]];then
cover_pkg=${test_path_name}"/..."
else
cover_pkg=${cover_pkg}","${test_path_name}"/..."
fi
done
go test -coverprofile=${cover_dir}/coverage.data -coverpkg=$cover_pkg $pkg_str
go tool cover -html=${cover_dir}/coverage.data -o ${cover_dir}/coverage.html
go tool cover -func=${cover_dir}/coverage.data -o ${cover_dir}/coverage.txt
}
case "$exec_mod" in
default)
exec_default
;;
custom)
${@:2}
;;
esac