probe/discovery/protocol/mdns/mdns_test.go

142 lines
3.0 KiB
Go
Raw Normal View History

2018-08-29 12:04:23 +00:00
package mdns
import (
"reflect"
"testing"
2018-09-01 06:07:15 +00:00
"git.loafle.net/overflow_scanner/probe/__test"
2018-08-29 12:09:59 +00:00
"git.loafle.net/overflow_scanner/probe/discovery/session"
2018-08-29 18:37:40 +00:00
"git.loafle.net/overflow_scanner/probe/discovery/types"
2018-08-29 12:04:23 +00:00
"github.com/grandcat/zeroconf"
)
func TestScan(t *testing.T) {
2018-08-31 02:32:25 +00:00
s := session.NewMockDiscoverySession(
"testRequester",
types.DiscoveryRequestTypeHost,
2018-09-01 06:07:15 +00:00
__test.Zone(),
__test.DiscoverHost(__test.DiscoveryConfig(), 1, 254, nil),
2018-08-29 12:09:59 +00:00
)
2018-08-29 12:04:23 +00:00
type args struct {
2018-08-29 12:09:59 +00:00
discoverySession session.DiscoverySession
2018-08-29 12:04:23 +00:00
}
tests := []struct {
2018-08-31 05:15:46 +00:00
name string
args args
wantErr bool
2018-08-29 12:04:23 +00:00
}{
{
name: "1",
args: args{
2018-08-29 12:09:59 +00:00
discoverySession: s,
2018-08-29 12:04:23 +00:00
},
2018-08-31 05:15:46 +00:00
wantErr: false,
2018-08-29 12:04:23 +00:00
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
2018-08-31 05:15:46 +00:00
if err := Scan(tt.args.discoverySession); (err != nil) != tt.wantErr {
t.Errorf("Scan() error = %v, wantErr %v", err, tt.wantErr)
}
2018-08-29 12:04:23 +00:00
})
}
}
func Test_removeDomainName(t *testing.T) {
type args struct {
instance string
domain string
}
tests := []struct {
name string
args args
wantService string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotService := removeDomainName(tt.args.instance, tt.args.domain); gotService != tt.wantService {
t.Errorf("removeDomainName() = %v, want %v", gotService, tt.wantService)
}
})
}
}
func Test_toMeta(t *testing.T) {
type args struct {
text []string
}
tests := []struct {
name string
args args
want map[string]string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := toMeta(tt.args.text); !reflect.DeepEqual(got, tt.want) {
t.Errorf("toMeta() = %v, want %v", got, tt.want)
}
})
}
}
func Test_parseService(t *testing.T) {
type args struct {
service string
}
tests := []struct {
name string
args args
wantName string
wantPortType string
wantCryptoType string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotName, gotPortType, gotCryptoType := parseService(tt.args.service)
if gotName != tt.wantName {
t.Errorf("parseService() gotName = %v, want %v", gotName, tt.wantName)
}
if gotPortType != tt.wantPortType {
t.Errorf("parseService() gotPortType = %v, want %v", gotPortType, tt.wantPortType)
}
if gotCryptoType != tt.wantCryptoType {
t.Errorf("parseService() gotCryptoType = %v, want %v", gotCryptoType, tt.wantCryptoType)
}
})
}
}
func Test_browse(t *testing.T) {
type args struct {
service string
domain string
}
tests := []struct {
name string
args args
want []*zeroconf.ServiceEntry
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := browse(tt.args.service, tt.args.domain)
if (err != nil) != tt.wantErr {
t.Errorf("browse() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("browse() = %v, want %v", got, tt.want)
}
})
}
}