This commit is contained in:
crusader 2018-08-30 03:37:40 +09:00
parent 42c3ad9ab4
commit f15521f202
4 changed files with 63 additions and 30 deletions

View File

@ -6,10 +6,10 @@ import (
omd "git.loafle.net/overflow/model/discovery" omd "git.loafle.net/overflow/model/discovery"
omu "git.loafle.net/overflow/model/util" omu "git.loafle.net/overflow/model/util"
"git.loafle.net/overflow_scanner/probe/discovery/protocol/mdns"
"git.loafle.net/overflow_scanner/probe/discovery/protocol/upnp"
"git.loafle.net/overflow_scanner/probe/discovery/session" "git.loafle.net/overflow_scanner/probe/discovery/session"
"git.loafle.net/overflow_scanner/probe/discovery/types" "git.loafle.net/overflow_scanner/probe/discovery/types"
"git.loafle.net/overflow_scanner/probe/internal/protocol/mdns"
"git.loafle.net/overflow_scanner/probe/internal/protocol/upnp"
) )
type Discoverer interface { type Discoverer interface {

View File

@ -0,0 +1,19 @@
package discovery
import "git.loafle.net/overflow_scanner/probe/discovery/types"
func MockDiscoveryRequest(requesterID string, requestType types.DiscoveryRequestType, params ...interface{}) *mockDiscoveryRequest {
m := &mockDiscoveryRequest{}
m.requesterID = requesterID
m.requestType = requestType
m.params = params
return m
}
type mockDiscoveryRequest struct {
ofDiscoveryRequest
}
func (dr *mockDiscoveryRequest) SendMessage(messageType types.DiscoveryMessageType, data interface{}, err error) {
}

View File

@ -6,26 +6,33 @@ import (
omd "git.loafle.net/overflow/model/discovery" omd "git.loafle.net/overflow/model/discovery"
omm "git.loafle.net/overflow/model/meta" omm "git.loafle.net/overflow/model/meta"
"git.loafle.net/overflow_scanner/probe/discovery"
"git.loafle.net/overflow_scanner/probe/discovery/session" "git.loafle.net/overflow_scanner/probe/discovery/session"
"git.loafle.net/overflow_scanner/probe/discovery/types"
"github.com/grandcat/zeroconf" "github.com/grandcat/zeroconf"
) )
func TestScan(t *testing.T) { func TestScan(t *testing.T) {
s := session.MockDiscoverySession() s := session.MockDiscoverySession()
s.InitWithDiscoverHost( s.InitWithRequest(
nil, discovery.MockDiscoveryRequest(
&omd.Zone{ "testRequester",
Network: "192.168.1.0/24", types.DiscoveryRequestTypeHost,
Iface: "enp3s0", []interface{}{
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4), &omd.Zone{
Address: "192.168.1.101", Network: "192.168.1.0/24",
Mac: "44:8a:5b:f1:f1:f3", Iface: "enp3s0",
}, MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
&omd.DiscoverHost{ Address: "192.168.1.101",
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4), Mac: "44:8a:5b:f1:f1:f3",
FirstScanRange: "192.168.1.1", },
LastScanRange: "192.168.1.254", &omd.DiscoverHost{
}, MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
FirstScanRange: "192.168.1.1",
LastScanRange: "192.168.1.254",
},
},
),
) )
type args struct { type args struct {

View File

@ -5,25 +5,32 @@ import (
omd "git.loafle.net/overflow/model/discovery" omd "git.loafle.net/overflow/model/discovery"
omm "git.loafle.net/overflow/model/meta" omm "git.loafle.net/overflow/model/meta"
"git.loafle.net/overflow_scanner/probe/discovery"
"git.loafle.net/overflow_scanner/probe/discovery/session" "git.loafle.net/overflow_scanner/probe/discovery/session"
"git.loafle.net/overflow_scanner/probe/discovery/types"
) )
func TestScan(t *testing.T) { func TestScan(t *testing.T) {
s := session.MockDiscoverySession() s := session.MockDiscoverySession()
s.InitWithDiscoverHost( s.InitWithRequest(
nil, discovery.MockDiscoveryRequest(
&omd.Zone{ "testRequester",
Network: "192.168.1.0/24", types.DiscoveryRequestTypeHost,
Iface: "enp3s0", []interface{}{
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4), &omd.Zone{
Address: "192.168.1.101", Network: "192.168.1.0/24",
Mac: "44:8a:5b:f1:f1:f3", Iface: "enp3s0",
}, MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
&omd.DiscoverHost{ Address: "192.168.1.101",
MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4), Mac: "44:8a:5b:f1:f1:f3",
FirstScanRange: "192.168.1.1", },
LastScanRange: "192.168.1.254", &omd.DiscoverHost{
}, MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
FirstScanRange: "192.168.1.1",
LastScanRange: "192.168.1.254",
},
},
),
) )
type args struct { type args struct {