From 0936b234da0229d9afd4170e43007331163ef878 Mon Sep 17 00:00:00 2001 From: Julien Duchesne Date: Fri, 2 Feb 2024 11:00:31 -0500 Subject: [PATCH] Test the case where a dashboard has no specified folder Closes https://github.com/grafana/grizzly/issues/201 A bug that is already fixed but untested --- integration/dashboard_test.go | 17 +++++++++++++++++ integration/testdata/dashboards/no-folder.yml | 11 +++++++++++ integration/utils_test.go | 12 ++++++++---- 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 integration/testdata/dashboards/no-folder.yml diff --git a/integration/dashboard_test.go b/integration/dashboard_test.go index ec307a1d..e0e78ef2 100644 --- a/integration/dashboard_test.go +++ b/integration/dashboard_test.go @@ -22,6 +22,23 @@ func TestDashboard(t *testing.T) { }) }) + 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", + }, + }, + }) + }) + t.Run("Get dashboard - failure", func(t *testing.T) { runTest(t, GrizzlyTest{ TestDir: dir, diff --git a/integration/testdata/dashboards/no-folder.yml b/integration/testdata/dashboards/no-folder.yml new file mode 100644 index 00000000..5a14a377 --- /dev/null +++ b/integration/testdata/dashboards/no-folder.yml @@ -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 diff --git a/integration/utils_test.go b/integration/utils_test.go index 4631d303..9e03d1f8 100644 --- a/integration/utils_test.go +++ b/integration/utils_test.go @@ -14,10 +14,11 @@ 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 + ExpectedOutputContains string } type GrizzlyTest struct { TestDir string @@ -50,6 +51,9 @@ func runTest(t *testing.T, test GrizzlyTest) { require.NoError(t, err) require.Equal(t, string(data), stdout) } + if command.ExpectedOutputContains != "" { + require.Contains(t, stdout, command.ExpectedOutputContains) + } } if test.Validate != nil { test.Validate(t)