Skip to content

Commit

Permalink
Merge pull request #2 from vokomarov/feature/travis-ci
Browse files Browse the repository at this point in the history
TravisCI integration
  • Loading branch information
vokomarov committed Mar 8, 2020
2 parents 5f554ef + d5e4bb6 commit e55f87b
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.so
*.dylib
.idea
coverage.out

# Test binary, built with `go test -c`
*.test
Expand Down
44 changes: 44 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions scanner/host/host_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
}
}

0 comments on commit e55f87b

Please sign in to comment.