Skip to content

Commit

Permalink
Test the case where a dashboard has no specified folder (#326)
Browse files Browse the repository at this point in the history
* Test the case where a dashboard has no specified folder
Closes #201
A bug that is already fixed but untested

* Fix tests
Bringing in features from #325
  • Loading branch information
julienduchesne authored Feb 2, 2024
1 parent 73bf6ed commit 3a045eb
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
6 changes: 3 additions & 3 deletions integration/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ func TestContexts(t *testing.T) {
TestDir: "testdata/contexts",
Commands: []Command{
{
Command: "config get-contexts",
ExpectedCode: 0,
ExpectedOutput: "get-contexts.txt",
Command: "config get-contexts",
ExpectedCode: 0,
ExpectedOutputFile: "get-contexts.txt",
},
},
})
Expand Down
23 changes: 20 additions & 3 deletions integration/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,26 @@ func TestDashboard(t *testing.T) {
RunOnContexts: allContexts,
Commands: []Command{
{
Command: "get Dashboard.ReciqtgGk",
ExpectedCode: 0,
ExpectedOutput: "ReciqtgGk.json",
Command: "get Dashboard.ReciqtgGk",
ExpectedCode: 0,
ExpectedOutputFile: "ReciqtgGk.json",
},
},
})
})

t.Run("Apply dashboard - no folder", func(t *testing.T) {
runTest(t, GrizzlyTest{
TestDir: dir,
RunOnContexts: allContexts,
Commands: []Command{
{
Command: "apply no-folder.yml",
ExpectedOutput: "Dashboard.no-folder added\n",
},
{
Command: "get Dashboard.no-folder",
ExpectedOutputContains: "folder: general",
},
},
})
Expand Down
11 changes: 11 additions & 0 deletions integration/testdata/dashboards/no-folder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: grizzly.grafana.com/v1alpha1
kind: Dashboard
metadata:
name: no-folder
spec:
schemaVersion: 17
tags:
- templated
timezone: browser
title: No Folder
uid: no-folder
23 changes: 16 additions & 7 deletions integration/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import (
var allContexts = []string{"default", "subpath", "basic_auth"}

type Command struct {
Command string
ExpectedCode int
ExpectedError error
ExpectedOutput string
Command string
ExpectedCode int
ExpectedError error
ExpectedOutput string
ExpectedOutputFile string
ExpectedOutputContains string
}
type GrizzlyTest struct {
TestDir string
Expand Down Expand Up @@ -45,10 +47,17 @@ func runTest(t *testing.T, test GrizzlyTest) {
require.Error(t, err, command.ExpectedError)
}
require.Equal(t, command.ExpectedCode, exitCode, "Exited with %d (%d expected).\nOutput: %s\nstderr: %s", exitCode, command.ExpectedCode, stdout, stderr)
if command.ExpectedOutput != "" {
data, err := os.ReadFile(filepath.Join(test.TestDir, command.ExpectedOutput))
// Check stdout
if command.ExpectedOutputFile != "" {
bytes, err := os.ReadFile(filepath.Join(test.TestDir, command.ExpectedOutputFile))
require.NoError(t, err)
require.Equal(t, string(data), stdout)
command.ExpectedOutput = string(bytes)
}
if command.ExpectedOutput != "" {
require.Equal(t, command.ExpectedOutput, stdout)
}
if command.ExpectedOutputContains != "" {
require.Contains(t, stdout, command.ExpectedOutputContains)
}
}
if test.Validate != nil {
Expand Down

0 comments on commit 3a045eb

Please sign in to comment.