From 023df5410e853637cb45e102aa882baaec7de5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Fl=C3=B6tzinger?= Date: Thu, 19 Aug 2021 01:43:26 +0200 Subject: [PATCH 1/7] Create test.yml --- .github/workflows/test.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c6e0998 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,35 @@ +name: test + +on: + push: + branches: [ master ] + pull_request: + paths: + - '**.go' + +jobs: + go_test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + + - name: Install goveralls + run: go install github.com/mattn/goveralls@latest + + - name: Install nmap + run: sudo apt install -y nmap + + - name: Test + run: go test -coverprofile=c.out ./... + + - name: Create coverage report + run: go tool cover -func=c.out + + - name: Send coverage report + env: + COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: goveralls -coverprofile=c.out -service=github From b06374c63fd36fce23af6b510b3137f714ba4b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Fl=C3=B6tzinger?= Date: Thu, 19 Aug 2021 13:55:31 +0200 Subject: [PATCH 2/7] Create build.yml --- .github/workflows/build.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..9879608 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,22 @@ +name: build + +on: + push: + branches: [ master ] + pull_request: + paths: + - 'examples/*' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + + - name: Build examples + run: for dir in examples/*/; do go build -o $dir/bin $dir/main.go; done + From e1d7cf534ab73d066e095f3d017fc1654deb40a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Fl=C3=B6tzinger?= Date: Thu, 19 Aug 2021 14:04:36 +0200 Subject: [PATCH 3/7] Update README.md --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f0eaf53..9638057 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,16 @@ - - + + - - + + + + Coverage Status + +

This library aims at providing idiomatic `nmap` bindings for go developers, in order to make it easier to write security audit tools using golang. From ac17330dce2d7a911b9bc87835756523a8875cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Fl=C3=B6tzinger?= Date: Thu, 19 Aug 2021 15:11:47 +0200 Subject: [PATCH 4/7] Remove travis CI file --- .travis.yml | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f2bce15..0000000 --- a/.travis.yml +++ /dev/null @@ -1,24 +0,0 @@ -dist: trusty -sudo: required -language: go - -go: -- 1.15.x - -before_install: -- sudo apt-get install -y nmap -- go mod tidy -- go get github.com/mattn/goveralls - -script: -# Run unit tests -- go test -v -covermode=count -coverprofile=coverage.out -- $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken=$COVERALLS_TOKEN -# Ensure the examples compile -- for dir in examples/*/; do go build -o $dir/bin $dir/main.go; done -notifications: - email: - recipients: - - brendan.le-glaunec@epitech.eu - on_success: never - on_failure: always From 77f28efd3b74bbb89a9506ffcad732e40648ed0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Fl=C3=B6tzinger?= Date: Thu, 19 Aug 2021 17:57:50 +0200 Subject: [PATCH 5/7] Speed up testing process --- nmap_test.go | 2 +- tests/scripts/fake_nmap_delay.sh | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/nmap_test.go b/nmap_test.go index e75a6ae..be64b9c 100644 --- a/nmap_test.go +++ b/nmap_test.go @@ -287,7 +287,7 @@ func TestRunWithProgress(t *testing.T) { compareWholeRun: true, expectedResult: r, - expectedProgress: []float32{56.66, 81.95, 87.84, 94.43, 97.76, 97.76}, + expectedProgress: []float32{3.22, 56.66, 77.02, 81.95, 86.79, 87.84}, expectedErr: nil, }, } diff --git a/tests/scripts/fake_nmap_delay.sh b/tests/scripts/fake_nmap_delay.sh index 73bd33e..48d090a 100755 --- a/tests/scripts/fake_nmap_delay.sh +++ b/tests/scripts/fake_nmap_delay.sh @@ -1,7 +1,12 @@ #!/bin/bash input=$1 +count=0 while IFS= read -r line do echo "$line" - sleep .5 + if [ $count -gt 13 ] && [ $count -lt 23 ] + then + sleep 1 + fi + (( count++ )) done < "$input" From 78008cb165098d18cf67fd65c6422490a17ab8d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Fl=C3=B6tzinger?= Date: Fri, 20 Aug 2021 14:09:32 +0200 Subject: [PATCH 6/7] Apply suggestions from code review Co-authored-by: Brendan Le Glaunec --- .github/workflows/build.yml | 33 +++++++++++++----- .github/workflows/test.yml | 69 +++++++++++++++++++++++++------------ 2 files changed, 71 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9879608..48f3ceb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,15 +8,30 @@ on: - 'examples/*' jobs: - build: + check: runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v2 - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.16 + - name: Check out source code + uses: actions/checkout@v2 + + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + # Here, we simply print the exact go version, to have it as part of the + # action's output, which might be convenient. + - name: Print Go version + run: go version - - name: Build examples - run: for dir in examples/*/; do go build -o $dir/bin $dir/main.go; done - + - name: Build examples + run: for dir in examples/*/; do go build -o $dir/bin $dir/main.go; done diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c6e0998..03a4d40 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,28 +8,53 @@ on: - '**.go' jobs: - go_test: + check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.16 - - - name: Install goveralls - run: go install github.com/mattn/goveralls@latest - - - name: Install nmap - run: sudo apt install -y nmap - - - name: Test - run: go test -coverprofile=c.out ./... - - - name: Create coverage report - run: go tool cover -func=c.out + - name: Check out source code + uses: actions/checkout@v2 + + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + # Here, we simply print the exact go version, to have it as part of the + # action's output, which might be convenient. + - name: Print Go version + run: go version - - name: Send coverage report - env: - COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: goveralls -coverprofile=c.out -service=github + # This check makes sure that the `go.mod` and `go.sum` files for Go + # modules are always up-to-date. + - name: Verify Go modules + run: go mod tidy && git status && git --no-pager diff && git diff-index --quiet HEAD -- + + # This check makes sure that the source code is formatted according to the + # Go standard `go fmt` formatting. + - name: Verify source code formatting + run: go fmt ./... && git status && git --no-pager diff && git diff-index --quiet HEAD -- + + - name: Install nmap + run: sudo apt install -y nmap + + - name: Test + run: go test -coverprofile=c.out ./... + + - name: Install goveralls + run: go install github.com/mattn/goveralls@latest + + - name: Create coverage report + run: go tool cover -func=c.out + + - name: Send coverage report + env: + COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: goveralls -coverprofile=c.out -service=github From 3f81fe3a50535c1315865e568225f04558f5a892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Fl=C3=B6tzinger?= Date: Mon, 23 Aug 2021 13:05:46 +0200 Subject: [PATCH 7/7] Format iflist_test.go file --- iflist_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iflist_test.go b/iflist_test.go index 2b4d1da..47466a2 100644 --- a/iflist_test.go +++ b/iflist_test.go @@ -29,7 +29,7 @@ func TestConvertInterface(t *testing.T) { assert.Equal(t, "loopback", i.Type) assert.False(t, i.Up) assert.Equal(t, 65536, i.MTU) - assert.Equal(t, net.HardwareAddr{0x11,0x11,0x11,0x11,0x11,0x11}, i.Mac) + assert.Equal(t, net.HardwareAddr{0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, i.Mac) } func TestConvertRoute(t *testing.T) { @@ -40,4 +40,4 @@ func TestConvertRoute(t *testing.T) { assert.Equal(t, "wlp5s0", r.Device) assert.Equal(t, 600, r.Metric) assert.Equal(t, net.ParseIP("192.168.0.1"), r.Gateway) -} \ No newline at end of file +}