probe/ping/service/matcher/matcher_test.go

137 lines
2.8 KiB
Go
Raw Normal View History

2018-09-17 16:25:56 +00:00
package matcher
import (
"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
osm "git.loafle.net/overflow/service_matcher-go"
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-17 23:08:58 +00:00
targetHost := __test.Host(
"",
"99",
"00:25:b3:fa:ca:9b",
)
targetPort := __test.Port(
targetHost,
80,
)
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
{
name: "192.168.1.99",
args: args{
service: __test.Service(
targetPort,
omm.MetaCryptoTypeEnumNONE,
"HTTP",
),
pingOption: &ounp.PingOption{
Retry: 3,
},
},
},
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
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Ping() = %v, want %v", got, tt.want)
}
})
}
}
func Test_processPrepacket(t *testing.T) {
type args struct {
service *omd.Service
pingOption ounp.Option
matchCtx *osm.MatchCtx
_matcher osm.Matcher
}
tests := []struct {
name string
args args
want ounp.Result
}{
2018-09-18 13:38:20 +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) {
if got := processPrepacket(tt.args.service, tt.args.pingOption, tt.args.matchCtx, tt.args._matcher); !reflect.DeepEqual(got, tt.want) {
t.Errorf("processPrepacket() = %v, want %v", got, tt.want)
}
})
}
}
func Test_processPostpacket(t *testing.T) {
type args struct {
service *omd.Service
pingOption ounp.Option
matchCtx *osm.MatchCtx
_matcher osm.Matcher
}
tests := []struct {
name string
args args
want ounp.Result
}{
2018-09-18 13:38:20 +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) {
if got := processPostpacket(tt.args.service, tt.args.pingOption, tt.args.matchCtx, tt.args._matcher); !reflect.DeepEqual(got, tt.want) {
t.Errorf("processPostpacket() = %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
}{
2018-09-18 13:38:20 +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)
}
})
}
}