149 lines
2.9 KiB
Go
149 lines
2.9 KiB
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"net"
|
|
"reflect"
|
|
"testing"
|
|
|
|
omd "git.loafle.net/overflow/model/discovery"
|
|
omm "git.loafle.net/overflow/model/meta"
|
|
ounp "git.loafle.net/overflow/util-go/net/ping"
|
|
"git.loafle.net/overflow_scanner/probe/__test"
|
|
)
|
|
|
|
func TestPing(t *testing.T) {
|
|
// targetHost := __test.Host(
|
|
// "",
|
|
// "234",
|
|
// "d0:7e:35:da:26:68",
|
|
// )
|
|
targetHost := __test.Host(
|
|
"",
|
|
"179",
|
|
"08-00-27-F0-DC-35",
|
|
)
|
|
|
|
targetPort := __test.Port(
|
|
targetHost,
|
|
139,
|
|
)
|
|
|
|
type args struct {
|
|
service *omd.Service
|
|
pingOption ounp.Option
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want ounp.Result
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "UNKNOWN",
|
|
args: args{
|
|
service: __test.Service(
|
|
targetPort,
|
|
omm.MetaCryptoTypeEnumNONE,
|
|
"",
|
|
),
|
|
pingOption: &ounp.PingOption{
|
|
Count: 3,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := Ping(tt.args.service, tt.args.pingOption)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("Ping() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
|
|
_buf, _ := json.Marshal(got)
|
|
log.Print(string(_buf))
|
|
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("Ping() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func Test_isDiscoveredByMatcher(t *testing.T) {
|
|
type args struct {
|
|
service *omd.Service
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := isDiscoveredByMatcher(tt.args.service); got != tt.want {
|
|
t.Errorf("isDiscoveredByMatcher() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func Test_processPing(t *testing.T) {
|
|
type args struct {
|
|
service *omd.Service
|
|
pingOption ounp.Option
|
|
_pingFunc pingFunc
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want ounp.Result
|
|
wantErr bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := processPing(tt.args.service, tt.args.pingOption, tt.args._pingFunc)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("processPing() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("processPing() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func Test_getConnection(t *testing.T) {
|
|
type args struct {
|
|
service *omd.Service
|
|
pingOption ounp.Option
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want net.Conn
|
|
wantErr bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := getConnection(tt.args.service, tt.args.pingOption)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("getConnection() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("getConnection() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|