github.com/jk-he/cni@v0.8.1/test.sh (about) 1 #!/usr/bin/env bash 2 set -euo pipefail 3 4 # switch into the repo root directory 5 cd "$(dirname $0)" 6 7 PKGS=${PKGS:-$(go list ./... | xargs echo)} 8 9 echo -n "Running tests " 10 function testrun { 11 bash -c "umask 0; PATH=$PATH go test $@" 12 } 13 if [ ! -z "${COVERALLS:-""}" ]; then 14 # coverage profile only works per-package 15 echo "with coverage profile generation..." 16 i=0 17 for t in ${PKGS}; do 18 testrun "-covermode set -coverprofile ${i}.coverprofile ${t}" 19 i=$((i+1)) 20 done 21 gover 22 goveralls -service=travis-ci -coverprofile=gover.coverprofile 23 else 24 echo "without coverage profile generation..." 25 for t in ${PKGS}; do 26 testrun "${t}" 27 done 28 fi 29 30 echo "Checking gofmt..." 31 fmtRes=$(go fmt ${PKGS}) 32 if [ -n "${fmtRes}" ]; then 33 echo -e "go fmt checking failed:\n${fmtRes}" 34 exit 255 35 fi 36 37 echo "Checking govet..." 38 vetRes=$(go vet ${PKGS}) 39 if [ -n "${vetRes}" ]; then 40 echo -e "go vet checking failed:\n${vetRes}" 41 exit 255 42 fi 43 44 echo "Checking license header..." 45 licRes=$( 46 for file in $(find . -type f -iname '*.go'); do 47 head -n1 "${file}" | grep -Eq "(Copyright|generated)" || echo -e " ${file}" 48 done 49 ) 50 if [ -n "${licRes}" ]; then 51 echo -e "license header checking failed:\n${licRes}" 52 exit 255 53 fi 54 55 echo "Success"