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

Test the case where a dashboard has no specified folder #326

Merged
merged 2 commits into from
Feb 2, 2024
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
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
Loading