Fix scan unit tests (#253)
This commit is contained in:
committed by
GitHub
parent
04ab1cfc8d
commit
8349bc7c3a
+8
-6
@@ -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"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +108,7 @@ func TestInternalScan(t *testing.T) {
|
|||||||
description string
|
description string
|
||||||
|
|
||||||
nmapResult *nmap.Run
|
nmapResult *nmap.Run
|
||||||
|
nmapWarnings []string
|
||||||
nmapError error
|
nmapError error
|
||||||
|
|
||||||
expectedStreams []Stream
|
expectedStreams []Stream
|
||||||
@@ -295,6 +296,7 @@ func TestInternalScan(t *testing.T) {
|
|||||||
description: "scan failed",
|
description: "scan failed",
|
||||||
|
|
||||||
nmapError: errors.New("scan failed"),
|
nmapError: errors.New("scan failed"),
|
||||||
|
nmapWarnings: []string{"invalid host"},
|
||||||
expectedErr: errors.New("error while scanning network: scan failed"),
|
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)),
|
||||||
|
|||||||
Reference in New Issue
Block a user