test 640 B

12345678910111213141516171819202122232425262728293031323334
  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. echo "Checking gofmt..."
  15. fmtRes=$(gofmt -l -s .)
  16. if [ -n "${fmtRes}" ]; then
  17. echo -e "gofmt checking failed:\n${fmtRes}"
  18. exit 255
  19. fi
  20. echo "Running tests..."
  21. bin=$(mktemp)
  22. go test -c -o ${bin} ${COVER} ./iptables/...
  23. if [[ -z "$SUDO_PERMITTED" ]]; then
  24. echo "Test aborted for safety reasons. Please set the SUDO_PERMITTED variable."
  25. exit 1
  26. fi
  27. sudo -E bash -c "${bin} $@ ./iptables/..."
  28. echo "Success"
  29. rm "${bin}"