Fix scan unit tests (#253)

This commit is contained in:
Brendan Le Glaunec
2020-01-17 09:47:38 +01:00
committed by GitHub
parent 04ab1cfc8d
commit 8349bc7c3a
+12 -10
View File
@@ -17,13 +17,13 @@ type nmapMock struct {
mock.Mock mock.Mock
} }
func (m *nmapMock) Run() (*nmap.Run, error) { func (m *nmapMock) Run() (*nmap.Run, []string, error) {
args := m.Called() args := m.Called()
if args.Get(0) != nil { if args.Get(0) != nil && args.Get(1) != nil {
return args.Get(0).(*nmap.Run), args.Error(1) return args.Get(0).(*nmap.Run), args.Get(1).([]string), args.Error(2)
} }
return nil, args.Error(1) return nil, nil, args.Error(2)
} }
var ( var (
@@ -77,7 +77,7 @@ func TestScan(t *testing.T) {
removePath: true, removePath: true,
ports: []string{"80"}, ports: []string{"80"},
expectedErr: errors.New("unable to create network scanner: 'nmap' binary was not found"), expectedErr: errors.New("unable to create network scanner: nmap binary was not found"),
}, },
} }
@@ -107,8 +107,9 @@ func TestInternalScan(t *testing.T) {
tests := []struct { tests := []struct {
description string description string
nmapResult *nmap.Run nmapResult *nmap.Run
nmapError error nmapWarnings []string
nmapError error
expectedStreams []Stream expectedStreams []Stream
expectedErr error expectedErr error
@@ -294,8 +295,9 @@ func TestInternalScan(t *testing.T) {
{ {
description: "scan failed", description: "scan failed",
nmapError: errors.New("scan failed"), nmapError: errors.New("scan failed"),
expectedErr: errors.New("error while scanning network: scan failed"), nmapWarnings: []string{"invalid host"},
expectedErr: errors.New("error while scanning network: scan failed"),
}, },
} }
@@ -303,7 +305,7 @@ func TestInternalScan(t *testing.T) {
t.Run(test.description, func(t *testing.T) { t.Run(test.description, func(t *testing.T) {
nmapMock := &nmapMock{} nmapMock := &nmapMock{}
nmapMock.On("Run").Return(test.nmapResult, test.nmapError) nmapMock.On("Run").Return(test.nmapResult, test.nmapWarnings, test.nmapError)
scanner := &Scanner{ scanner := &Scanner{
term: disgo.NewTerminal(disgo.WithDefaultOutput(ioutil.Discard)), term: disgo.NewTerminal(disgo.WithDefaultOutput(ioutil.Discard)),