Skip to content
Snippets Groups Projects
Commit 7c1e78bb authored by Oliver's avatar Oliver
Browse files

bytes,. i never liked you

parent 2d55bcfd
No related branches found
No related tags found
No related merge requests found
Loading
@@ -9,7 +9,6 @@ package exporter
Loading
@@ -9,7 +9,6 @@ package exporter
*/ */
   
import ( import (
"bytes"
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
Loading
@@ -152,7 +151,7 @@ func resetSlowLog(t *testing.T, addr string) error {
Loading
@@ -152,7 +151,7 @@ func resetSlowLog(t *testing.T, addr string) error {
return nil return nil
} }
   
func downloadUrl(t *testing.T, url string) []byte { func downloadUrl(t *testing.T, url string) string {
log.Debugf("downloadURL() %s", url) log.Debugf("downloadURL() %s", url)
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
Loading
@@ -163,7 +162,7 @@ func downloadUrl(t *testing.T, url string) []byte {
Loading
@@ -163,7 +162,7 @@ func downloadUrl(t *testing.T, url string) []byte {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
return body return string(body)
} }
   
func TestLatencySpike(t *testing.T) { func TestLatencySpike(t *testing.T) {
Loading
@@ -1044,7 +1043,7 @@ func TestHTTPEndpoint(t *testing.T) {
Loading
@@ -1044,7 +1043,7 @@ func TestHTTPEndpoint(t *testing.T) {
`cmd="get"`, `cmd="get"`,
} }
for _, test := range tests { for _, test := range tests {
if !bytes.Contains(body, []byte(test)) { if !strings.Contains(body, test) {
t.Errorf("want metrics to include %q, have:\n%s", test, body) t.Errorf("want metrics to include %q, have:\n%s", test, body)
} }
} }
Loading
@@ -1223,16 +1222,14 @@ func TestKeysReset(t *testing.T) {
Loading
@@ -1223,16 +1222,14 @@ func TestKeysReset(t *testing.T) {
}() }()
   
body := downloadUrl(t, ts.URL+"/metrics") body := downloadUrl(t, ts.URL+"/metrics")
if !strings.Contains(body, keys[0]) {
if !bytes.Contains(body, []byte(keys[0])) {
t.Errorf("Did not found key %q\n%s", keys[0], body) t.Errorf("Did not found key %q\n%s", keys[0], body)
} }
   
deleteKeysFromDB(t, defaultRedisHost.Addrs[0]) deleteKeysFromDB(t, defaultRedisHost.Addrs[0])
   
body = downloadUrl(t, ts.URL+"/metrics") body = downloadUrl(t, ts.URL+"/metrics")
if strings.Contains(body, keys[0]) {
if bytes.Contains(body, []byte(keys[0])) {
t.Errorf("Metric is present in metrics list %q\n%s", keys[0], body) t.Errorf("Metric is present in metrics list %q\n%s", keys[0], body)
} }
} }
Loading
@@ -1249,6 +1246,7 @@ func TestClusterMaster(t *testing.T) {
Loading
@@ -1249,6 +1246,7 @@ func TestClusterMaster(t *testing.T) {
   
addr := "redis://" + os.Getenv("TEST_REDIS_CLUSTER_MASTER_URI") addr := "redis://" + os.Getenv("TEST_REDIS_CLUSTER_MASTER_URI")
host := RedisHost{Addrs: []string{addr}, Aliases: []string{"master"}} host := RedisHost{Addrs: []string{addr}, Aliases: []string{"master"}}
log.Printf("master - using host cfg: %#v", host)
e, _ := NewRedisExporter(host, "test", "", "") e, _ := NewRedisExporter(host, "test", "", "")
   
setupDBKeys(t, defaultRedisHost.Addrs[0]) setupDBKeys(t, defaultRedisHost.Addrs[0])
Loading
@@ -1262,9 +1260,11 @@ func TestClusterMaster(t *testing.T) {
Loading
@@ -1262,9 +1260,11 @@ func TestClusterMaster(t *testing.T) {
}() }()
   
body := downloadUrl(t, ts.URL+"/metrics") body := downloadUrl(t, ts.URL+"/metrics")
log.Printf("body: %s", body) log.Printf("slave - body: %s", body)
if !bytes.Contains(body, []byte("test_instance_info")) { for _, want := range []string{"test_instance_info", "test_master_repl_offset"} {
t.Errorf("Did not found key %q\n%s", keys[0], body) if !strings.Contains(body, want) {
t.Errorf("Did not find key [%s] \nbody: %s", want, body)
}
} }
} }
   
Loading
@@ -1312,8 +1312,8 @@ func TestPasswordProtectedInstance(t *testing.T) {
Loading
@@ -1312,8 +1312,8 @@ func TestPasswordProtectedInstance(t *testing.T) {
   
body := downloadUrl(t, ts.URL+"/metrics") body := downloadUrl(t, ts.URL+"/metrics")
   
if !bytes.Contains(body, []byte("test_up")) { if !strings.Contains(body, "test_up") {
t.Errorf("error") t.Errorf("error, missing test_up")
} }
} }
   
Loading
@@ -1360,7 +1360,7 @@ func TestPasswordInvalid(t *testing.T) {
Loading
@@ -1360,7 +1360,7 @@ func TestPasswordInvalid(t *testing.T) {
}() }()
   
body := downloadUrl(t, ts.URL+"/metrics") body := downloadUrl(t, ts.URL+"/metrics")
if !bytes.Contains(body, []byte("test_exporter_last_scrape_error 1")) { if !strings.Contains(body, "test_exporter_last_scrape_error 1") {
t.Errorf(`error, expected string "test_exporter_last_scrape_error 1" in body`) t.Errorf(`error, expected string "test_exporter_last_scrape_error 1" in body`)
} }
} }
Loading
@@ -1377,6 +1377,7 @@ func TestClusterSlave(t *testing.T) {
Loading
@@ -1377,6 +1377,7 @@ func TestClusterSlave(t *testing.T) {
   
addr := "redis://" + os.Getenv("TEST_REDIS_CLUSTER_SLAVE_URI") addr := "redis://" + os.Getenv("TEST_REDIS_CLUSTER_SLAVE_URI")
host := RedisHost{Addrs: []string{addr}, Aliases: []string{"slave"}} host := RedisHost{Addrs: []string{addr}, Aliases: []string{"slave"}}
log.Printf("slave - using host cfg: %#v", host)
e, _ := NewRedisExporter(host, "test", "", "") e, _ := NewRedisExporter(host, "test", "", "")
   
setupDBKeys(t, defaultRedisHost.Addrs[0]) setupDBKeys(t, defaultRedisHost.Addrs[0])
Loading
@@ -1390,8 +1391,8 @@ func TestClusterSlave(t *testing.T) {
Loading
@@ -1390,8 +1391,8 @@ func TestClusterSlave(t *testing.T) {
}() }()
   
body := downloadUrl(t, ts.URL+"/metrics") body := downloadUrl(t, ts.URL+"/metrics")
log.Printf("body: %s", body) log.Printf("slave - body: %s", body)
if !bytes.Contains(body, []byte("test_instance_info")) { if !strings.Contains(body, "test_instance_info") {
t.Errorf("Did not found key %q\n%s", keys[0], body) t.Errorf("Did not found key %q\n%s", keys[0], body)
} }
} }
Loading
Loading
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