forked from colega/grafana-tools-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers_test.go
63 lines (49 loc) · 1.1 KB
/
helpers_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
package sdk_test
import (
"encoding/json"
"fmt"
"net/http"
"os"
"testing"
"github.com/grafana-tools/sdk"
)
func getDebugURL(t *testing.T) string {
t.Helper()
resp, err := http.Get("http://localhost:9222/json/version")
if err != nil {
t.Fatal(err)
}
var result map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
t.Fatal(err)
}
return result["webSocketDebuggerUrl"].(string)
}
func getFullUrl(t *testing.T) (addr, user, pass string) {
t.Helper()
addr = "http://localhost:3000"
user = "admin"
pass = "admin"
if a := os.Getenv("GRAFANA_ADDR"); a != "" {
addr = a
}
if u := os.Getenv("GRAFANA_USER"); u != "" {
user = u
}
if p := os.Getenv("GRAFANA_PASS"); p != "" {
pass = p
}
return
}
func getClient(t *testing.T) *sdk.Client {
t.Helper()
addr, user, pass := getFullUrl(t)
cl, _ := sdk.NewClient(addr, fmt.Sprintf("%s:%s", user, pass), sdk.DefaultHTTPClient)
return cl
}
func shouldSkip(t *testing.T) {
t.Helper()
if v := os.Getenv("GRAFANA_INTEGRATION"); v != "1" {
t.Skipf("skipping because GRAFANA_INTEGRATION is %s, not 1", v)
}
}