-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexample_metrics_test.go
More file actions
50 lines (42 loc) · 1.29 KB
/
example_metrics_test.go
File metadata and controls
50 lines (42 loc) · 1.29 KB
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
package graphite
import (
"fmt"
"net/http"
"net/http/httptest"
)
func createFindMetricsTestServer() *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `[
{"text": "one", "expandable": 1, "leaf": 0, "id": "cluster.one", "allowChildren": 1},
{"text": "two", "expandable": 1, "leaf": 0, "id": "cluster.two", "allowChildren": 1}]`)
}))
}
func ExampleClient_FindMetrics() {
ts := createFindMetricsTestServer()
defer ts.Close()
client, _ := NewFromString(ts.URL)
res, _ := client.FindMetrics(
FindMetricRequest{
Query: "cluster.*",
},
)
fmt.Printf("%+v", res)
// Output: [{Id:cluster.one Text:one Expandable:1 Leaf:0 AllowChildren:1} {Id:cluster.two Text:two Expandable:1 Leaf:0 AllowChildren:1}]
}
func createExpandMetricsTestServer() *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "{\"results\": [\"cluster.one\", \"cluster.two\"]}")
}))
}
func ExampleClient_ExpandMetrics() {
ts := createExpandMetricsTestServer()
defer ts.Close()
client, _ := NewFromString(ts.URL)
res, _ := client.ExpandMetrics(
ExpandMetricRequest{
Query: "cluster.*",
},
)
fmt.Printf("%+v", res)
// Output: {Results:[cluster.one cluster.two]}
}