Changed from Retry to Count

This commit is contained in:
crusader 2018-09-20 14:12:13 +09:00
parent 56b9d39ba9
commit ac5e1d0bd3
8 changed files with 14 additions and 14 deletions

View File

@ -7,7 +7,7 @@ import (
)
type Option interface {
GetRetry() int
GetCount() int
GetInterval() int
GetDeadline() int
Validate()
@ -35,13 +35,13 @@ type Result interface {
}
type PingOption struct {
Retry int `json:"retry,omitempty"`
Count int `json:"count,omitempty"`
Interval int `json:"interval,omitempty"`
Deadline int `json:"deadline,omitempty"`
}
func (o *PingOption) GetRetry() int {
return o.Retry
func (o *PingOption) GetCount() int {
return o.Count
}
func (o *PingOption) GetInterval() int {
return o.Interval
@ -50,8 +50,8 @@ func (o *PingOption) GetDeadline() int {
return o.Deadline
}
func (o *PingOption) Validate() {
if 0 >= o.Retry {
o.Retry = 1
if 0 >= o.Count {
o.Count = 1
}
if 0 >= o.Interval {
o.Interval = 1

View File

@ -10,7 +10,7 @@ func Ping(destination string, option Option) (Result, error) {
params := make([]string, 0)
params = append(params, destination)
params = append(params, fmt.Sprintf("-c %d", option.GetRetry()))
params = append(params, fmt.Sprintf("-c %d", option.GetCount()))
params = append(params, fmt.Sprintf("-i %d", option.GetInterval()))
pCmd := exec.Command("ping", params...)

View File

@ -21,7 +21,7 @@ func TestPing(t *testing.T) {
args: args{
destination: "192.168.1.1",
option: &PingOption{
Retry: 4,
Count: 4,
},
},
},

View File

@ -11,7 +11,7 @@ func Ping(destination string, option Option) (Result, error) {
params := make([]string, 0)
params = append(params, destination)
params = append(params, fmt.Sprintf("-c %d", option.GetRetry()))
params = append(params, fmt.Sprintf("-c %d", option.GetCount()))
params = append(params, fmt.Sprintf("-i %d", option.GetInterval()))
pCmd := exec.Command("ping", params...)

View File

@ -18,7 +18,7 @@ func TestPing(t *testing.T) {
args: args{
destination: "192.168.1.1",
option: &PingOption{
Retry: 4,
Count: 4,
},
},
},

View File

@ -7,7 +7,7 @@ import (
func TestPingOptions_Validate(t *testing.T) {
type fields struct {
Retry int
Count int
Interval int
Deadline int
}
@ -21,7 +21,7 @@ func TestPingOptions_Validate(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := &PingOption{
Retry: tt.fields.Retry,
Count: tt.fields.Count,
Interval: tt.fields.Interval,
Deadline: tt.fields.Deadline,
}

View File

@ -10,7 +10,7 @@ func Ping(destination string, option Option) (Result, error) {
params := make([]string, 0)
params = append(params, "/C")
params = append(params, fmt.Sprintf("chcp 437 && ping %s -n %d -w %d", destination, option.GetRetry(), option.GetDeadline()*1000))
params = append(params, fmt.Sprintf("chcp 437 && ping %s -n %d -w %d", destination, option.GetCount(), option.GetDeadline()*1000))
pCmd := exec.Command("cmd.exe", params...)
output, err := pCmd.CombinedOutput()

View File

@ -18,7 +18,7 @@ func TestPing(t *testing.T) {
args: args{
destination: "192.168.1.1",
option: &PingOption{
Retry: 4,
Count: 4,
},
},
},