Skip to content

Commit

Permalink
reconfigured travis-ci and fixed some tests/codes
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 committed Aug 8, 2021
1 parent 0e7ae49 commit 7a11125
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 21 deletions.
28 changes: 16 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
language: go
dist: bionic

go:
- 1.8.x
- 1.16.x

env:
global:
- CC_TEST_REPORTER_ID=9311a4b76692580fa889c7d2476a621b41f7ffb5554b8dabc5e818e572d0602c

before_install:
- sudo apt-get -qq update
- sudo apt-get install -y libpcap-dev
- env

before_script:
- go get github.com/mattn/goveralls
- go get github.com/AlekSi/gocoverutil
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build

before_install:
- sudo apt-get -qq update
- sudo apt-get install -y libpcap-dev
- env

go_import_path: github.com/hyeoncheon/goul

script:
- go build -o goul -ldflags "-X main.buildNumber=`git rev-parse --short HEAD`" ./cmd/goul
- ls -l goul
- ./goul -v
- ./supports/test-gocover.sh
- go test ./... -v
- goveralls -v -service=travis-ci
- >
go mod tidy &&
cat go.mod go.sum &&
go build -o goul -ldflags "-X main.buildNumber=`git rev-parse --short HEAD`" ./cmd/goul &&
ls -l goul &&
./goul -v &&
./supports/test-gocover.sh &&
go test ./... -v &&
goveralls -v -service=travis-ci
# cover.out was generated by test-gocover.sh, github.com/AlekSi/gocoverutil
after_script:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Goul, Virtual Port Mirror over Internet (for Cloud)

[![Build Status](https://travis-ci.org/hyeoncheon/goul.svg?branch=master)](https://travis-ci.org/hyeoncheon/goul)
[![Go Reference](https://pkg.go.dev/badge/github.com/hyeoncheon/goul.svg)](https://pkg.go.dev/github.com/hyeoncheon/goul)
[![Build Status](https://travis-ci.com/hyeoncheon/goul.svg?branch=master)](https://travis-ci.com/hyeoncheon/goul)
[![Go Report Card](https://goreportcard.com/badge/github.com/hyeoncheon/goul)](https://goreportcard.com/report/github.com/hyeoncheon/goul)
[![Code Climate](https://codeclimate.com/github/hyeoncheon/goul/badges/gpa.svg)](https://codeclimate.com/github/hyeoncheon/goul)
[![Coverage Status](https://coveralls.io/repos/github/hyeoncheon/goul/badge.svg?branch=master)](https://coveralls.io/github/hyeoncheon/goul?branch=master)
Expand Down
4 changes: 3 additions & 1 deletion adapters/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ func NewDevice(dev string, isTest bool) (*DeviceAdapter, error) {
Adapter: &goul.BaseAdapter{},
isTest: isTest,
}
a.inactiveHandle, a.err = pcap.NewInactiveHandle(a.device)
if !isTest {
a.inactiveHandle, a.err = pcap.NewInactiveHandle(a.device)
}
return a, a.err
}

Expand Down
34 changes: 31 additions & 3 deletions adapters/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"github.com/hyeoncheon/goul/adapters"
)

func Test_DeviceAdapter_1_NormalFlow(t *testing.T) {
func Test_DeviceAdapter_11_NormalFlowReader(t *testing.T) {
var err error
var adapter goul.Adapter
r := require.New(t)

adapter, err = adapters.NewDevice("eth0", true)
adapter, err = adapters.NewDevice("lo", false)
r.NoError(err)
r.NotNil(adapter)

Expand All @@ -38,6 +38,34 @@ func Test_DeviceAdapter_1_NormalFlow(t *testing.T) {
r.EqualError(err, adapters.ErrCouldNotActivate) // permission denied
r.Contains(adapter.GetError().Error(), "Permission Denied")

adapter.Close()
}

func Test_DeviceAdapter_12_NormalFlowWriterTestmode(t *testing.T) {
var err error
var adapter goul.Adapter
r := require.New(t)

adapter, err = adapters.NewDevice("lo", true)
r.NoError(err)
r.NotNil(adapter)

logger := goul.NewLogger("debug")
err = adapter.SetLogger(logger)
r.NoError(err)

lgr := adapter.GetLogger()
r.NotNil(lgr)

in := make(chan goul.Item)
go func() {
defer func() {
recover()
}()
in <- &goul.ItemGeneric{Meta: "Message", DATA: []byte{1}}
return
}()

done, err := adapter.Write(in, nil) // with testmode
r.NoError(err)
close(in)
Expand All @@ -50,7 +78,7 @@ func Test_DeviceAdapter_2_AdapterSpecific(t *testing.T) {
r := require.New(t)

// get instance as adapters.DeviceAdapter instead of goul.Adapter
adapter, err := adapters.NewDevice("eth0", false)
adapter, err := adapters.NewDevice("lo", false)
r.NoError(err)
r.NotNil(adapter)

Expand Down
8 changes: 5 additions & 3 deletions cmd/goul/run_private_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ func Test_RunServer(t *testing.T) {
isTest: false,
isServer: true,
port: 6060,
device: "bond9",
device: "bond9", // does not exist
filter: "port 80",
}

err := run(svrOpts)
r.EqualError(err, ErrCouldNotStartTheRouter) // permission
r.Error(err)
//r.EqualError(err, ErrCouldNotStartTheRouter) // in my local
//r.EqualError(err, ErrCouldNotCreateDeviceReader) // in travis-ci
}

func Test_RunTestServer(t *testing.T) {
Expand Down Expand Up @@ -62,7 +64,7 @@ func Test_RunClient(t *testing.T) {
isServer: false,
addr: "localhost",
port: 6060,
device: "bond9",
device: "lo",
filter: "port 80",
}

Expand Down
6 changes: 5 additions & 1 deletion utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ func Test_PrintDevices_1_Normal(t *testing.T) {

err = goul.PrintDevices()
if isTravis {
r.Error(err)
// Ah... I don't remember but it seems like this was an workaround
// for Travis CI. but not it works as the same as local env.
// just leave it as is as a history.
//r.Error(err)
r.NoError(err)
} else {
r.NoError(err)
}
Expand Down

0 comments on commit 7a11125

Please sign in to comment.