@@ -40,10 +40,8 @@ type apiTest struct {
4040 inRes interface {}
4141
4242 reqPath string
43- reqParam url.Values
4443 reqMethod string
4544 res interface {}
46- warnings Warnings
4745 err error
4846}
4947
@@ -55,7 +53,7 @@ type apiTestClient struct {
5553func (c * apiTestClient ) URL (ep string , args map [string ]string ) * url.URL {
5654 path := ep
5755 for k , v := range args {
58- path = strings .Replace (path , ":" + k , v , - 1 )
56+ path = strings .ReplaceAll (path , ":" + k , v )
5957 }
6058 u := & url.URL {
6159 Host : "test:9090" ,
@@ -255,11 +253,6 @@ func TestAPIs(t *testing.T) {
255253
256254 reqMethod : "POST" ,
257255 reqPath : "/api/v1/query" ,
258- reqParam : url.Values {
259- "query" : []string {"2" },
260- "time" : []string {testTime .Format (time .RFC3339Nano )},
261- "timeout" : []string {(5 * time .Second ).String ()},
262- },
263256 res : & model.Scalar {
264257 Value : 2 ,
265258 Timestamp : model .TimeFromUnix (testTime .Unix ()),
@@ -271,11 +264,7 @@ func TestAPIs(t *testing.T) {
271264
272265 reqMethod : "POST" ,
273266 reqPath : "/api/v1/query" ,
274- reqParam : url.Values {
275- "query" : []string {"2" },
276- "time" : []string {testTime .Format (time .RFC3339Nano )},
277- },
278- err : fmt .Errorf ("some error" ),
267+ err : fmt .Errorf ("some error" ),
279268 },
280269 {
281270 do : doQuery ("2" , testTime ),
@@ -289,11 +278,7 @@ func TestAPIs(t *testing.T) {
289278
290279 reqMethod : "POST" ,
291280 reqPath : "/api/v1/query" ,
292- reqParam : url.Values {
293- "query" : []string {"2" },
294- "time" : []string {testTime .Format (time .RFC3339Nano )},
295- },
296- err : errors .New ("server_error: server error: 500" ),
281+ err : errors .New ("server_error: server error: 500" ),
297282 },
298283 {
299284 do : doQuery ("2" , testTime ),
@@ -307,11 +292,7 @@ func TestAPIs(t *testing.T) {
307292
308293 reqMethod : "POST" ,
309294 reqPath : "/api/v1/query" ,
310- reqParam : url.Values {
311- "query" : []string {"2" },
312- "time" : []string {testTime .Format (time .RFC3339Nano )},
313- },
314- err : errors .New ("client_error: client error: 404" ),
295+ err : errors .New ("client_error: client error: 404" ),
315296 },
316297 // Warning only.
317298 {
@@ -327,15 +308,10 @@ func TestAPIs(t *testing.T) {
327308
328309 reqMethod : "POST" ,
329310 reqPath : "/api/v1/query" ,
330- reqParam : url.Values {
331- "query" : []string {"2" },
332- "time" : []string {testTime .Format (time .RFC3339Nano )},
333- },
334311 res : & model.Scalar {
335312 Value : 2 ,
336313 Timestamp : model .TimeFromUnix (testTime .Unix ()),
337314 },
338- warnings : []string {"warning" },
339315 },
340316 // Warning + error.
341317 {
@@ -351,12 +327,7 @@ func TestAPIs(t *testing.T) {
351327
352328 reqMethod : "POST" ,
353329 reqPath : "/api/v1/query" ,
354- reqParam : url.Values {
355- "query" : []string {"2" },
356- "time" : []string {testTime .Format (time .RFC3339Nano )},
357- },
358- err : errors .New ("client_error: client error: 404" ),
359- warnings : []string {"warning" },
330+ err : errors .New ("client_error: client error: 404" ),
360331 },
361332
362333 {
@@ -369,14 +340,7 @@ func TestAPIs(t *testing.T) {
369340
370341 reqMethod : "POST" ,
371342 reqPath : "/api/v1/query_range" ,
372- reqParam : url.Values {
373- "query" : []string {"2" },
374- "start" : []string {testTime .Add (- time .Minute ).Format (time .RFC3339Nano )},
375- "end" : []string {testTime .Format (time .RFC3339Nano )},
376- "step" : []string {time .Minute .String ()},
377- "timeout" : []string {(5 * time .Second ).String ()},
378- },
379- err : fmt .Errorf ("some error" ),
343+ err : fmt .Errorf ("some error" ),
380344 },
381345
382346 {
@@ -393,7 +357,6 @@ func TestAPIs(t *testing.T) {
393357 reqMethod : "GET" ,
394358 reqPath : "/api/v1/labels" ,
395359 res : []string {"val1" , "val2" },
396- warnings : []string {"a" },
397360 },
398361
399362 {
@@ -410,14 +373,12 @@ func TestAPIs(t *testing.T) {
410373 reqMethod : "GET" ,
411374 reqPath : "/api/v1/labels" ,
412375 err : fmt .Errorf ("some error" ),
413- warnings : []string {"a" },
414376 },
415377 {
416378 do : doLabelNames ([]string {"up" }),
417379 inRes : []string {"val1" , "val2" },
418380 reqMethod : "GET" ,
419381 reqPath : "/api/v1/labels" ,
420- reqParam : url.Values {"match[]" : {"up" }},
421382 res : []string {"val1" , "val2" },
422383 },
423384
@@ -435,7 +396,6 @@ func TestAPIs(t *testing.T) {
435396 reqMethod : "GET" ,
436397 reqPath : "/api/v1/label/mylabel/values" ,
437398 res : model.LabelValues {"val1" , "val2" },
438- warnings : []string {"a" },
439399 },
440400
441401 {
@@ -452,14 +412,12 @@ func TestAPIs(t *testing.T) {
452412 reqMethod : "GET" ,
453413 reqPath : "/api/v1/label/mylabel/values" ,
454414 err : fmt .Errorf ("some error" ),
455- warnings : []string {"a" },
456415 },
457416 {
458417 do : doLabelValues ([]string {"up" }, "mylabel" ),
459418 inRes : []string {"val1" , "val2" },
460419 reqMethod : "GET" ,
461420 reqPath : "/api/v1/label/mylabel/values" ,
462- reqParam : url.Values {"match[]" : {"up" }},
463421 res : model.LabelValues {"val1" , "val2" },
464422 },
465423
@@ -474,11 +432,6 @@ func TestAPIs(t *testing.T) {
474432 },
475433 reqMethod : "GET" ,
476434 reqPath : "/api/v1/series" ,
477- reqParam : url.Values {
478- "match" : []string {"up" },
479- "start" : []string {testTime .Add (- time .Minute ).Format (time .RFC3339Nano )},
480- "end" : []string {testTime .Format (time .RFC3339Nano )},
481- },
482435 res : []model.LabelSet {
483436 {
484437 "__name__" : "up" ,
@@ -500,32 +453,21 @@ func TestAPIs(t *testing.T) {
500453 inWarnings : []string {"a" },
501454 reqMethod : "GET" ,
502455 reqPath : "/api/v1/series" ,
503- reqParam : url.Values {
504- "match" : []string {"up" },
505- "start" : []string {testTime .Add (- time .Minute ).Format (time .RFC3339Nano )},
506- "end" : []string {testTime .Format (time .RFC3339Nano )},
507- },
508456 res : []model.LabelSet {
509457 {
510458 "__name__" : "up" ,
511459 "job" : "prometheus" ,
512460 "instance" : "localhost:9090" ,
513461 },
514462 },
515- warnings : []string {"a" },
516463 },
517464
518465 {
519466 do : doSeries ("up" , testTime .Add (- time .Minute ), testTime ),
520467 inErr : fmt .Errorf ("some error" ),
521468 reqMethod : "GET" ,
522469 reqPath : "/api/v1/series" ,
523- reqParam : url.Values {
524- "match" : []string {"up" },
525- "start" : []string {testTime .Add (- time .Minute ).Format (time .RFC3339Nano )},
526- "end" : []string {testTime .Format (time .RFC3339Nano )},
527- },
528- err : fmt .Errorf ("some error" ),
470+ err : fmt .Errorf ("some error" ),
529471 },
530472 // Series with error and warning.
531473 {
@@ -534,13 +476,7 @@ func TestAPIs(t *testing.T) {
534476 inWarnings : []string {"a" },
535477 reqMethod : "GET" ,
536478 reqPath : "/api/v1/series" ,
537- reqParam : url.Values {
538- "match" : []string {"up" },
539- "start" : []string {testTime .Add (- time .Minute ).Format (time .RFC3339Nano )},
540- "end" : []string {testTime .Format (time .RFC3339Nano )},
541- },
542- err : fmt .Errorf ("some error" ),
543- warnings : []string {"a" },
479+ err : fmt .Errorf ("some error" ),
544480 },
545481
546482 {
@@ -550,9 +486,6 @@ func TestAPIs(t *testing.T) {
550486 },
551487 reqMethod : "POST" ,
552488 reqPath : "/api/v1/admin/tsdb/snapshot" ,
553- reqParam : url.Values {
554- "skip_head" : []string {"true" },
555- },
556489 res : SnapshotResult {
557490 Name : "20171210T211224Z-2be650b6d019eb54" ,
558491 },
@@ -591,24 +524,14 @@ func TestAPIs(t *testing.T) {
591524 },
592525 reqMethod : "POST" ,
593526 reqPath : "/api/v1/admin/tsdb/delete_series" ,
594- reqParam : url.Values {
595- "match" : []string {"up" },
596- "start" : []string {testTime .Add (- time .Minute ).Format (time .RFC3339Nano )},
597- "end" : []string {testTime .Format (time .RFC3339Nano )},
598- },
599527 },
600528
601529 {
602530 do : doDeleteSeries ("up" , testTime .Add (- time .Minute ), testTime ),
603531 inErr : fmt .Errorf ("some error" ),
604532 reqMethod : "POST" ,
605533 reqPath : "/api/v1/admin/tsdb/delete_series" ,
606- reqParam : url.Values {
607- "match" : []string {"up" },
608- "start" : []string {testTime .Add (- time .Minute ).Format (time .RFC3339Nano )},
609- "end" : []string {testTime .Format (time .RFC3339Nano )},
610- },
611- err : fmt .Errorf ("some error" ),
534+ err : fmt .Errorf ("some error" ),
612535 },
613536
614537 {
@@ -1067,11 +990,6 @@ func TestAPIs(t *testing.T) {
1067990 },
1068991 reqMethod : "GET" ,
1069992 reqPath : "/api/v1/targets/metadata" ,
1070- reqParam : url.Values {
1071- "match_target" : []string {"{job=\" prometheus\" }" },
1072- "metric" : []string {"go_goroutines" },
1073- "limit" : []string {"1" },
1074- },
1075993 res : []MetricMetadata {
1076994 {
1077995 Target : map [string ]string {
@@ -1090,12 +1008,7 @@ func TestAPIs(t *testing.T) {
10901008 inErr : fmt .Errorf ("some error" ),
10911009 reqMethod : "GET" ,
10921010 reqPath : "/api/v1/targets/metadata" ,
1093- reqParam : url.Values {
1094- "match_target" : []string {"{job=\" prometheus\" }" },
1095- "metric" : []string {"go_goroutines" },
1096- "limit" : []string {"1" },
1097- },
1098- err : fmt .Errorf ("some error" ),
1011+ err : fmt .Errorf ("some error" ),
10991012 },
11001013
11011014 {
@@ -1111,10 +1024,6 @@ func TestAPIs(t *testing.T) {
11111024 },
11121025 reqMethod : "GET" ,
11131026 reqPath : "/api/v1/metadata" ,
1114- reqParam : url.Values {
1115- "metric" : []string {"go_goroutines" },
1116- "limit" : []string {"1" },
1117- },
11181027 res : map [string ][]Metadata {
11191028 "go_goroutines" : {
11201029 {
@@ -1131,11 +1040,7 @@ func TestAPIs(t *testing.T) {
11311040 inErr : fmt .Errorf ("some error" ),
11321041 reqMethod : "GET" ,
11331042 reqPath : "/api/v1/metadata" ,
1134- reqParam : url.Values {
1135- "metric" : []string {"" },
1136- "limit" : []string {"1" },
1137- },
1138- err : fmt .Errorf ("some error" ),
1043+ err : fmt .Errorf ("some error" ),
11391044 },
11401045
11411046 {
@@ -1323,7 +1228,9 @@ func TestAPIs(t *testing.T) {
13231228 if err .Error () != test .err .Error () {
13241229 t .Errorf ("unexpected error: want %s, got %s" , test .err , err )
13251230 }
1326- if apiErr , ok := err .(* Error ); ok {
1231+
1232+ apiErr := & Error {}
1233+ if ok := errors .As (err , & apiErr ); ok {
13271234 if apiErr .Detail != test .inRes {
13281235 t .Errorf ("%q should be %q" , apiErr .Detail , test .inRes )
13291236 }
0 commit comments