probe/ping/service/service_test.go

163 lines
3.1 KiB
Go
Raw Normal View History

2018-09-21 17:52:45 +00:00
package service
2018-09-17 16:25:56 +00:00
import (
2018-09-21 17:52:45 +00:00
"encoding/json"
"log"
2018-09-17 16:25:56 +00:00
"net"
"reflect"
"testing"
omd "git.loafle.net/overflow/model/discovery"
2018-09-17 23:08:58 +00:00
omm "git.loafle.net/overflow/model/meta"
2018-09-17 16:25:56 +00:00
ounp "git.loafle.net/overflow/util-go/net/ping"
2018-09-17 23:08:58 +00:00
"git.loafle.net/overflow_scanner/probe/__test"
2018-09-17 16:25:56 +00:00
)
func TestPing(t *testing.T) {
2018-09-26 08:00:38 +00:00
// targetHost := __test.Host(
// "",
// "234",
// "d0:7e:35:da:26:68",
// )
2018-09-17 23:08:58 +00:00
targetHost := __test.Host(
"",
2018-09-28 07:13:45 +00:00
"1",
"00:11:32:7f:20:61",
2018-09-17 23:08:58 +00:00
)
2018-09-17 16:25:56 +00:00
type args struct {
service *omd.Service
pingOption ounp.Option
}
tests := []struct {
name string
args args
want ounp.Result
wantErr bool
}{
2018-09-17 23:08:58 +00:00
{
2018-09-21 17:52:45 +00:00
name: "UNKNOWN",
2018-09-17 23:08:58 +00:00
args: args{
service: __test.Service(
2018-09-28 07:13:45 +00:00
__test.Port(
targetHost,
548,
),
2018-09-17 23:08:58 +00:00
omm.MetaCryptoTypeEnumNONE,
2018-09-21 17:52:45 +00:00
"",
2018-09-17 23:08:58 +00:00
),
pingOption: &ounp.PingOption{
2018-09-28 07:13:45 +00:00
Count: 5,
},
},
},
{
name: "HTTP",
args: args{
service: __test.Service(
__test.Port(
targetHost,
5000,
),
omm.MetaCryptoTypeEnumNONE,
"HTTP",
),
pingOption: &ounp.PingOption{
Count: 5,
2018-09-17 23:08:58 +00:00
},
},
},
2018-09-17 16:25:56 +00:00
}
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
}
2018-09-21 17:52:45 +00:00
_buf, _ := json.Marshal(got)
log.Print(string(_buf))
2018-09-17 16:25:56 +00:00
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Ping() = %v, want %v", got, tt.want)
}
})
}
}
2018-09-21 17:52:45 +00:00
func Test_isDiscoveredByMatcher(t *testing.T) {
2018-09-17 16:25:56 +00:00
type args struct {
2018-09-21 17:52:45 +00:00
service *omd.Service
2018-09-17 16:25:56 +00:00
}
tests := []struct {
name string
args args
2018-09-21 17:52:45 +00:00
want bool
2018-09-17 16:25:56 +00:00
}{
2018-09-20 05:57:30 +00:00
// TODO: Add test cases.
2018-09-17 16:25:56 +00:00
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
2018-09-21 17:52:45 +00:00
if got := isDiscoveredByMatcher(tt.args.service); got != tt.want {
t.Errorf("isDiscoveredByMatcher() = %v, want %v", got, tt.want)
2018-09-17 16:25:56 +00:00
}
})
}
}
2018-09-21 17:52:45 +00:00
func Test_processPing(t *testing.T) {
2018-09-17 16:25:56 +00:00
type args struct {
service *omd.Service
pingOption ounp.Option
2018-09-21 17:52:45 +00:00
_pingFunc pingFunc
2018-09-17 16:25:56 +00:00
}
tests := []struct {
2018-09-21 17:52:45 +00:00
name string
args args
want ounp.Result
wantErr bool
2018-09-17 16:25:56 +00:00
}{
2018-09-20 05:57:30 +00:00
// TODO: Add test cases.
2018-09-17 16:25:56 +00:00
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
2018-09-21 17:52:45 +00:00
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)
2018-09-17 16:25:56 +00:00
}
})
}
}
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
}{
2018-09-20 05:57:30 +00:00
// TODO: Add test cases.
2018-09-17 16:25:56 +00:00
}
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)
}
})
}
}