-
Notifications
You must be signed in to change notification settings - Fork 892
/
Copy pathhttp_test.go
720 lines (637 loc) · 19.2 KB
/
http_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
package exporter
import (
"fmt"
"io"
"math/rand"
"net"
"net/http"
"net/http/httptest"
"net/url"
"os"
"strings"
"sync"
"testing"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)
func TestHTTPScrapeMetricsEndpoints(t *testing.T) {
if os.Getenv("TEST_REDIS_URI") == "" || os.Getenv("TEST_PWD_REDIS_URI") == "" {
t.Skipf("Skipping TestHTTPScrapeMetricsEndpoints, missing env vars")
}
setupTestKeys(t, os.Getenv("TEST_REDIS_URI"))
defer deleteTestKeys(t, os.Getenv("TEST_REDIS_URI"))
setupTestKeys(t, os.Getenv("TEST_PWD_REDIS_URI"))
defer deleteTestKeys(t, os.Getenv("TEST_PWD_REDIS_URI"))
csk := dbNumStrFull + "=" + url.QueryEscape(testKeys[0]) // check-single-keys
css := dbNumStrFull + "=" + TestKeysStreamName // check-single-streams
cntk := dbNumStrFull + "=" + testKeys[0] + "*" // count-keys
u, err := url.Parse(os.Getenv("TEST_REDIS_URI"))
if err != nil {
t.Fatalf("url.Parse() err: %s", err)
}
testRedisIPAddress := ""
testRedisHostname := u.Hostname()
if testRedisHostname == "localhost" {
testRedisIPAddress = "127.0.0.1"
} else {
ips, err := net.LookupIP(testRedisHostname)
if err != nil {
t.Fatalf("Could not get IP address: %s", err)
}
if len(ips) == 0 {
t.Fatal("No IP addresses found")
}
testRedisIPAddress = ips[0].String()
}
testRedisIPAddress = fmt.Sprintf("%s:%s", testRedisIPAddress, u.Port())
testRedisHostname = fmt.Sprintf("%s:%s", testRedisHostname, u.Port())
t.Logf("testRedisIPAddress: %s", testRedisIPAddress)
t.Logf("testRedisHostname: %s", testRedisHostname)
for _, tst := range []struct {
name string
addr string
ck string
csk string
cs string
scrapeCs string
css string
cntk string
pwd string
scrape bool
target string
wantStatusCode int
}{
{name: "ip-addr", addr: testRedisIPAddress, csk: csk, css: css, cntk: cntk},
{name: "hostname", addr: testRedisHostname, csk: csk, css: css, cntk: cntk},
{name: "check-keys", addr: os.Getenv("TEST_REDIS_URI"), ck: csk, cs: css, cntk: cntk},
{name: "check-single-keys", addr: os.Getenv("TEST_REDIS_URI"), csk: csk, css: css, cntk: cntk},
{name: "addr-no-prefix", addr: strings.TrimPrefix(os.Getenv("TEST_REDIS_URI"), "redis://"), csk: csk, css: css, cntk: cntk},
{name: "scrape-target-no-prefix", pwd: "", scrape: true, target: strings.TrimPrefix(os.Getenv("TEST_REDIS_URI"), "redis://"), ck: csk, cs: css, cntk: cntk},
{name: "scrape-broken-target", wantStatusCode: http.StatusBadRequest, scrape: true, target: "://nope"},
{name: "scrape-broken-target2", wantStatusCode: http.StatusBadRequest, scrape: true, target: os.Getenv("TEST_REDIS_URI") + "-", csk: csk, css: css, cntk: cntk},
{name: "scrape-broken-cs", wantStatusCode: http.StatusBadRequest, scrape: true, target: os.Getenv("TEST_REDIS_URI"), scrapeCs: "1=2=3=4"},
{name: "scrape-ck", pwd: "", scrape: true, target: os.Getenv("TEST_REDIS_URI"), ck: csk, scrapeCs: css, cntk: cntk},
{name: "scrape-csk", pwd: "", scrape: true, target: os.Getenv("TEST_REDIS_URI"), csk: csk, css: css, cntk: cntk},
{name: "scrape-pwd-ck", pwd: "redis-password", scrape: true, target: os.Getenv("TEST_PWD_REDIS_URI"), ck: csk, scrapeCs: css, cntk: cntk},
{name: "scrape-pwd-csk", pwd: "redis-password", scrape: true, target: os.Getenv("TEST_PWD_REDIS_URI"), csk: csk, scrapeCs: css, cntk: cntk},
{name: "error-scrape-no-target", wantStatusCode: http.StatusBadRequest, scrape: true, target: ""},
} {
t.Run(tst.name, func(t *testing.T) {
options := Options{
Namespace: "test",
Password: tst.pwd,
LuaScript: map[string][]byte{
"test.lua": []byte(`return {"a", "11", "b", "12", "c", "13"}`),
},
Registry: prometheus.NewRegistry(),
}
options.CheckSingleKeys = tst.csk
options.CheckKeys = tst.ck
options.CheckSingleStreams = tst.css
options.CheckStreams = tst.cs
options.CountKeys = tst.cntk
options.CheckKeysBatchSize = 1000
e, _ := NewRedisExporter(tst.addr, options)
ts := httptest.NewServer(e)
u := ts.URL
if tst.scrape {
u += "/scrape"
v := url.Values{}
v.Add("target", tst.target)
v.Add("check-single-keys", tst.csk)
v.Add("check-keys", tst.ck)
v.Add("check-streams", tst.scrapeCs)
v.Add("check-single-streams", tst.css)
v.Add("count-keys", tst.cntk)
up, _ := url.Parse(u)
up.RawQuery = v.Encode()
u = up.String()
} else {
u += "/metrics"
}
wantStatusCode := http.StatusOK
if tst.wantStatusCode != 0 {
wantStatusCode = tst.wantStatusCode
}
gotStatusCode, body := downloadURLWithStatusCode(t, u)
if gotStatusCode != wantStatusCode {
t.Fatalf("got status code: %d wanted: %d", gotStatusCode, wantStatusCode)
return
}
// we can stop here if we expected a non-200 response
if wantStatusCode != http.StatusOK {
return
}
wants := []string{
// metrics
`test_connected_clients`,
`test_commands_processed_total`,
`test_instance_info`,
"db_keys",
"db_avg_ttl_seconds",
"cpu_sys_seconds_total",
"loading_dump_file", // testing renames
"config_maxmemory", // testing config extraction
"config_maxclients", // testing config extraction
"slowlog_length",
"slowlog_last_id",
"start_time_seconds",
"uptime_in_seconds",
// labels and label values
`redis_mode`,
`cmd="config`,
"maxmemory_policy",
`test_script_value`, // lua script
`test_key_size{db="db11",key="` + testKeys[0] + `"} 7`,
`test_key_value{db="db11",key="` + testKeys[0] + `"} 1234.56`,
`test_keys_count{db="db11",key="` + testKeys[0] + `*"} 1`,
`test_db_keys{db="db11"} `,
`test_db_keys_expiring{db="db11"} `,
// streams
`stream_length`,
`stream_groups`,
`stream_radix_tree_keys`,
`stream_radix_tree_nodes`,
`stream_group_consumers`,
`stream_group_messages_pending`,
`stream_group_consumer_messages_pending`,
`stream_group_consumer_idle_seconds`,
`test_up 1`,
}
for _, want := range wants {
if !strings.Contains(body, want) {
t.Errorf("url: %s want metrics to include %q, have:\n%s", u, want, body)
break
}
}
ts.Close()
})
}
}
func TestSimultaneousMetricsHttpRequests(t *testing.T) {
if os.Getenv("TEST_REDIS_URI") == "" ||
os.Getenv("TEST_REDIS_2_8_URI") == "" ||
os.Getenv("TEST_KEYDB01_URI") == "" ||
os.Getenv("TEST_KEYDB02_URI") == "" ||
os.Getenv("TEST_REDIS5_URI") == "" ||
os.Getenv("TEST_REDIS6_URI") == "" ||
os.Getenv("TEST_REDIS_CLUSTER_MASTER_URI") == "" ||
os.Getenv("TEST_REDIS_CLUSTER_SLAVE_URI") == "" ||
os.Getenv("TEST_TILE38_URI") == "" ||
os.Getenv("TEST_REDIS_MODULES_URI") == "" {
t.Skipf("Skipping TestSimultaneousMetricsHttpRequests, missing env vars")
}
setupTestKeys(t, os.Getenv("TEST_REDIS_URI"))
defer deleteTestKeys(t, os.Getenv("TEST_REDIS_URI"))
e, _ := NewRedisExporter("", Options{Namespace: "test", InclSystemMetrics: false, Registry: prometheus.NewRegistry()})
ts := httptest.NewServer(e)
defer ts.Close()
uris := []string{
os.Getenv("TEST_REDIS_URI"),
os.Getenv("TEST_REDIS_2_8_URI"),
os.Getenv("TEST_REDIS7_URI"),
os.Getenv("TEST_VALKEY7_URI"),
os.Getenv("TEST_VALKEY8_URI"),
os.Getenv("TEST_KEYDB01_URI"),
os.Getenv("TEST_KEYDB02_URI"),
os.Getenv("TEST_REDIS5_URI"),
os.Getenv("TEST_REDIS6_URI"),
os.Getenv("TEST_REDIS_MODULES_URI"),
// tile38 & Cluster need to be last in this list so we can identify them when selected, down in line 229
os.Getenv("TEST_REDIS_CLUSTER_MASTER_URI"),
os.Getenv("TEST_REDIS_CLUSTER_SLAVE_URI"),
os.Getenv("TEST_TILE38_URI"),
}
t.Logf("uris: %#v", uris)
goroutines := 20
var wg sync.WaitGroup
wg.Add(goroutines)
for ; goroutines > 0; goroutines-- {
go func() {
requests := 100
for ; requests > 0; requests-- {
v := url.Values{}
uriIdx := rand.Intn(len(uris))
target := uris[uriIdx]
v.Add("target", target)
// not appending this param for Tile38 and cluster (the last two in the list)
// Tile38 & cluster don't support the SELECT command so this test will fail and spam the logs
if uriIdx < len(uris)-3 {
v.Add("check-single-keys", dbNumStrFull+"="+url.QueryEscape(testKeys[0]))
}
up, _ := url.Parse(ts.URL + "/scrape")
up.RawQuery = v.Encode()
fullURL := up.String()
body := downloadURL(t, fullURL)
wants := []string{
`test_connected_clients`,
`test_commands_processed_total`,
`test_instance_info`,
`test_up 1`,
}
for _, want := range wants {
if !strings.Contains(body, want) {
t.Errorf("fullURL: %s - want metrics to include %q, have:\n%s", fullURL, want, body)
break
}
}
}
wg.Done()
}()
}
wg.Wait()
}
func TestHttpHandlers(t *testing.T) {
if os.Getenv("TEST_PWD_REDIS_URI") == "" {
t.Skipf("TEST_PWD_REDIS_URI not set - skipping")
}
e, _ := NewRedisExporter(os.Getenv("TEST_PWD_REDIS_URI"), Options{Namespace: "test", Registry: prometheus.NewRegistry()})
ts := httptest.NewServer(e)
defer ts.Close()
for _, tst := range []struct {
path string
want string
}{
{
path: "/",
want: `<head><title>Redis Exporter `,
},
{
path: "/health",
want: `ok`,
},
} {
t.Run(fmt.Sprintf("path: %s", tst.path), func(t *testing.T) {
body := downloadURL(t, ts.URL+tst.path)
if !strings.Contains(body, tst.want) {
t.Fatalf(`error, expected string "%s" in body, got body: \n\n%s`, tst.want, body)
}
})
}
}
func TestHttpDiscoverClusterNodesHandlers(t *testing.T) {
clusterAddr := os.Getenv("TEST_REDIS_CLUSTER_MASTER_URI")
nonClusterAddr := os.Getenv("TEST_REDIS_URI")
if clusterAddr == "" || nonClusterAddr == "" {
t.Skipf("TEST_REDIS_CLUSTER_MASTER_URI or TEST_REDIS_URI not set - skipping")
}
tests := []struct {
addr string
want string
isCluster bool
}{
{
addr: clusterAddr,
want: "redis://127.0.0.1:7000",
isCluster: true,
},
{
addr: clusterAddr,
want: "redis://127.0.0.1:7001",
isCluster: true,
},
{
addr: clusterAddr,
want: "redis://127.0.0.1:7002",
isCluster: true,
},
{
addr: clusterAddr,
want: "The discovery endpoint is only available on a redis cluster",
isCluster: false,
},
{
addr: nonClusterAddr,
want: "The discovery endpoint is only available on a redis cluster",
isCluster: false,
},
{
addr: nonClusterAddr,
want: "ouldn't connect to redis cluster: Cluster refresh failed",
isCluster: true,
},
{
addr: "doesnt-exist:9876",
want: "The discovery endpoint is only available on a redis cluster",
isCluster: false,
},
{
addr: "doesnt-exist:9876",
want: "Couldn't connect to redis cluster: Cluster refresh failed: redisc: all nodes failed",
isCluster: true,
},
}
for _, tst := range tests {
t.Run(fmt.Sprintf("addr: %s, isCluster: %v", tst.addr, tst.isCluster), func(t *testing.T) {
e, _ := NewRedisExporter(tst.addr, Options{
Namespace: "test",
Registry: prometheus.NewRegistry(),
IsCluster: tst.isCluster,
})
ts := httptest.NewServer(e)
defer ts.Close()
body := downloadURL(t, ts.URL+"/discover-cluster-nodes")
if !strings.Contains(body, tst.want) {
t.Fatalf(`error, expected string "%s" in body, got body: \n\n%s`, tst.want, body)
}
})
}
}
func TestReloadHandlers(t *testing.T) {
if os.Getenv("TEST_PWD_REDIS_URI") == "" {
t.Skipf("TEST_PWD_REDIS_URI not set - skipping")
}
eWithPwdfile, _ := NewRedisExporter(os.Getenv("TEST_PWD_REDIS_URI"), Options{Namespace: "test", Registry: prometheus.NewRegistry(), RedisPwdFile: "../contrib/sample-pwd-file.json"})
ts := httptest.NewServer(eWithPwdfile)
defer ts.Close()
for _, tst := range []struct {
e *Exporter
path string
want string
}{
{
path: "/-/reload",
want: `ok`,
},
} {
t.Run(fmt.Sprintf("path: %s", tst.path), func(t *testing.T) {
body := downloadURL(t, ts.URL+tst.path)
if !strings.Contains(body, tst.want) {
t.Fatalf(`error, expected string "%s" in body, got body: \n\n%s`, tst.want, body)
}
})
}
eWithnoPwdfile, _ := NewRedisExporter(os.Getenv("TEST_PWD_REDIS_URI"), Options{Namespace: "test", Registry: prometheus.NewRegistry()})
ts2 := httptest.NewServer(eWithnoPwdfile)
defer ts2.Close()
for _, tst := range []struct {
e *Exporter
path string
want string
}{
{
path: "/-/reload",
want: `There is no pwd file specified`,
},
} {
t.Run(fmt.Sprintf("path: %s", tst.path), func(t *testing.T) {
body := downloadURL(t, ts2.URL+tst.path)
if !strings.Contains(body, tst.want) {
t.Fatalf(`error, expected string "%s" in body, got body: \n\n%s`, tst.want, body)
}
})
}
eWithMalformedPwdfile, _ := NewRedisExporter(os.Getenv("TEST_PWD_REDIS_URI"), Options{Namespace: "test", Registry: prometheus.NewRegistry(), RedisPwdFile: "../contrib/sample-pwd-file.json-malformed"})
ts3 := httptest.NewServer(eWithMalformedPwdfile)
defer ts3.Close()
for _, tst := range []struct {
e *Exporter
path string
want string
}{
{
path: "/-/reload",
want: `failed to reload passwords file: unexpected end of JSON input`,
},
} {
t.Run(fmt.Sprintf("path: %s", tst.path), func(t *testing.T) {
body := downloadURL(t, ts3.URL+tst.path)
if !strings.Contains(body, tst.want) {
t.Fatalf(`error, expected string "%s" in body, got body: \n\n%s`, tst.want, body)
}
})
}
}
func TestIsBasicAuthConfigured(t *testing.T) {
tests := []struct {
name string
username string
password string
want bool
}{
{
name: "no credentials configured",
username: "",
password: "",
want: false,
},
{
name: "only username configured",
username: "user",
password: "",
want: false,
},
{
name: "only password configured",
username: "",
password: "pass",
want: false,
},
{
name: "both credentials configured",
username: "user",
password: "pass",
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e, _ := NewRedisExporter("", Options{
BasicAuthUsername: tt.username,
BasicAuthPassword: tt.password,
})
if got := e.isBasicAuthConfigured(); got != tt.want {
t.Errorf("isBasicAuthConfigured() = %v, want %v", got, tt.want)
}
})
}
}
func TestVerifyBasicAuth(t *testing.T) {
tests := []struct {
name string
configUser string
configPass string
providedUser string
providedPass string
authHeaderSet bool
wantErr bool
wantErrString string
}{
{
name: "no auth configured - no credentials provided",
configUser: "",
configPass: "",
providedUser: "",
providedPass: "",
authHeaderSet: false,
wantErr: false,
},
{
name: "auth configured - no auth header",
configUser: "user",
configPass: "pass",
providedUser: "",
providedPass: "",
authHeaderSet: false,
wantErr: true,
wantErrString: "Unauthorized",
},
{
name: "auth configured - correct credentials",
configUser: "user",
configPass: "pass",
providedUser: "user",
providedPass: "pass",
authHeaderSet: true,
wantErr: false,
},
{
name: "auth configured - wrong username",
configUser: "user",
configPass: "pass",
providedUser: "wronguser",
providedPass: "pass",
authHeaderSet: true,
wantErr: true,
wantErrString: "Unauthorized",
},
{
name: "auth configured - wrong password",
configUser: "user",
configPass: "pass",
providedUser: "user",
providedPass: "wrongpass",
authHeaderSet: true,
wantErr: true,
wantErrString: "Unauthorized",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e, _ := NewRedisExporter("", Options{
BasicAuthUsername: tt.configUser,
BasicAuthPassword: tt.configPass,
})
err := e.verifyBasicAuth(tt.providedUser, tt.providedPass, tt.authHeaderSet)
if (err != nil) != tt.wantErr {
t.Errorf("verifyBasicAuth() error = %v, wantErr %v", err, tt.wantErr)
return
}
if err != nil && err.Error() != tt.wantErrString {
t.Errorf("verifyBasicAuth() error = %v, wantErrString %v", err, tt.wantErrString)
}
})
}
}
func TestBasicAuth(t *testing.T) {
if os.Getenv("TEST_REDIS_URI") == "" {
t.Skipf("TEST_REDIS_URI not set - skipping")
}
tests := []struct {
name string
username string
password string
configUsername string
configPassword string
wantStatusCode int
}{
{
name: "No auth configured - no credentials provided",
username: "",
password: "",
configUsername: "",
configPassword: "",
wantStatusCode: http.StatusOK,
},
{
name: "Auth configured - correct credentials",
username: "testuser",
password: "testpass",
configUsername: "testuser",
configPassword: "testpass",
wantStatusCode: http.StatusOK,
},
{
name: "Auth configured - wrong username",
username: "wronguser",
password: "testpass",
configUsername: "testuser",
configPassword: "testpass",
wantStatusCode: http.StatusUnauthorized,
},
{
name: "Auth configured - wrong password",
username: "testuser",
password: "wrongpass",
configUsername: "testuser",
configPassword: "testpass",
wantStatusCode: http.StatusUnauthorized,
},
{
name: "Auth configured - no credentials provided",
username: "",
password: "",
configUsername: "testuser",
configPassword: "testpass",
wantStatusCode: http.StatusUnauthorized,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e, _ := NewRedisExporter(os.Getenv("TEST_REDIS_URI"), Options{
Namespace: "test",
Registry: prometheus.NewRegistry(),
BasicAuthUsername: tt.configUsername,
BasicAuthPassword: tt.configPassword,
})
ts := httptest.NewServer(e)
defer ts.Close()
client := &http.Client{}
req, err := http.NewRequest("GET", ts.URL+"/metrics", nil)
if err != nil {
t.Fatalf("Failed to create request: %v", err)
}
if tt.username != "" || tt.password != "" {
req.SetBasicAuth(tt.username, tt.password)
}
resp, err := client.Do(req)
if err != nil {
t.Fatalf("Failed to send request: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != tt.wantStatusCode {
t.Errorf("Expected status code %d, got %d", tt.wantStatusCode, resp.StatusCode)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("Failed to read response body: %v", err)
}
if tt.wantStatusCode == http.StatusOK {
if !strings.Contains(string(body), "test_up") {
t.Errorf("Expected body to contain 'test_up', got: %s", string(body))
}
} else {
if !strings.Contains(resp.Header.Get("WWW-Authenticate"), "Basic realm=\"redis-exporter") {
t.Errorf("Expected WWW-Authenticate header, got: %s", resp.Header.Get("WWW-Authenticate"))
}
}
})
}
}
func downloadURL(t *testing.T, u string) string {
_, res := downloadURLWithStatusCode(t, u)
return res
}
func downloadURLWithStatusCode(t *testing.T, u string) (int, string) {
log.Debugf("downloadURL() %s", u)
resp, err := http.Get(u)
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
return resp.StatusCode, string(body)
}