Provisioning: Fix flake in delete resources integration test (#108507)

* Fix flake in delete resources test

* Fix linting issue
This commit is contained in:
Roberto Jiménez Sánchez
2025-07-23 11:43:57 +01:00
committed by GitHub
parent 0e7b041b27
commit 24d898d6a7
2 changed files with 12 additions and 38 deletions
+5 -1
View File
@@ -184,8 +184,12 @@ func (h *provisioningTestHelper) RenderObject(t *testing.T, filePath string, val
// CopyToProvisioningPath copies a file to the provisioning path.
// The from path is relative to test file's directory.
func (h *provisioningTestHelper) CopyToProvisioningPath(t *testing.T, from, to string) {
fullPath := path.Join(h.ProvisioningPath, to)
err := os.MkdirAll(path.Dir(fullPath), 0750)
require.NoError(t, err, "failed to create directories for provisioning path")
file := h.LoadFile(from)
err := os.WriteFile(path.Join(h.ProvisioningPath, to), file, 0600)
err = os.WriteFile(fullPath, file, 0600)
require.NoError(t, err, "failed to write file to provisioning path")
}
@@ -743,46 +743,16 @@ func TestIntegrationProvisioning_DeleteResources(t *testing.T) {
_, err := helper.Repositories.Resource.Create(ctx, localTmp, metav1.CreateOptions{})
require.NoError(t, err)
// create the structure:
// dashboard1.json
// folder/
// dashboard2.json
// nested/
// dashboard3.json
dashboard1 := helper.LoadFile("testdata/all-panels.json")
result := helper.AdminREST.Post().
Namespace("default").
Resource("repositories").
Name(repo).
SubResource("files", "dashboard1.json").
Body(dashboard1).
SetHeader("Content-Type", "application/json").
Do(ctx)
require.NoError(t, result.Error())
dashboard2 := helper.LoadFile("testdata/text-options.json")
result = helper.AdminREST.Post().
Namespace("default").
Resource("repositories").
Name(repo).
SubResource("files", "folder", "dashboard2.json").
Body(dashboard2).
SetHeader("Content-Type", "application/json").
Do(ctx)
require.NoError(t, result.Error())
dashboard3 := helper.LoadFile("testdata/timeline-demo.json")
result = helper.AdminREST.Post().
Namespace("default").
Resource("repositories").
Name(repo).
SubResource("files", "folder", "nested", "dashboard3.json").
Body(dashboard3).
SetHeader("Content-Type", "application/json").
Do(ctx)
require.NoError(t, result.Error())
// Copy the dashboards to the repository path
helper.CopyToProvisioningPath(t, "testdata/all-panels.json", "dashboard1.json")
helper.CopyToProvisioningPath(t, "testdata/text-options.json", "folder/dashboard2.json")
helper.CopyToProvisioningPath(t, "testdata/timeline-demo.json", "folder/nested/dashboard3.json")
// make sure we don't fail when there is a .keep file in a folder
helper.CopyToProvisioningPath(t, "testdata/.keep", "folder/nested/.keep")
// Trigger and wait for a sync job to finish
helper.SyncAndWait(t, repo, nil)
dashboards, err := helper.DashboardsV1.Resource.List(ctx, metav1.ListOptions{})
require.NoError(t, err)
require.Equal(t, 3, len(dashboards.Items))