Skip to content

Commit 0dbede9

Browse files
Provisioning: Fix ImportAllPanelsFromLocalRepository test (#108441)
* Provisioning: Skip flaky test * Fix flaky provisioning test * Fix lint --------- Co-authored-by: Roberto Jimenez Sanchez <[email protected]>
1 parent 482872c commit 0dbede9

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

pkg/tests/apis/provisioning/provisioning_test.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -575,38 +575,42 @@ func TestIntegrationProvisioning_ImportAllPanelsFromLocalRepository(t *testing.T
575575
helper := runGrafana(t)
576576
ctx := context.Background()
577577

578+
// The dashboard shouldn't exist yet
579+
const allPanels = "n1jR8vnnz"
580+
_, err := helper.DashboardsV1.Resource.Get(ctx, allPanels, metav1.GetOptions{})
581+
require.Error(t, err, "no all-panels dashboard should exist")
582+
require.True(t, apierrors.IsNotFound(err))
583+
578584
const repo = "local-tmp"
579585
// Set up the repository and the file to import.
580586
helper.CopyToProvisioningPath(t, "testdata/all-panels.json", "all-panels.json")
581-
582587
localTmp := helper.RenderObject(t, "testdata/local-write.json.tmpl", map[string]any{
583588
"Name": repo,
584589
"SyncEnabled": true,
585590
})
586-
_, err := helper.Repositories.Resource.Create(ctx, localTmp, metav1.CreateOptions{})
591+
592+
// We create the repository
593+
_, err = helper.Repositories.Resource.Create(ctx, localTmp, metav1.CreateOptions{})
587594
require.NoError(t, err)
588595

596+
// Now, we import it, such that it may exist
597+
// The sync may not be necessary as the sync may have happened automatically at this point
598+
helper.SyncAndWait(t, repo, nil)
599+
589600
// Make sure the repo can read and validate the file
590601
obj, err := helper.Repositories.Resource.Get(ctx, repo, metav1.GetOptions{}, "files", "all-panels.json")
591602
require.NoError(t, err, "valid path should be fine")
592603

593604
resource, _, err := unstructured.NestedMap(obj.Object, "resource")
594605
require.NoError(t, err, "missing resource")
595-
action, _, err := unstructured.NestedString(resource, "action")
596606
require.NoError(t, err, "invalid action")
597-
598607
require.NotNil(t, resource["file"], "the raw file")
599608
require.NotNil(t, resource["dryRun"], "dryRun result")
600-
require.Equal(t, "create", action)
601-
602-
// But the dashboard shouldn't exist yet
603-
const allPanels = "n1jR8vnnz"
604-
_, err = helper.DashboardsV1.Resource.Get(ctx, allPanels, metav1.GetOptions{})
605-
require.Error(t, err, "no all-panels dashboard should exist")
606-
require.True(t, apierrors.IsNotFound(err))
607609

608-
// Now, we import it, such that it may exist
609-
helper.SyncAndWait(t, repo, nil)
610+
action, _, err := unstructured.NestedString(resource, "action")
611+
require.NoError(t, err, "invalid action")
612+
// FIXME: there is no point in in returning action for a read / get request.
613+
require.Equal(t, "update", action)
610614

611615
_, err = helper.DashboardsV1.Resource.List(ctx, metav1.ListOptions{})
612616
require.NoError(t, err, "can list values")

0 commit comments

Comments
 (0)