forked from nytm/go-grafana-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provide basic pattern for integration testing
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
Showing
2 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |