Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Commit 5543779

Browse files
committed
provide basic pattern for integration testing
This seeks to address issue #58. It also illustrates the problem outlined in issue #56, as `TestAnnotationsIntegration` will fail until PR #57 is merged.
1 parent 249aba6 commit 5543779

File tree

2 files changed

+101
-2
lines changed

2 files changed

+101
-2
lines changed

README.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,22 @@ Grafana HTTP API Client for Go
66

77
## Tests
88

9-
To run the tests:
9+
To run unit tests:
1010

1111
```
12-
go test
12+
make test
13+
```
14+
15+
To run integration tests:
16+
17+
Start a `localhost:3000` Grafana:
18+
19+
```
20+
make serve-grafana
21+
```
22+
23+
Run the integration tests:
24+
25+
```
26+
make integration-test:
1327
```

annotation_integration_test.go

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// +build integration
2+
3+
package gapi
4+
5+
import (
6+
"fmt"
7+
"net/url"
8+
"testing"
9+
)
10+
11+
func TestAnnotationsIntegration(t *testing.T) {
12+
client, err := New("admin:admin", "http://localhost:3000")
13+
if err != nil {
14+
t.Error(err)
15+
}
16+
17+
_, err = client.Annotations(url.Values{})
18+
if err != nil {
19+
t.Error(err)
20+
}
21+
}
22+
23+
func TestNewAnnotationIntegration(t *testing.T) {
24+
client, err := New("admin:admin", "http://localhost:3000")
25+
if err != nil {
26+
t.Error(err)
27+
}
28+
29+
_, err = client.NewAnnotation(&Annotation{
30+
Text: "integration-test-new",
31+
})
32+
if err != nil {
33+
t.Error(err)
34+
}
35+
}
36+
37+
func TestUpdateAnnotationIntegration(t *testing.T) {
38+
client, err := New("admin:admin", "http://localhost:3000")
39+
if err != nil {
40+
t.Error(err)
41+
}
42+
43+
id, err := client.NewAnnotation(&Annotation{
44+
Text: "integration-test-update",
45+
})
46+
if err != nil {
47+
t.Error(err)
48+
}
49+
50+
message, err := client.UpdateAnnotation(id, &Annotation{
51+
Text: "integration-test-updated",
52+
})
53+
if err != nil {
54+
t.Error(err)
55+
}
56+
57+
expected := "Annotation updated"
58+
if message != expected {
59+
t.Error(fmt.Sprintf("expected UpdateAnnotation message to be %s; got %s", expected, message))
60+
}
61+
}
62+
63+
func TestDeleteAnnotationIntegration(t *testing.T) {
64+
client, err := New("admin:admin", "http://localhost:3000")
65+
if err != nil {
66+
t.Error(err)
67+
}
68+
69+
id, err := client.NewAnnotation(&Annotation{
70+
Text: "integration-test-delete",
71+
})
72+
if err != nil {
73+
t.Error(err)
74+
}
75+
76+
message, err := client.DeleteAnnotation(id)
77+
if err != nil {
78+
t.Error(err)
79+
}
80+
81+
expected := "Annotation deleted"
82+
if message != expected {
83+
t.Error(fmt.Sprintf("expected DeleteAnnotation message to be %s; got %s", expected, message))
84+
}
85+
}

0 commit comments

Comments
 (0)