From 1b6cdf8f00a7f942e7d7272f3f0ca0a78c782f13 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 5 Oct 2024 20:36:52 -0700 Subject: [PATCH] TestHTTPScrapeMetricsEndpoints --- exporter/exporter_test.go | 2 +- exporter/http_test.go | 39 +++++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/exporter/exporter_test.go b/exporter/exporter_test.go index 1af02a33..6cdec3d0 100644 --- a/exporter/exporter_test.go +++ b/exporter/exporter_test.go @@ -82,7 +82,7 @@ func setupKeys(t *testing.T, c redis.Conn, dbNumStr string) error { } } - // setting to expire in 300 seconds, should be plenty for a test run + // set to expire in 300 seconds, should be plenty for a test run for _, key := range keysExpiring { if _, err := c.Do("SETEX", key, "300", TestValue); err != nil { t.Errorf("couldn't setup redis, err: %s ", err) diff --git a/exporter/http_test.go b/exporter/http_test.go index a827020e..e5924a4c 100644 --- a/exporter/http_test.go +++ b/exporter/http_test.go @@ -31,26 +31,33 @@ func TestHTTPScrapeMetricsEndpoints(t *testing.T) { css := dbNumStrFull + "=" + TestStreamName // check-single-streams cntk := dbNumStrFull + "=" + keys[0] + "*" // count-keys + u, err := url.Parse(os.Getenv("TEST_REDIS_URI")) + if err != nil { + t.Fatalf("url.Parse() err: %s", err) + } + testRedisIPAddress := "" - testRedisHostname := "" - if u, err := url.Parse(os.Getenv("TEST_REDIS_URI")); err == nil { - 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() + 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") } - t.Logf("testRedisIPAddress: %s", testRedisIPAddress) - t.Logf("testRedisHostname: %s", testRedisHostname) + 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