/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ package tests import ( "context" "fmt" "net/url" "os" "path/filepath" "regexp" "strings" "testing" "github.com/brianvoe/gofakeit/v7" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/require" "github.com/bpg/terraform-provider-proxmox/proxmox/api" "github.com/bpg/terraform-provider-proxmox/proxmox/ssh" "github.com/bpg/terraform-provider-proxmox/utils" ) type nodeResolver struct { node ssh.ProxmoxNode } func (c *nodeResolver) Resolve(_ context.Context, _ string) (ssh.ProxmoxNode, error) { return c.node, nil } func TestAccResourceFile(t *testing.T) { te := initTestEnvironment(t) snippetRaw := fmt.Sprintf("snippet-raw-%s.txt", gofakeit.Word()) snippetURL := "https://raw.githubusercontent.com/yaml/yaml-test-suite/main/src/229Q.yaml" snippetFile1 := strings.ReplaceAll(createFile(t, "snippet-file-1-*.yaml", "test snippet 1 - file").Name(), `\`, `/`) snippetFile2 := strings.ReplaceAll(createFile(t, "snippet-file-2-*.yaml", "test snippet 2 - file").Name(), `\`, `/`) fileISO := strings.ReplaceAll(createFile(t, "file-*.iso", "pretend it is an ISO").Name(), `\`, `/`) te.addTemplateVars(map[string]interface{}{ "SnippetRaw": snippetRaw, "SnippetURL": snippetURL, "SnippetFile1": snippetFile1, "SnippetFile2": snippetFile2, "FileISO": fileISO, }) resource.ParallelTest(t, resource.TestCase{ ProtoV6ProviderFactories: te.accProviders, PreCheck: func() { uploadSnippetFile(t, snippetFile2) t.Cleanup(func() { deleteSnippet(te, filepath.Base(snippetFile1)) deleteSnippet(te, filepath.Base(snippetFile2)) _ = os.Remove(snippetFile1) _ = os.Remove(snippetFile2) _ = os.Remove(fileISO) }) }, Steps: []resource.TestStep{ { Config: te.renderConfig(` resource "proxmox_virtual_environment_file" "test_raw" { content_type = "snippets" datastore_id = "local" node_name = "{{.NodeName}}" source_raw { data = <