-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexample_render_test.go
More file actions
42 lines (36 loc) · 921 Bytes
/
example_render_test.go
File metadata and controls
42 lines (36 loc) · 921 Bytes
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
package graphite
import (
"fmt"
"net/http"
"net/http/httptest"
"strconv"
)
func createTestServer() *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "[{\"target\": \"main\", \"datapoints\": [[1, 1468339853], [1.0, 1468339854], [null, 1468339855]]}]")
}))
}
func ExampleClient_QueryRender() {
ts := createTestServer()
defer ts.Close()
client, _ := NewFromString(ts.URL)
res, _ := client.QueryRender(
RenderRequest{
Targets: []string{"main"},
},
)
fmt.Printf(strconv.FormatInt(res[0].Datapoints[0].Timestamp.Unix(), 10))
// Output: 1468339853
}
func ExampleNewFromString() {
client, _ := NewFromString("http://my-graphite.tld")
fmt.Printf(client.Url.Host)
// Output: my-graphite.tld
}
func ExampleRequestError_Error() {
err := RequestError{
Type: "Error type",
}
fmt.Printf(err.Error())
// Output: Error type
}