test 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env bash
  2. #
  3. # Run all go-iptables tests
  4. # ./test
  5. # ./test -v
  6. #
  7. # Run tests for one package
  8. # PKG=./unit ./test
  9. # PKG=ssh ./test
  10. #
  11. set -e
  12. # Invoke ./cover for HTML output
  13. COVER=${COVER:-"-cover"}
  14. source ./build
  15. TESTABLE="iptables"
  16. FORMATTABLE="$TESTABLE"
  17. # user has not provided PKG override
  18. if [ -z "$PKG" ]; then
  19. TEST=$TESTABLE
  20. FMT=$FORMATTABLE
  21. # user has provided PKG override
  22. else
  23. # strip out slashes and dots from PKG=./foo/
  24. TEST=${PKG//\//}
  25. TEST=${TEST//./}
  26. # only run gofmt on packages provided by user
  27. FMT="$TEST"
  28. fi
  29. echo "Checking gofmt..."
  30. fmtRes=$(gofmt -l $FMT)
  31. if [ -n "${fmtRes}" ]; then
  32. echo -e "gofmt checking failed:\n${fmtRes}"
  33. exit 255
  34. fi
  35. # split TEST into an array and prepend REPO_PATH to each local package
  36. split=(${TEST// / })
  37. TEST=${split[@]/#/${REPO_PATH}/}
  38. echo "Running tests..."
  39. go test -i ${TEST}
  40. if [[ -z "$SUDO_PERMITTED" ]]; then
  41. echo "Test aborted for safety reasons. Please set the SUDO_PERMITTED variable."
  42. exit 1
  43. fi
  44. sudo -E bash -c "PATH=\$GOROOT/bin:\$PATH go test ${COVER} $@ ${TEST}"
  45. echo "Success"