Provisioning: Fix ImportAllPanelsFromLocalRepository test (#108441)
* Provisioning: Skip flaky test * Fix flaky provisioning test * Fix lint --------- Co-authored-by: Roberto Jimenez Sanchez <roberto.jimenez@grafana.com>
This commit is contained in:
@@ -575,38 +575,42 @@ func TestIntegrationProvisioning_ImportAllPanelsFromLocalRepository(t *testing.T
|
||||
helper := runGrafana(t)
|
||||
ctx := context.Background()
|
||||
|
||||
// The dashboard shouldn't exist yet
|
||||
const allPanels = "n1jR8vnnz"
|
||||
_, err := helper.DashboardsV1.Resource.Get(ctx, allPanels, metav1.GetOptions{})
|
||||
require.Error(t, err, "no all-panels dashboard should exist")
|
||||
require.True(t, apierrors.IsNotFound(err))
|
||||
|
||||
const repo = "local-tmp"
|
||||
// Set up the repository and the file to import.
|
||||
helper.CopyToProvisioningPath(t, "testdata/all-panels.json", "all-panels.json")
|
||||
|
||||
localTmp := helper.RenderObject(t, "testdata/local-write.json.tmpl", map[string]any{
|
||||
"Name": repo,
|
||||
"SyncEnabled": true,
|
||||
})
|
||||
_, err := helper.Repositories.Resource.Create(ctx, localTmp, metav1.CreateOptions{})
|
||||
|
||||
// We create the repository
|
||||
_, err = helper.Repositories.Resource.Create(ctx, localTmp, metav1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Now, we import it, such that it may exist
|
||||
// The sync may not be necessary as the sync may have happened automatically at this point
|
||||
helper.SyncAndWait(t, repo, nil)
|
||||
|
||||
// Make sure the repo can read and validate the file
|
||||
obj, err := helper.Repositories.Resource.Get(ctx, repo, metav1.GetOptions{}, "files", "all-panels.json")
|
||||
require.NoError(t, err, "valid path should be fine")
|
||||
|
||||
resource, _, err := unstructured.NestedMap(obj.Object, "resource")
|
||||
require.NoError(t, err, "missing resource")
|
||||
action, _, err := unstructured.NestedString(resource, "action")
|
||||
require.NoError(t, err, "invalid action")
|
||||
|
||||
require.NotNil(t, resource["file"], "the raw file")
|
||||
require.NotNil(t, resource["dryRun"], "dryRun result")
|
||||
require.Equal(t, "create", action)
|
||||
|
||||
// But the dashboard shouldn't exist yet
|
||||
const allPanels = "n1jR8vnnz"
|
||||
_, err = helper.DashboardsV1.Resource.Get(ctx, allPanels, metav1.GetOptions{})
|
||||
require.Error(t, err, "no all-panels dashboard should exist")
|
||||
require.True(t, apierrors.IsNotFound(err))
|
||||
|
||||
// Now, we import it, such that it may exist
|
||||
helper.SyncAndWait(t, repo, nil)
|
||||
action, _, err := unstructured.NestedString(resource, "action")
|
||||
require.NoError(t, err, "invalid action")
|
||||
// FIXME: there is no point in in returning action for a read / get request.
|
||||
require.Equal(t, "update", action)
|
||||
|
||||
_, err = helper.DashboardsV1.Resource.List(ctx, metav1.ListOptions{})
|
||||
require.NoError(t, err, "can list values")
|
||||
|
||||
Reference in New Issue
Block a user