2018-09-17 11:07:36 +00:00
|
|
|
package ping
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPing(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
destination string
|
2018-09-17 12:45:26 +00:00
|
|
|
option Option
|
2018-09-17 11:07:36 +00:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
2018-09-17 12:45:26 +00:00
|
|
|
want Result
|
2018-09-17 11:07:36 +00:00
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "192.168.1.1",
|
|
|
|
args: args{
|
|
|
|
destination: "192.168.1.1",
|
2018-09-17 12:45:26 +00:00
|
|
|
option: &PingOption{
|
|
|
|
retry: 4,
|
2018-09-17 11:07:36 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2018-09-17 12:45:26 +00:00
|
|
|
got, err := Ping(tt.args.destination, tt.args.option)
|
2018-09-17 11:07:36 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|