Skip to content

Commit

Permalink
TestHTTPScrapeMetricsEndpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver006 committed Oct 6, 2024
1 parent 49c8302 commit 1b6cdf8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 23 additions & 16 deletions exporter/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1b6cdf8

Please sign in to comment.