Skip to content

Commit

Permalink
Add a few unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Phoen committed Apr 2, 2021
1 parent 79c5828 commit 75c23fb
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
9 changes: 9 additions & 0 deletions dashboard/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/K-Phoen/grabana/variable/datasource"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -155,6 +156,14 @@ func TestDashboardCanHaveVariablesAsQuery(t *testing.T) {
req.Len(panel.board.Templating.List, 1)
}

func TestDashboardCanHaveVariablesAsDatasource(t *testing.T) {
req := require.New(t)

panel := New("", VariableAsDatasource("source", datasource.Type("prometheus")))

req.Len(panel.board.Templating.List, 1)
}

func TestDashboardCanHaveRows(t *testing.T) {
req := require.New(t)

Expand Down
10 changes: 10 additions & 0 deletions graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package graph
import (
"testing"

"github.com/K-Phoen/grabana/graph/series"

"github.com/K-Phoen/grabana/axis"
"github.com/K-Phoen/grabana/target/stackdriver"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -260,3 +262,11 @@ func TestLegendCanHideNullSeries(t *testing.T) {

req.True(panel.Builder.GraphPanel.Legend.HideEmpty)
}

func TestSeriesOverridesCanBeAdded(t *testing.T) {
req := require.New(t)

panel := New("", SeriesOverride(series.Alias("series"), series.Color("red")))

req.Len(panel.Builder.GraphPanel.SeriesOverrides, 1)
}
1 change: 1 addition & 0 deletions graph/series/override.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
// OverrideOption represents an option that can be used alter a graph panel series.
type OverrideOption func(series *sdk.SeriesOverride)

// Alis defines an alias/regex used to identify the series to override.
func Alias(alias string) OverrideOption {
return func(series *sdk.SeriesOverride) {
series.Alias = alias
Expand Down
67 changes: 67 additions & 0 deletions graph/series/override_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package series

import (
"testing"

"github.com/grafana-tools/sdk"
"github.com/stretchr/testify/require"
)

func TestAliasCanBeDefined(t *testing.T) {
req := require.New(t)
series := &sdk.SeriesOverride{}

Alias("Error - .*")(series)

req.Equal("Error - .*", series.Alias)
}

func TestColorCanBeDefined(t *testing.T) {
req := require.New(t)
series := &sdk.SeriesOverride{}

Color("#65c5db")(series)

req.NotNil(series.Color)
req.Equal("#65c5db", *series.Color)
}

func TestDashesCanBeEnabled(t *testing.T) {
req := require.New(t)
series := &sdk.SeriesOverride{}

Dashes(true)(series)

req.NotNil(series.Dashes)
req.True(*series.Dashes)
}

func TestLinesCanBeEnabled(t *testing.T) {
req := require.New(t)
series := &sdk.SeriesOverride{}

Lines(true)(series)

req.NotNil(series.Lines)
req.True(*series.Lines)
}

func TestFillOpacityCanBeDefined(t *testing.T) {
req := require.New(t)
series := &sdk.SeriesOverride{}

Fill(2)(series)

req.NotNil(*series.Fill)
req.Equal(2, *series.Fill)
}

func TestLineWidthCanBeDefined(t *testing.T) {
req := require.New(t)
series := &sdk.SeriesOverride{}

LineWidth(3)(series)

req.NotNil(*series.LineWidth)
req.Equal(3, *series.LineWidth)
}

0 comments on commit 75c23fb

Please sign in to comment.