diff --git a/.gitignore b/.gitignore index 9808852..7ce1bf9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.so *.dylib .idea +coverage.out # Test binary, built with `go test -c` *.test diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1ab3cc8 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,44 @@ +language: go + +go: + - '1.14' + +before_install: + - sudo apt-get install libpcap-dev + +install: + - go get golang.org/x/tools/cmd/cover + - go get github.com/mattn/goveralls + - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.6 + +script: + - go test ./... -v -covermode=count -coverprofile=coverage.out + - cat coverage.out | grep -v "main.go" | grep -v "hosts.go" | grep -v "ports.go" > cover.out + - goveralls -coverprofile=cover.out -service=travis-ci + - golangci-lint run + + - export PCAPV=1.9.1 + - wget http://www.tcpdump.org/release/libpcap-$PCAPV.tar.gz + - tar xvf libpcap-$PCAPV.tar.gz + - cd libpcap-$PCAPV + - ./configure --with-pcap=linux + - make + - cd .. + + - CGO_ENABLED=1 GOARCH=amd64 GOOS=linux CGO_LDFLAGS+="-L./libpcap-$PCAPV" go build -ldflags="-s -w" -o out/netshark_linux_x86-64 . + + # TODO. MacOS build + # - GOARCH=amd64 GOOS=darwin go build -o out/netshark_osx . + + - GOARCH=386 GOOS=windows go build -o out/netshark_win32.exe . + - GOARCH=amd64 GOOS=windows go build -o out/netshark_win64.exe . + +deploy: + provider: releases + api_key: + secure: $GITHUB_API_KEY_SECURE + file_glob: true + file: out/* + skip_cleanup: true + on: + tags: true diff --git a/scanner/host/host_test.go b/scanner/host/host_test.go new file mode 100644 index 0000000..852f902 --- /dev/null +++ b/scanner/host/host_test.go @@ -0,0 +1,45 @@ +package host + +import "testing" + +func TestHost_ID(t *testing.T) { + for _, test := range []struct { + IP string + MAC string + ID string + }{ + { + ID: "d41d8cd98f00b204e9800998ecf8427e", + }, + { + IP: "192.168.1.1", + ID: "66efff4c945d3c3b87fc271b47d456db", + }, + { + MAC: "28:6c:07:48:66:be", + ID: "924a7370c8df57b5b3f0a2e0d9d91598", + }, + { + IP: "192.168.1.1", + MAC: "28:6c:07:48:66:be", + ID: "7a48a7ba6494c7eb4c06e4787e9a6a88", + }, + } { + host := Host{ + IP: test.IP, + MAC: test.MAC, + } + + if host.id != "" { + t.Errorf("initial Host ID is not empty") + } + + if host.ID() != test.ID { + t.Errorf("test Host ID [%s] is not equal to actual Host ID [%s]", test.ID, host.ID()) + } + + if host.id == "" { + t.Errorf("Host ID is not cached") + } + } +}