Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move test to *_test package #22

Merged
merged 1 commit into from
Sep 5, 2018
Merged
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
20 changes: 12 additions & 8 deletions board_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sdk
package sdk_test

/*
Copyright 2016 Alexander I.Grafov <[email protected]>
Expand All @@ -18,10 +18,14 @@ package sdk
ॐ तारे तुत्तारे तुरे स्व
*/

import "testing"
import (
"testing"

"github.com/grafana-tools/sdk"
)

func TestAddTags(t *testing.T) {
b := NewBoard("Sample")
b := sdk.NewBoard("Sample")

b.AddTags("1", "2", "3")

Expand All @@ -31,7 +35,7 @@ func TestAddTags(t *testing.T) {
}

func TestBoardRemoveTags_Existent(t *testing.T) {
b := NewBoard("Sample")
b := sdk.NewBoard("Sample")
b.AddTags("1", "2", "3", "4")

b.RemoveTags("1", "2")
Expand All @@ -42,7 +46,7 @@ func TestBoardRemoveTags_Existent(t *testing.T) {
}

func TestBoardRemoveTags_NonExistent(t *testing.T) {
b := NewBoard("Sample")
b := sdk.NewBoard("Sample")
b.AddTags("1", "2")

b.RemoveTags("3", "4")
Expand All @@ -53,7 +57,7 @@ func TestBoardRemoveTags_NonExistent(t *testing.T) {
}

func TestBoardRemoveTags_WhenNoTags(t *testing.T) {
b := NewBoard("Sample")
b := sdk.NewBoard("Sample")

b.RemoveTags("1", "2")

Expand All @@ -63,7 +67,7 @@ func TestBoardRemoveTags_WhenNoTags(t *testing.T) {
}

func TestBoardHasTag_TagExists(t *testing.T) {
b := NewBoard("Sample")
b := sdk.NewBoard("Sample")
b.AddTags("1", "2", "3")

if !b.HasTag("2") {
Expand All @@ -72,7 +76,7 @@ func TestBoardHasTag_TagExists(t *testing.T) {
}

func TestBoardHasTag_TagNotExists(t *testing.T) {
b := NewBoard("Sample")
b := sdk.NewBoard("Sample")
b.AddTags("1", "2")

if b.HasTag("3") {
Expand Down
2 changes: 1 addition & 1 deletion cmd/import-datasources/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func main() {
}
}
if status, err = c.CreateDatasource(newDS); err != nil {
fmt.Fprint(os.Stderr, fmt.Sprintf("error on importing datasource %s with %s (%s)", newDS.Name, err, status.Message))
fmt.Fprint(os.Stderr, fmt.Sprintf("error on importing datasource %s with %s (%s)", newDS.Name, err, *status.Message))
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions custom-types_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sdk
package sdk_test

/*
Copyright 2016 Alexander I.Grafov <[email protected]>
Expand All @@ -22,10 +22,12 @@ import (
"bytes"
"encoding/json"
"testing"

"github.com/grafana-tools/sdk"
)

func TestIntString_Unmarshal(t *testing.T) {
var i IntString
var i sdk.IntString
raw := []byte(`100`)

err := json.Unmarshal(raw, &i)
Expand All @@ -43,7 +45,7 @@ func TestIntString_Unmarshal(t *testing.T) {
}

func TestIntString_Marshal(t *testing.T) {
i := NewIntString(100)
i := sdk.NewIntString(100)

body, err := json.Marshal(i)
if err != nil {
Expand Down
34 changes: 18 additions & 16 deletions dashboard-unmarshal_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sdk
package sdk_test

/*
Copyright 2016 Alexander I.Grafov <[email protected]>
Expand All @@ -22,10 +22,12 @@ import (
"encoding/json"
"io/ioutil"
"testing"

"github.com/grafana-tools/sdk"
)

func TestUnmarshal_NewEmptyDashboard26(t *testing.T) {
var board Board
var board sdk.Board
raw, _ := ioutil.ReadFile("testdata/new-empty-dashboard-2.6.json")

err := json.Unmarshal(raw, &board)
Expand All @@ -36,7 +38,7 @@ func TestUnmarshal_NewEmptyDashboard26(t *testing.T) {
}

func TestUnmarshal_EmptyDashboardWithTemplating26(t *testing.T) {
var board Board
var board sdk.Board
raw, _ := ioutil.ReadFile("testdata/empty-dashboard-with-templating-2.6.json")

err := json.Unmarshal(raw, &board)
Expand All @@ -47,7 +49,7 @@ func TestUnmarshal_EmptyDashboardWithTemplating26(t *testing.T) {
}

func TestUnmarshal_EmptyDashboardWithAnnotation26(t *testing.T) {
var board Board
var board sdk.Board
raw, _ := ioutil.ReadFile("testdata/empty-dashboard-with-annotation-2.6.json")

err := json.Unmarshal(raw, &board)
Expand All @@ -58,7 +60,7 @@ func TestUnmarshal_EmptyDashboardWithAnnotation26(t *testing.T) {
}

func TestUnmarshal_EmptyDashboardWithLinks26(t *testing.T) {
var board Board
var board sdk.Board
raw, _ := ioutil.ReadFile("testdata/empty-dashboard-with-links-2.6.json")

err := json.Unmarshal(raw, &board)
Expand All @@ -69,7 +71,7 @@ func TestUnmarshal_EmptyDashboardWithLinks26(t *testing.T) {
}

func TestUnmarshal_DashboardWithDefaultPanelsIn2Rows26(t *testing.T) {
var board Board
var board sdk.Board
raw, _ := ioutil.ReadFile("testdata/default-panels-all-types-2-rows-dashboard-2.6.json")

err := json.Unmarshal(raw, &board)
Expand All @@ -80,7 +82,7 @@ func TestUnmarshal_DashboardWithDefaultPanelsIn2Rows26(t *testing.T) {
}

func TestUnmarshal_DashboardWithGraphWithTargets26(t *testing.T) {
var board Board
var board sdk.Board
raw, _ := ioutil.ReadFile("testdata/default-panels-graph-with-targets-2.6.json")

err := json.Unmarshal(raw, &board)
Expand All @@ -95,19 +97,19 @@ func TestUnmarshal_DashboardWithGraphWithTargets26(t *testing.T) {
t.Errorf("there are 1 panel defined but got %d", len(board.Rows[0].Panels))
}
panel := board.Rows[0].Panels[0]
if panel.OfType != GraphType {
t.Errorf("panel type should be %d (\"graph\") type but got %d", GraphType, panel.OfType)
if panel.OfType != sdk.GraphType {
t.Errorf("panel type should be %d (\"graph\") type but got %d", sdk.GraphType, panel.OfType)
}
if *panel.Datasource != MixedSource {
t.Errorf("panel Datasource should be \"%s\" but got \"%s\"", MixedSource, *panel.Datasource)
if *panel.Datasource != sdk.MixedSource {
t.Errorf("panel Datasource should be \"%s\" but got \"%s\"", sdk.MixedSource, *panel.Datasource)
}
if len(panel.GraphPanel.Targets) != 2 {
t.Errorf("panel has 2 targets but got %d", len(panel.GraphPanel.Targets))
}
}

func TestUnmarshal_DashboardWithEmptyPanels30(t *testing.T) {
var board Board
var board sdk.Board
raw, _ := ioutil.ReadFile("testdata/dashboard-with-default-panels-grafana-3.0.json")

err := json.Unmarshal(raw, &board)
Expand All @@ -118,7 +120,7 @@ func TestUnmarshal_DashboardWithEmptyPanels30(t *testing.T) {
}

func TestUnmarshal_DashboardWithHiddenTemplates(t *testing.T) {
var board Board
var board sdk.Board
raw, _ := ioutil.ReadFile("testdata/empty-dashboard-with-templating-4.0.json")

err := json.Unmarshal(raw, &board)
Expand All @@ -127,13 +129,13 @@ func TestUnmarshal_DashboardWithHiddenTemplates(t *testing.T) {
t.Error(err)
}

if board.Templating.List[1].Hide != TemplatingHideVariable {
t.Errorf("templating has hidden variable '%d', got %d", TemplatingHideVariable, board.Templating.List[1].Hide)
if board.Templating.List[1].Hide != sdk.TemplatingHideVariable {
t.Errorf("templating has hidden variable '%d', got %d", sdk.TemplatingHideVariable, board.Templating.List[1].Hide)
}
}

func TestUnmarshal_DashboardWithMixedYaxes(t *testing.T) {
var board Board
var board sdk.Board
raw, _ := ioutil.ReadFile("testdata/dashboard-with-panels-with-mixed-yaxes.json")

err := json.Unmarshal(raw, &board)
Expand Down
Loading