From a6a12fa1229fc66b27e4528a68ab72b50d4bf1ea Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Wed, 14 Feb 2024 22:08:29 -0500 Subject: [PATCH] fix file test for unprivileged user Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- fwprovider/tests/resource_file_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/fwprovider/tests/resource_file_test.go b/fwprovider/tests/resource_file_test.go index 466b201b..3e0ce6d6 100644 --- a/fwprovider/tests/resource_file_test.go +++ b/fwprovider/tests/resource_file_test.go @@ -23,6 +23,8 @@ import ( "github.com/bpg/terraform-provider-proxmox/proxmox/api" "github.com/bpg/terraform-provider-proxmox/proxmox/ssh" + resourceSsh "github.com/bpg/terraform-provider-proxmox/proxmoxtf/resource/ssh" + "github.com/bpg/terraform-provider-proxmox/utils" ) @@ -144,13 +146,22 @@ func uploadSnippetFile(t *testing.T, file *os.File) { defer f.Close() - err = sshClient.NodeUpload(context.Background(), "pve", "/var/lib/vz", + fname := filepath.Base(file.Name()) + err = sshClient.NodeUpload(context.Background(), "pve", "/tmp/tfpve/testacc", &api.FileUploadRequest{ ContentType: "snippets", - FileName: filepath.Base(file.Name()), + FileName: fname, File: f, }) require.NoError(t, err) + + _, err = sshClient.ExecuteNodeCommands(context.Background(), "pve", []string{ + fmt.Sprintf(`%s; try_sudo "mv /tmp/tfpve/testacc/snippets/%s /var/lib/vz/snippets/%s" && rm -rf /tmp/tfpve/testacc/`, + resourceSsh.TrySudo, + fname, fname, + ), + }) + require.NoError(t, err) } func createFile(t *testing.T, namePattern string, content string) *os.File {