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

Integration tests #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
}