@@ -124,7 +124,7 @@ func Test_HttpJson(t *testing.T) {
124
124
expected := "chartify"
125
125
actual := vals ["value" ]
126
126
if actual != expected {
127
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
127
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
128
128
}
129
129
})
130
130
@@ -137,18 +137,18 @@ func Test_HttpJson(t *testing.T) {
137
137
expected := "go-yaml"
138
138
actual := vals ["value" ]
139
139
if actual != expected {
140
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
140
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
141
141
}
142
142
})
143
143
144
144
t .Run ("Error getting document from location jsonquery.LoadURL" , func (t * testing.T ) {
145
145
config := createProvider ("httpjson://boom.github.com/users/helmfile/repos?insecure=true#" , "//owner" , "false" )
146
146
_ , err := Load (config )
147
147
if err != nil {
148
- expected := "error fetching json document at http://boom.github.com/users/helmfile/repos: invalid character '<' looking for beginning of value "
148
+ expected := "error fetching json document at http://boom.github.com/users/helmfile/repos: Get \" http://boom.github.com/users/helmfile/repos \" : dial tcp: lookup boom.github.com: no such host "
149
149
actual := err .Error ()
150
150
if actual != expected {
151
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
151
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
152
152
}
153
153
}
154
154
})
@@ -161,7 +161,7 @@ func Test_HttpJson(t *testing.T) {
161
161
expected := "unable to query doc for value with xpath query using " + uri + "//boom"
162
162
actual := err .Error ()
163
163
if actual != expected {
164
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
164
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
165
165
}
166
166
}
167
167
})
@@ -174,19 +174,19 @@ func Test_HttpJson(t *testing.T) {
174
174
expected := "unable to query doc for value with xpath query using " + uri + "//boom"
175
175
actual := err .Error ()
176
176
if actual != expected {
177
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
177
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
178
178
}
179
179
}
180
180
})
181
181
182
182
t .Run ("Get Avatar URL with child nodes causing error" , func (t * testing.T ) {
183
- config := createProvider (prefixAndPath + "?insecure=true&mode=singleparam #" , "//owner" , "false" )
183
+ config := createProvider (prefixAndPath + "?insecure=true#" , "//owner" , "false" )
184
184
_ , err := Load (config )
185
185
if err != nil {
186
186
expected := "location //owner has child nodes at " + server .URL + ", please use a more granular query"
187
187
actual := err .Error ()
188
188
if actual != expected {
189
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
189
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
190
190
}
191
191
}
192
192
})
@@ -200,7 +200,7 @@ func Test_HttpJson(t *testing.T) {
200
200
expected := "251296379"
201
201
actual := vals ["value" ]
202
202
if actual != expected {
203
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
203
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
204
204
}
205
205
})
206
206
@@ -211,7 +211,7 @@ func Test_HttpJson(t *testing.T) {
211
211
expected := "unable to convert possible float to int for value: chartify"
212
212
actual := err .Error ()
213
213
if actual != expected {
214
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
214
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
215
215
}
216
216
}
217
217
})
@@ -225,7 +225,7 @@ func Test_HttpJson(t *testing.T) {
225
225
expected := "chartify.database1.io,chartify.database2.io,chartify.database3.io,chartify.database4.io,chartify.database5.io"
226
226
actual := vals ["value" ]
227
227
if actual != expected {
228
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
228
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
229
229
}
230
230
})
231
231
}
@@ -243,7 +243,7 @@ func Test_HttpJson_UnitTests(t *testing.T) {
243
243
}
244
244
expected := "http://boom.com/path"
245
245
if returnValue != expected {
246
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , returnValue )
246
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , returnValue )
247
247
}
248
248
})
249
249
t .Run ("GetUrlFromUri: valid (https)" , func (t * testing.T ) {
@@ -253,37 +253,64 @@ func Test_HttpJson_UnitTests(t *testing.T) {
253
253
}
254
254
expected := "https://boom.com/path"
255
255
if returnValue != expected {
256
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , returnValue )
256
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , returnValue )
257
257
}
258
258
})
259
259
t .Run ("GetUrlFromUri: invalid character in host name (https)" , func (t * testing.T ) {
260
260
_ , err := httpjson .GetUrlFromUri ("httpjson://supsupsup^boom#///*[1]/name" , "https" )
261
- if err != nil {
262
- expected := "invalid domain: parse \" https://supsupsup^boom\" : invalid character \" ^\" in host name"
263
- actual := err .Error ()
264
- if actual != expected {
265
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
266
- }
261
+ expected := "invalid URL: https://supsupsup^boom, error: parse \" https://supsupsup^boom\" : invalid character \" ^\" in host name"
262
+
263
+ if err == nil {
264
+ t .Fatalf ("expected an error %q, got nil" , expected )
265
+ }
266
+
267
+ actual := err .Error ()
268
+ if actual != expected {
269
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
267
270
}
268
271
})
269
272
t .Run ("GetUrlFromUri: no domain provided (http)" , func (t * testing.T ) {
270
273
_ , err := httpjson .GetUrlFromUri ("httpjson://?insecure=true#///*[1]/name" , "http" )
271
- if err != nil {
272
- expected := "no domain found in uri: httpjson://?insecure=true#///*[1]/name"
273
- actual := err .Error ()
274
- if actual != expected {
275
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
276
- }
274
+
275
+ expected := "no domain found in uri: httpjson://?insecure=true#///*[1]/name"
276
+
277
+ if err == nil {
278
+ t .Fatalf ("expected an error %q, got nil" , expected )
279
+ }
280
+
281
+ actual := err .Error ()
282
+ if actual != expected {
283
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
277
284
}
278
285
})
279
286
t .Run ("GetUrlFromUri: no domain provided (https)" , func (t * testing.T ) {
280
287
_ , err := httpjson .GetUrlFromUri ("httpjson://#///*[1]/name" , "https" )
281
- if err != nil {
282
- expected := "no domain found in uri: httpjson://#///*[1]/name"
283
- actual := err .Error ()
284
- if actual != expected {
285
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
286
- }
288
+
289
+ expected := "no domain found in uri: httpjson://#///*[1]/name"
290
+
291
+ if err == nil {
292
+ t .Fatalf ("expected an error %q, got nil" , expected )
293
+ }
294
+
295
+ actual := err .Error ()
296
+ if actual != expected {
297
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
298
+ }
299
+ })
300
+ t .Run ("GetUrlFromUri: query params are preserved" , func (t * testing.T ) {
301
+ url , _ := httpjson .GetUrlFromUri ("httpjson://domain.com/path/?param=value#///*[1]/name" , "https" )
302
+
303
+ expected := "https://domain.com/path/?param=value"
304
+ if expected != url {
305
+ t .Errorf ("unexpected url: expected=%q, got=%q" , expected , url )
306
+ }
307
+ })
308
+ t .Run ("GetUrlFromUri: special query params are removed" , func (t * testing.T ) {
309
+ url , _ := httpjson .GetUrlFromUri ("httpjson://domain.com/path/?insecure=true&floatAsInt=false¶m=value#///*[1]/name" , "http" )
310
+
311
+ expected := "http://domain.com/path/?param=value"
312
+ if expected != url {
313
+ t .Errorf ("unexpected url: expected=%q, got=%q" , expected , url )
287
314
}
288
315
})
289
316
@@ -295,7 +322,7 @@ func Test_HttpJson_UnitTests(t *testing.T) {
295
322
}
296
323
expected := "//*[1]/name"
297
324
if returnValue != expected {
298
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , returnValue )
325
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , returnValue )
299
326
}
300
327
})
301
328
t .Run ("GetXpathFromUri: valid (https)" , func (t * testing.T ) {
@@ -305,7 +332,7 @@ func Test_HttpJson_UnitTests(t *testing.T) {
305
332
}
306
333
expected := "//*[1]/name"
307
334
if returnValue != expected {
308
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , returnValue )
335
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , returnValue )
309
336
}
310
337
})
311
338
t .Run ("GetXpathFromUri: no xpath provided (http)" , func (t * testing.T ) {
@@ -314,7 +341,7 @@ func Test_HttpJson_UnitTests(t *testing.T) {
314
341
expected := "no xpath expression found in uri: httpjson://blah.blah/blah?insecure=true"
315
342
actual := err .Error ()
316
343
if actual != expected {
317
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
344
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
318
345
}
319
346
}
320
347
})
@@ -324,7 +351,7 @@ func Test_HttpJson_UnitTests(t *testing.T) {
324
351
expected := "no xpath expression found in uri: httpjson://blah.blah/blah"
325
352
actual := err .Error ()
326
353
if actual != expected {
327
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
354
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
328
355
}
329
356
}
330
357
})
@@ -334,7 +361,7 @@ func Test_HttpJson_UnitTests(t *testing.T) {
334
361
expected := "unable to compile xpath expression '' from uri: httpjson://blah.blah/blah?insecure=true#/"
335
362
actual := err .Error ()
336
363
if actual != expected {
337
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
364
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
338
365
}
339
366
}
340
367
})
@@ -344,7 +371,7 @@ func Test_HttpJson_UnitTests(t *testing.T) {
344
371
expected := "unable to compile xpath expression '' from uri: httpjson://blah.blah/blah#/"
345
372
actual := err .Error ()
346
373
if actual != expected {
347
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
374
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
348
375
}
349
376
}
350
377
})
@@ -354,7 +381,7 @@ func Test_HttpJson_UnitTests(t *testing.T) {
354
381
expected := "unable to compile xpath expression '' from uri: httpjson://blah.blah/blah?insecure=true#/hello^sup"
355
382
actual := err .Error ()
356
383
if actual != expected {
357
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
384
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
358
385
}
359
386
}
360
387
})
@@ -364,7 +391,7 @@ func Test_HttpJson_UnitTests(t *testing.T) {
364
391
expected := "unable to compile xpath expression '' from uri: httpjson://blah.blah/blah#/hello^sup"
365
392
actual := err .Error ()
366
393
if actual != expected {
367
- t .Errorf ("unepected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
394
+ t .Errorf ("unexpected value for key %q: expected=%q, got=%q" , "value" , expected , actual )
368
395
}
369
396
}
370
397
})
0 commit comments