-
Notifications
You must be signed in to change notification settings - Fork 191
/
rest-annotation_integration_test.go
61 lines (52 loc) · 1.18 KB
/
rest-annotation_integration_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
package sdk_test
import (
"context"
"testing"
"time"
"github.com/grafana-tools/sdk"
)
func TestAnnotations(t *testing.T) {
shouldSkip(t)
client := getClient(t)
ctx := context.Background()
ar := sdk.CreateAnnotationRequest{
Text: "test",
Time: time.Now().UnixNano() / 1000000,
}
resp, err := client.CreateAnnotation(ctx, ar)
if err != nil {
t.Fatal(err)
}
checkResponse(t, resp, "Annotation added")
id := *resp.ID
resp, err = client.PatchAnnotation(ctx, id, sdk.PatchAnnotationRequest{Text: "new text"})
if err != nil {
t.Fatal(err)
}
checkResponse(t, resp, "Annotation patched")
anns, err := client.GetAnnotations(ctx, sdk.WithLimit(100))
if err != nil {
t.Fatal(err)
}
var found bool
for _, a := range anns {
if a.ID == id {
found = true
}
}
if !found {
t.Errorf("annotation not found")
}
resp, err = client.DeleteAnnotation(ctx, id)
if err != nil {
t.Fatal(err)
}
checkResponse(t, resp, "Annotation deleted")
}
func checkResponse(t *testing.T, r sdk.StatusMessage, msg string) {
if r.Message == nil {
t.Errorf("expected message, but was nil")
} else if *r.Message != msg {
t.Errorf("expected message '%s', but got '%s'", msg, *r.Message)
}
}