Skip to content

Commit

Permalink
provide basic pattern for integration testing
Browse files Browse the repository at this point in the history
This seeks to address issue nytm#58.

It also illustrates the problem outlined in issue nytm#56, as
`TestAnnotationsIntegration` will fail until PR nytm#57 is merged.
  • Loading branch information
mdb committed Jul 19, 2020
1 parent 204577e commit 45d6a23
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 2 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,22 @@ Grafana HTTP API Client for Go

## Tests

To run the tests:
To run unit tests:

```
go test
make test
```

To run integration tests:

Start a `localhost:3000` Grafana:

```
make serve-grafana
```

Run the integration tests:

```
make integration-test:
```
85 changes: 85 additions & 0 deletions annotation_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// +build integration

package gapi

import (
"fmt"
"net/url"
"testing"
)

func TestAnnotationsIntegration(t *testing.T) {
client, err := New("admin:admin", "http://localhost:3000")
if err != nil {
t.Error(err)
}

_, err = client.Annotations(url.Values{})
if err != nil {
t.Error(err)
}
}

func TestNewAnnotationIntegration(t *testing.T) {
client, err := New("admin:admin", "http://localhost:3000")
if err != nil {
t.Error(err)
}

_, err = client.NewAnnotation(&Annotation{
Text: "integration-test-new",
})
if err != nil {
t.Error(err)
}
}

func TestUpdateAnnotationIntegration(t *testing.T) {
client, err := New("admin:admin", "http://localhost:3000")
if err != nil {
t.Error(err)
}

id, err := client.NewAnnotation(&Annotation{
Text: "integration-test-update",
})
if err != nil {
t.Error(err)
}

message, err := client.UpdateAnnotation(id, &Annotation{
Text: "integration-test-updated",
})
if err != nil {
t.Error(err)
}

expected := "Annotation updated"
if message != expected {
t.Error(fmt.Sprintf("expected UpdateAnnotation message to be %s; got %s", expected, message))
}
}

func TestDeleteAnnotationIntegration(t *testing.T) {
client, err := New("admin:admin", "http://localhost:3000")
if err != nil {
t.Error(err)
}

id, err := client.NewAnnotation(&Annotation{
Text: "integration-test-delete",
})
if err != nil {
t.Error(err)
}

message, err := client.DeleteAnnotation(id)
if err != nil {
t.Error(err)
}

expected := "Annotation deleted"
if message != expected {
t.Error(fmt.Sprintf("expected DeleteAnnotation message to be %s; got %s", expected, message))
}
}

0 comments on commit 45d6a23

Please sign in to comment.