forked from q191201771/lal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·70 lines (59 loc) · 1.83 KB
/
test.sh
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
#!/usr/bin/env bash
#set -x
echo '-----add_go_license-----'
if command -v add_go_license >/dev/null 2>&1; then
add_go_license -d ./ -e [email protected] -n Chef
else
echo 'CHEFNOTICEME add_go_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 | grep -v innertest); 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.'