github.com/Tyktechnologies/tyk@v2.9.5+incompatible/bin/ci-test.sh (about)

     1  #!/bin/bash
     2  
     3  TEST_TIMEOUT=5m
     4  
     5  # print a command and execute it
     6  show() {
     7  	echo "$@" >&2
     8  	eval "$@"
     9  }
    10  
    11  fatal() {
    12  	echo "$@" >&2
    13  	exit 1
    14  }
    15  
    16  race=""
    17  if [[ ${LATEST_GO} ]]; then
    18      FMT_FILES=$(gofmt -l . | grep -v vendor)
    19      if [[ -n $FMT_FILES ]]; then
    20          fatal "Run 'gofmt -w' on these files:\n$FMT_FILES"
    21      fi
    22  
    23      echo "gofmt check is ok!"
    24  
    25      IMP_FILES="$(goimports -l . | grep -v vendor)"
    26      if [[ -n $IMP_FILES ]]; then
    27          fatal "Run 'goimports -w' on these files:\n$IMP_FILES"
    28      fi
    29  
    30      echo "goimports check is ok!"
    31  
    32      # Run with race if latest
    33      race="-race"
    34  fi
    35  
    36  PKGS="$(go list ./...)"
    37  
    38  go get -t
    39  
    40  export PKG_PATH=$GOPATH/src/github.com/TykTechnologies/tyk
    41  
    42  # build Go-plugin used in tests
    43  go build ${race} -o ./test/goplugins/goplugins.so -buildmode=plugin ./test/goplugins || fatal "building Go-plugin failed"
    44  
    45  for pkg in $PKGS; do
    46      tags=""
    47  
    48      # TODO: Remove skipRace variable after solving race conditions in tests.
    49      skipRace=false
    50      if [[ ${pkg} == *"grpc" ]]; then
    51          skipRace=true
    52      elif [[ ${pkg} == *"goplugin" ]]; then
    53          tags="-tags 'goplugin'"
    54      fi
    55  
    56      race=""
    57  
    58      # Some tests should not be run with -race. Therefore, test them with penultimate Go version.
    59      # And, test with -race in latest Go version.
    60      if [[ ${LATEST_GO} && ${skipRace} = false ]]; then
    61          race="-race"
    62      fi
    63  
    64      show go test -v ${race} -timeout ${TEST_TIMEOUT} -coverprofile=test.cov $pkg ${tags} || fatal "Test Failed"
    65      show go vet ${tags} $pkg || fatal "go vet errored"
    66  done