Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit 4fdbeb5

Browse files
committed
fix stale annotations tests
1 parent b55ac47 commit 4fdbeb5

File tree

3 files changed

+50
-46
lines changed

3 files changed

+50
-46
lines changed

annotation.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"io/ioutil"
9+
"net/url"
910
)
1011

1112
// Annotation represents a Grafana API Annotation
@@ -37,9 +38,8 @@ type GraphiteAnnotation struct {
3738
}
3839

3940
// Annotations fetches the annotations queried with the params it's passed
40-
func (c *Client) Annotations(params map[string]string) ([]Annotation, error) {
41-
pathAndQuery := buildPathAndQuery("/api/annotations", params)
42-
req, err := c.newRequest("GET", pathAndQuery, nil)
41+
func (c *Client) Annotations(params url.Values) ([]Annotation, error) {
42+
req, err := c.newRequest("GET", "/api/annotation", params, nil)
4343
if err != nil {
4444
return nil, err
4545
}
@@ -68,7 +68,7 @@ func (c *Client) NewAnnotation(a *Annotation) (int64, error) {
6868
if err != nil {
6969
return 0, err
7070
}
71-
req, err := c.newRequest("POST", "/api/annotations", bytes.NewBuffer(data))
71+
req, err := c.newRequest("POST", "/api/annotations", nil, bytes.NewBuffer(data))
7272
if err != nil {
7373
return 0, err
7474
}
@@ -99,7 +99,7 @@ func (c *Client) NewGraphiteAnnotation(gfa *GraphiteAnnotation) (int64, error) {
9999
if err != nil {
100100
return 0, err
101101
}
102-
req, err := c.newRequest("POST", "/api/annotations/graphite", bytes.NewBuffer(data))
102+
req, err := c.newRequest("POST", "/api/annotations/graphite", nil, bytes.NewBuffer(data))
103103
if err != nil {
104104
return 0, err
105105
}
@@ -131,7 +131,7 @@ func (c *Client) UpdateAnnotation(a *Annotation) (int64, error) {
131131
if err != nil {
132132
return 0, err
133133
}
134-
req, err := c.newRequest("PUT", path, bytes.NewBuffer(data))
134+
req, err := c.newRequest("PUT", path, nil, bytes.NewBuffer(data))
135135
if err != nil {
136136
return 0, err
137137
}
@@ -159,7 +159,7 @@ func (c *Client) UpdateAnnotation(a *Annotation) (int64, error) {
159159
// DeleteAnnotation deletes the annotation of the ID it is passed
160160
func (c *Client) DeleteAnnotation(id int64) (string, error) {
161161
path := fmt.Sprintf("/api/annotations/%d", id)
162-
req, err := c.newRequest("DELETE", path, bytes.NewBuffer(nil))
162+
req, err := c.newRequest("DELETE", path, nil, bytes.NewBuffer(nil))
163163
if err != nil {
164164
return "", err
165165
}
@@ -187,7 +187,7 @@ func (c *Client) DeleteAnnotation(id int64) (string, error) {
187187
// DeleteAnnotationByRegionID deletes the annotation corresponding to the region ID it is passed
188188
func (c *Client) DeleteAnnotationByRegionID(id int64) (string, error) {
189189
path := fmt.Sprintf("/api/annotations/region/%d", id)
190-
req, err := c.newRequest("DELETE", path, bytes.NewBuffer(nil))
190+
req, err := c.newRequest("DELETE", path, nil, bytes.NewBuffer(nil))
191191
if err != nil {
192192
return "", err
193193
}

annotation_test.go

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,57 @@
11
package gapi
22

33
import (
4+
"net/url"
45
"testing"
56

67
"github.com/gobs/pretty"
78
)
89

10+
const (
11+
annotationsJSON = `[{
12+
"id": 1124,
13+
"alertId": 0,
14+
"dashboardId": 468,
15+
"panelId": 2,
16+
"userId": 1,
17+
"userName": "",
18+
"newState": "",
19+
"prevState": "",
20+
"time": 1507266395000,
21+
"text": "test",
22+
"metric": "",
23+
"regionId": 1123,
24+
"type": "event",
25+
"tags": [
26+
"tag1",
27+
"tag2"
28+
],
29+
"data": {}
30+
}]`
31+
32+
newAnnotationJSON = `{
33+
"message":"Annotation added",
34+
"id": 1,
35+
"endId": 2
36+
}`
37+
38+
newGraphiteAnnotationJSON = `{
39+
"message":"Annotation added",
40+
"id": 1
41+
}`
42+
43+
deleteAnnotationJSON = `{"message":"Annotation deleted"}`
44+
)
45+
946
func TestAnnotations(t *testing.T) {
1047
server, client := gapiTestTools(200, annotationsJSON)
1148
defer server.Close()
1249

13-
params := map[string]string{
14-
"from": "1506676478816",
15-
"to": "1507281278816",
16-
"limit": "100",
17-
}
50+
params := url.Values{}
51+
params.Add("from", "1506676478816")
52+
params.Add("to", "1507281278816")
53+
params.Add("limit", "100")
54+
1855
as, err := client.Annotations(params)
1956
if err != nil {
2057
t.Error(err)

grafana_testing_tools_test.go

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)