Skip to content
Snippets Groups Projects
Commit 9bb06cf2 authored by Oliver's avatar Oliver
Browse files

fix http test setup

parent f5d93eda
No related branches found
No related tags found
No related merge requests found
Loading
@@ -9,19 +9,21 @@ package exporter
Loading
@@ -9,19 +9,21 @@ package exporter
*/ */
   
import ( import (
"bytes"
"flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
"net/http/httptest"
"net/url" "net/url"
"strings" "strings"
"testing" "testing"
"time" "time"
   
"bytes"
"flag"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
dto "github.com/prometheus/client_model/go" dto "github.com/prometheus/client_model/go"
) )
   
Loading
@@ -42,6 +44,8 @@ var (
Loading
@@ -42,6 +44,8 @@ var (
   
dbNumStr = "11" dbNumStr = "11"
dbNumStrFull = fmt.Sprintf("db%s", dbNumStr) dbNumStrFull = fmt.Sprintf("db%s", dbNumStr)
TestServerURL = ""
) )
   
const ( const (
Loading
@@ -97,7 +101,9 @@ func resetLatency(t *testing.T, addr string) error {
Loading
@@ -97,7 +101,9 @@ func resetLatency(t *testing.T, addr string) error {
} }
   
func getMetrics(t *testing.T) []byte { func getMetrics(t *testing.T) []byte {
resp, err := http.Get("http://127.0.0.1:9121/metrics") url := TestServerURL + "/metrics"
log.Printf("Getting metrics from: %s", url)
resp, err := http.Get(url)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
Loading
@@ -568,7 +574,6 @@ func TestCommandStats(t *testing.T) {
Loading
@@ -568,7 +574,6 @@ func TestCommandStats(t *testing.T) {
} }
   
func TestHTTPEndpoint(t *testing.T) { func TestHTTPEndpoint(t *testing.T) {
e, _ := NewRedisExporter(defaultRedisHost, "test", dbNumStrFull+"="+url.QueryEscape(keys[0])) e, _ := NewRedisExporter(defaultRedisHost, "test", dbNumStrFull+"="+url.QueryEscape(keys[0]))
   
setupDBKeys(t, defaultRedisHost.Addrs[0]) setupDBKeys(t, defaultRedisHost.Addrs[0])
Loading
@@ -808,6 +813,5 @@ func init() {
Loading
@@ -808,6 +813,5 @@ func init() {
log.Printf("Using redis addrs: %#v", addrs) log.Printf("Using redis addrs: %#v", addrs)
defaultRedisHost = RedisHost{Addrs: []string{"redis://" + *redisAddr}, Aliases: aliases} defaultRedisHost = RedisHost{Addrs: []string{"redis://" + *redisAddr}, Aliases: aliases}
   
http.Handle("/metrics", prometheus.Handler()) TestServerURL = httptest.NewServer(promhttp.Handler()).URL
go http.ListenAndServe("127.0.0.1:9121", nil)
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment