language: go

go:
    - "1.13.x"
    - "1.14.x"
    - master

os:
  - linux

install:
    - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get -qq update       ; fi
    - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo modprobe nfnetlink_queue ; fi
    - go get golang.org/x/lint/golint
    - go get -d -t ./...

before_script:
    - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo ip6tables -I OUTPUT -p ipv6-icmp -j NFQUEUE --queue-num 100 ; fi
    - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo iptables -I OUTPUT -p icmp -j NFQUEUE --queue-num 100       ; fi

script:
    - go vet ./...
    - golint -set_exit_status $(go list ./... | grep -v internal/unix)
    - go test -v -race ./...
    - go test -c -tags integration .
    - |
        ping6 -c 10 -i 2 2606:4700:4700::1111 &
        export PING6_PID=$!
    - |
        ping -c 10 -i 2 1.1.1.1 &
        export PING4_PID=$!
    - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo ./go-nfqueue.test -test.v ; fi
    - if [[ $(ps cax | grep $PING4_PID) ]]; then kill -9 $PING4_PID ; fi
    - if [[ $(ps cax | grep $PING6_PID) ]]; then kill -9 $PING6_PID ; fi
