155 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			155 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package mdns
 | |
| 
 | |
| import (
 | |
| 	"reflect"
 | |
| 	"testing"
 | |
| 
 | |
| 	omd "git.loafle.net/overflow/model/discovery"
 | |
| 	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/types"
 | |
| 	"github.com/grandcat/zeroconf"
 | |
| )
 | |
| 
 | |
| func TestScan(t *testing.T) {
 | |
| 	s := session.MockDiscoverySession()
 | |
| 	s.InitWithRequest(
 | |
| 		discovery.MockDiscoveryRequest(
 | |
| 			"testRequester",
 | |
| 			types.DiscoveryRequestTypeHost,
 | |
| 			[]interface{}{
 | |
| 				&omd.Zone{
 | |
| 					Network:    "192.168.1.0/24",
 | |
| 					Iface:      "enp3s0",
 | |
| 					MetaIPType: omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
 | |
| 					Address:    "192.168.1.101",
 | |
| 					Mac:        "44:8a:5b:f1:f1:f3",
 | |
| 				},
 | |
| 				&omd.DiscoverHost{
 | |
| 					MetaIPType:     omm.ToMetaIPType(omm.MetaIPTypeEnumV4),
 | |
| 					FirstScanRange: "192.168.1.1",
 | |
| 					LastScanRange:  "192.168.1.254",
 | |
| 				},
 | |
| 			},
 | |
| 		),
 | |
| 	)
 | |
| 
 | |
| 	type args struct {
 | |
| 		discoverySession session.DiscoverySession
 | |
| 	}
 | |
| 	tests := []struct {
 | |
| 		name string
 | |
| 		args args
 | |
| 	}{
 | |
| 		{
 | |
| 			name: "1",
 | |
| 			args: args{
 | |
| 				discoverySession: s,
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 	for _, tt := range tests {
 | |
| 		t.Run(tt.name, func(t *testing.T) {
 | |
| 			Scan(tt.args.discoverySession)
 | |
| 		})
 | |
| 	}
 | |
| }
 | |
| 
 | |
| 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)
 | |
| 			}
 | |
| 		})
 | |
| 	}
 | |
| }
 |