github.com/john-lin/cni@v0.6.0-rc1.0.20170712150331-b69e640cc0e2/test.sh (about)

     1  #!/usr/bin/env bash
     2  #
     3  # Run all CNI tests
     4  #   ./test
     5  #   ./test -v
     6  #
     7  # Run tests for one package
     8  #   PKG=./libcni ./test
     9  #
    10  set -e
    11  
    12  source ./build.sh
    13  
    14  TESTABLE="libcni pkg/invoke pkg/skel pkg/types pkg/types/current pkg/types/020 pkg/version pkg/version/testhelpers plugins/test/noop"
    15  FORMATTABLE="$TESTABLE"
    16  
    17  # user has not provided PKG override
    18  if [ -z "$PKG" ]; then
    19  	TEST=$TESTABLE
    20  	FMT=$FORMATTABLE
    21  
    22  # user has provided PKG override
    23  else
    24  	# strip out slashes and dots from PKG=./foo/
    25  	TEST=${PKG//\//}
    26  	TEST=${TEST//./}
    27  
    28  	# only run gofmt on packages provided by user
    29  	FMT="$TEST"
    30  fi
    31  
    32  # split TEST into an array and prepend REPO_PATH to each local package
    33  split=(${TEST// / })
    34  TEST=${split[@]/#/${REPO_PATH}/}
    35  
    36  echo -n "Running tests "
    37  function testrun {
    38      sudo -E bash -c "umask 0; PATH=$GOROOT/bin:$(pwd)/bin:$PATH go test -covermode set $@"
    39  }
    40  if [ ! -z "${COVERALLS}" ]; then
    41      echo "with coverage profile generation..."
    42      i=0
    43      for t in ${TEST}; do
    44          testrun "-coverprofile ${i}.coverprofile ${t}"
    45          i=$((i+1))
    46      done
    47      gover
    48      goveralls -service=travis-ci -coverprofile=gover.coverprofile -repotoken=$COVERALLS_TOKEN
    49  else
    50      echo "without coverage profile generation..."
    51      testrun "${TEST}"
    52  fi
    53  
    54  echo "Checking gofmt..."
    55  fmtRes=$(gofmt -l $FMT)
    56  if [ -n "${fmtRes}" ]; then
    57  	echo -e "gofmt checking failed:\n${fmtRes}"
    58  	exit 255
    59  fi
    60  
    61  echo "Checking govet..."
    62  vetRes=$(go vet $TEST)
    63  if [ -n "${vetRes}" ]; then
    64  	echo -e "govet checking failed:\n${vetRes}"
    65  	exit 255
    66  fi
    67  
    68  echo "Checking license header..."
    69  licRes=$(
    70         for file in $(find . -type f -iname '*.go' ! -path './vendor/*'); do
    71                 head -n1 "${file}" | grep -Eq "(Copyright|generated)" || echo -e "  ${file}"
    72         done
    73  )
    74  if [ -n "${licRes}" ]; then
    75         echo -e "license header checking failed:\n${licRes}"
    76         exit 255
    77  fi
    78  
    79  
    80  echo "Success"