@@ -5,12 +5,12 @@ package ping
5
5
import (
6
6
"errors"
7
7
"reflect"
8
- "runtime"
9
8
"sort"
10
9
"testing"
11
10
12
11
"github.com/influxdata/telegraf/testutil"
13
12
"github.com/stretchr/testify/assert"
13
+ "github.com/stretchr/testify/require"
14
14
)
15
15
16
16
// BSD/Darwin ping output
@@ -99,68 +99,29 @@ func TestErrorProcessPingOutput(t *testing.T) {
99
99
// Test that arg lists and created correctly
100
100
func TestArgs (t * testing.T ) {
101
101
p := Ping {
102
- Count : 2 ,
102
+ Count : 2 ,
103
+ Interface : "eth0" ,
104
+ Timeout : 12.0 ,
105
+ Deadline : 24 ,
106
+ PingInterval : 1.2 ,
103
107
}
104
108
105
- // Actual and Expected arg lists must be sorted for reflect.DeepEqual
106
-
107
- actual := p .args ("www.google.com" )
108
- expected := []string {"-c" , "2" , "-n" , "-s" , "16" , "www.google.com" }
109
- sort .Strings (actual )
110
- sort .Strings (expected )
111
- assert .True (t , reflect .DeepEqual (expected , actual ),
112
- "Expected: %s Actual: %s" , expected , actual )
113
-
114
- p .Interface = "eth0"
115
- actual = p .args ("www.google.com" )
116
- expected = []string {"-c" , "2" , "-n" , "-s" , "16" , "-I" , "eth0" ,
117
- "www.google.com" }
118
- sort .Strings (actual )
119
- sort .Strings (expected )
120
- assert .True (t , reflect .DeepEqual (expected , actual ),
121
- "Expected: %s Actual: %s" , expected , actual )
122
-
123
- p .Timeout = 12.0
124
- actual = p .args ("www.google.com" )
125
- switch runtime .GOOS {
126
- case "darwin" :
127
- expected = []string {"-c" , "2" , "-n" , "-s" , "16" , "-I" , "eth0" , "-W" ,
128
- "12000.0" , "www.google.com" }
129
- default :
130
- expected = []string {"-c" , "2" , "-n" , "-s" , "16" , "-I" , "eth0" , "-W" ,
131
- "12" , "www.google.com" }
132
- }
133
-
134
- p .Deadline = 24
135
- actual = p .args ("www.google.com" )
136
- switch runtime .GOOS {
137
- case "darwin" :
138
- expected = []string {"-c" , "2" , "-n" , "-s" , "16" , "-I" , "eth0" , "-W" ,
139
- "12000.0" , "-t" , "24" , "www.google.com" }
140
- default :
141
- expected = []string {"-c" , "2" , "-n" , "-s" , "16" , "-I" , "eth0" , "-W" ,
142
- "12" , "-w" , "24" , "www.google.com" }
109
+ var systemCases = []struct {
110
+ system string
111
+ output []string
112
+ }{
113
+ {"darwin" , []string {"-c" , "2" , "-n" , "-s" , "16" , "-i" , "1.2" , "-W" , "12000" , "-t" , "24" , "-S" , "eth0" , "www.google.com" }},
114
+ {"linux" , []string {"-c" , "2" , "-n" , "-s" , "16" , "-i" , "1.2" , "-W" , "12" , "-w" , "24" , "-I" , "eth0" , "www.google.com" }},
115
+ {"anything else" , []string {"-c" , "2" , "-n" , "-s" , "16" , "-i" , "1.2" , "-W" , "12" , "-w" , "24" , "-I" , "eth0" , "www.google.com" }},
143
116
}
144
-
145
- sort .Strings (actual )
146
- sort .Strings (expected )
147
- assert .True (t , reflect .DeepEqual (expected , actual ),
148
- "Expected: %s Actual: %s" , expected , actual )
149
-
150
- p .PingInterval = 1.2
151
- actual = p .args ("www.google.com" )
152
- switch runtime .GOOS {
153
- case "darwin" :
154
- expected = []string {"-c" , "2" , "-n" , "-s" , "16" , "-I" , "eth0" , "-W" ,
155
- "12000.0" , "-t" , "24" , "-i" , "1.2" , "www.google.com" }
156
- default :
157
- expected = []string {"-c" , "2" , "-n" , "-s" , "16" , "-I" , "eth0" , "-W" ,
158
- "12" , "-w" , "24" , "-i" , "1.2" , "www.google.com" }
117
+ for i := range systemCases {
118
+ actual := p .args ("www.google.com" , systemCases [i ].system )
119
+ expected := systemCases [i ].output
120
+ sort .Strings (actual )
121
+ sort .Strings (expected )
122
+ require .True (t , reflect .DeepEqual (expected , actual ),
123
+ "Expected: %s Actual: %s" , expected , actual )
159
124
}
160
- sort .Strings (actual )
161
- sort .Strings (expected )
162
- assert .True (t , reflect .DeepEqual (expected , actual ),
163
- "Expected: %s Actual: %s" , expected , actual )
164
125
}
165
126
166
127
func mockHostPinger (timeout float64 , args ... string ) (string , error ) {
0 commit comments