forked from containernetworking/cni
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·50 lines (42 loc) · 1.14 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
#!/usr/bin/env bash
set -euo pipefail
# switch into the repo root directory
cd "$(dirname $0)"
PKGS=${PKGS:-$(go list ./... | xargs echo)}
echo -n "Running tests "
if [ ! -z "${COVERALLS:-""}" ]; then
# coverage profile only works per-package
echo "with coverage profile generation..."
i=0
for t in ${PKGS}; do
go test -covermode set -coverprofile ${i}.coverprofile "${t}"
i=$((i+1))
done
else
echo "without coverage profile generation..."
go test ${PKGS}
fi
GO_FILES=$(find . -name '*.go' -type f -print)
echo "Checking gofmt..."
fmtRes=$(gofmt -d -e -s ${GO_FILES})
if [ -n "${fmtRes}" ]; then
echo -e "go fmt checking failed:\n${fmtRes}"
exit 255
fi
echo "Checking govet..."
vetRes=$(go vet ${PKGS})
if [ -n "${vetRes}" ]; then
echo -e "go vet checking failed:\n${vetRes}"
exit 255
fi
echo "Checking license header..."
licRes=$(
for file in $(find . -type f -iname '*.go'); do
head -n1 "${file}" | grep -Eq "(Copyright|generated)" || echo -e " ${file}"
done
)
if [ -n "${licRes}" ]; then
echo -e "license header checking failed:\n${licRes}"
exit 255
fi
echo "Success"