From 6cd7b99e65249ce94267d8d5f3aabc418068091a Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Thu, 21 Mar 2024 20:14:01 -0400 Subject: [PATCH 01/10] chore(tests): configure more acceptance test parameters via env vars Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- fwprovider/tests/datasource_version_test.go | 5 +- fwprovider/tests/resource_container_test.go | 47 +++--- .../tests/resource_download_file_test.go | 28 ++-- fwprovider/tests/resource_file_test.go | 64 +++---- .../tests/resource_linux_bridge_test.go | 9 +- fwprovider/tests/resource_linux_vlan_test.go | 23 ++- fwprovider/tests/resource_options_test.go | 5 +- fwprovider/tests/resource_user_test.go | 10 +- fwprovider/tests/resource_vm_test.go | 108 ++++++------ fwprovider/tests/test_environment.go | 156 ++++++++++++++++++ fwprovider/tests/test_support.go | 122 -------------- proxmox/nodes/query_url_metadata.go | 2 +- 12 files changed, 305 insertions(+), 274 deletions(-) create mode 100644 fwprovider/tests/test_environment.go diff --git a/fwprovider/tests/datasource_version_test.go b/fwprovider/tests/datasource_version_test.go index fc1723b13..58d079920 100644 --- a/fwprovider/tests/datasource_version_test.go +++ b/fwprovider/tests/datasource_version_test.go @@ -7,7 +7,6 @@ package tests import ( - "context" "fmt" "strings" "testing" @@ -18,12 +17,12 @@ import ( func TestAccDatasourceVersion(t *testing.T) { t.Parallel() - accProviders := testAccMuxProviders(context.Background(), t) + te := initTestEnvironment(t) datasourceName := "data.proxmox_virtual_environment_version.test" resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: accProviders, + ProtoV6ProviderFactories: te.accProviders, Steps: []resource.TestStep{ // Read testing { diff --git a/fwprovider/tests/resource_container_test.go b/fwprovider/tests/resource_container_test.go index d9d501858..7876c8e3b 100644 --- a/fwprovider/tests/resource_container_test.go +++ b/fwprovider/tests/resource_container_test.go @@ -29,34 +29,39 @@ var ( ) func TestAccResourceContainer(t *testing.T) { - accProviders := testAccMuxProviders(context.Background(), t) + // download fails with 404 or "exit code 8" if run in parallel + // t.Parallel() + + te := initTestEnvironment(t) resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: accProviders, + ProtoV6ProviderFactories: te.accProviders, Steps: []resource.TestStep{ { - Config: testAccResourceContainerCreateConfig(false), - Check: testAccResourceContainerCreateCheck(t), + Config: testAccResourceContainerCreateConfig(te, false), + Check: testAccResourceContainerCreateCheck(te), }, { - Config: testAccResourceContainerCreateConfig(true) + testAccResourceContainerCreateCloneConfig(), - Check: testAccResourceContainerCreateCloneCheck(t), + Config: testAccResourceContainerCreateConfig(te, true) + testAccResourceContainerCreateCloneConfig(te), + Check: testAccResourceContainerCreateCloneCheck(te), }, }, }) } -func testAccResourceContainerCreateConfig(isTemplate bool) string { +func testAccResourceContainerCreateConfig(te *testEnvironment, isTemplate bool) string { + te.t.Helper() + return fmt.Sprintf(` resource "proxmox_virtual_environment_download_file" "ubuntu_container_template" { content_type = "vztmpl" datastore_id = "local" - node_name = "pve" + node_name = "%[1]s" url = "http://download.proxmox.com/images/system/ubuntu-23.04-standard_23.04-1_amd64.tar.zst" overwrite_unmanaged = true } resource "proxmox_virtual_environment_container" "test_container" { - node_name = "%s" + node_name = "%[1]s" vm_id = %d template = %t @@ -90,24 +95,26 @@ resource "proxmox_virtual_environment_container" "test_container" { type = "ubuntu" } } -`, accTestNodeName, accTestContainerID, isTemplate) +`, te.nodeName, accTestContainerID, isTemplate) } -func testAccResourceContainerCreateCheck(t *testing.T) resource.TestCheckFunc { - t.Helper() +func testAccResourceContainerCreateCheck(te *testEnvironment) resource.TestCheckFunc { + te.t.Helper() return resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(accTestContainerName, "description", "my\ndescription\nvalue\n"), func(*terraform.State) error { - err := getNodesClient().Container(accTestContainerID).WaitForContainerStatus(context.Background(), "running", 10, 1) - require.NoError(t, err, "container did not start") + err := te.nodeClient().Container(accTestContainerID).WaitForContainerStatus(context.Background(), "running", 10, 1) + require.NoError(te.t, err, "container did not start") return nil }, ) } -func testAccResourceContainerCreateCloneConfig() string { +func testAccResourceContainerCreateCloneConfig(te *testEnvironment) string { + te.t.Helper() + return fmt.Sprintf(` resource "proxmox_virtual_environment_container" "test_container_clone" { depends_on = [proxmox_virtual_environment_container.test_container] @@ -123,16 +130,16 @@ resource "proxmox_virtual_environment_container" "test_container_clone" { hostname = "test-clone" } } -`, accTestNodeName, accCloneContainerID) +`, te.nodeName, accCloneContainerID) } -func testAccResourceContainerCreateCloneCheck(t *testing.T) resource.TestCheckFunc { - t.Helper() +func testAccResourceContainerCreateCloneCheck(te *testEnvironment) resource.TestCheckFunc { + te.t.Helper() return resource.ComposeTestCheckFunc( func(*terraform.State) error { - err := getNodesClient().Container(accCloneContainerID).WaitForContainerStatus(context.Background(), "running", 10, 1) - require.NoError(t, err, "container did not start") + err := te.nodeClient().Container(accCloneContainerID).WaitForContainerStatus(context.Background(), "running", 10, 1) + require.NoError(te.t, err, "container did not start") return nil }, diff --git a/fwprovider/tests/resource_download_file_test.go b/fwprovider/tests/resource_download_file_test.go index 3ccb6e014..96ba9531d 100644 --- a/fwprovider/tests/resource_download_file_test.go +++ b/fwprovider/tests/resource_download_file_test.go @@ -24,6 +24,8 @@ const ( ) func TestAccResourceDownloadFile(t *testing.T) { + te := initTestEnvironment(t) + tests := []struct { name string steps []resource.TestStep @@ -37,11 +39,11 @@ func TestAccResourceDownloadFile(t *testing.T) { url = "%s" overwrite_unmanaged = true } - `, accTestNodeName, accTestStorageName, fakeFileISO), + `, te.nodeName, accTestStorageName, fakeFileISO), Check: resource.ComposeTestCheckFunc( testResourceAttributes("proxmox_virtual_environment_download_file.iso_image", map[string]string{ "id": "local:iso/fake_file.iso", - "node_name": accTestNodeName, + "node_name": te.nodeName, "datastore_id": accTestStorageName, "url": fakeFileISO, "file_name": "fake_file.iso", @@ -68,12 +70,12 @@ func TestAccResourceDownloadFile(t *testing.T) { checksum_algorithm = "sha256" overwrite_unmanaged = true } - `, accTestNodeName, accTestStorageName, fakeFileQCOW2), + `, te.nodeName, accTestStorageName, fakeFileQCOW2), Check: resource.ComposeTestCheckFunc( testResourceAttributes("proxmox_virtual_environment_download_file.qcow2_image", map[string]string{ "id": "local:iso/fake_qcow2_file.img", "content_type": "iso", - "node_name": accTestNodeName, + "node_name": te.nodeName, "datastore_id": accTestStorageName, "url": fakeFileQCOW2, "file_name": "fake_qcow2_file.img", @@ -99,12 +101,12 @@ func TestAccResourceDownloadFile(t *testing.T) { upload_timeout = 10000 overwrite_unmanaged = true } - `, accTestNodeName, accTestStorageName, fakeFileISO), + `, te.nodeName, accTestStorageName, fakeFileISO), Check: resource.ComposeTestCheckFunc( testResourceAttributes("proxmox_virtual_environment_download_file.iso_image", map[string]string{ "id": "local:iso/fake_iso_file.img", "content_type": "iso", - "node_name": accTestNodeName, + "node_name": te.nodeName, "datastore_id": accTestStorageName, "url": fakeFileISO, "file_name": "fake_iso_file.img", @@ -121,16 +123,16 @@ func TestAccResourceDownloadFile(t *testing.T) { }}}, {"override unmanaged file", []resource.TestStep{{ PreConfig: func() { - err := getNodeStorageClient().DownloadFileByURL(context.Background(), &storage.DownloadURLPostRequestBody{ + err := te.nodeStorageClient().DownloadFileByURL(context.Background(), &storage.DownloadURLPostRequestBody{ Content: types.StrPtr("iso"), FileName: types.StrPtr("fake_file.iso"), - Node: types.StrPtr(accTestNodeName), + Node: types.StrPtr(te.nodeName), Storage: types.StrPtr(accTestStorageName), URL: types.StrPtr(fakeFileISO), }, 600) require.NoError(t, err) t.Cleanup(func() { - err := getNodeStorageClient().DeleteDatastoreFile(context.Background(), "iso/fake_file.iso") + err := te.nodeStorageClient().DeleteDatastoreFile(context.Background(), "iso/fake_file.iso") require.NoError(t, err) }) }, @@ -142,12 +144,12 @@ func TestAccResourceDownloadFile(t *testing.T) { url = "%s" overwrite_unmanaged = true } - `, accTestNodeName, accTestStorageName, fakeFileISO), + `, te.nodeName, accTestStorageName, fakeFileISO), Check: resource.ComposeTestCheckFunc( testResourceAttributes("proxmox_virtual_environment_download_file.iso_image", map[string]string{ "id": "local:iso/fake_file.iso", "content_type": "iso", - "node_name": accTestNodeName, + "node_name": te.nodeName, "datastore_id": accTestStorageName, "url": fakeFileISO, "file_name": "fake_file.iso", @@ -163,12 +165,10 @@ func TestAccResourceDownloadFile(t *testing.T) { }}}, } - accProviders := testAccMuxProviders(context.Background(), t) - for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: accProviders, + ProtoV6ProviderFactories: te.accProviders, Steps: tt.steps, }) }) diff --git a/fwprovider/tests/resource_file_test.go b/fwprovider/tests/resource_file_test.go index 98919b685..184b717e5 100644 --- a/fwprovider/tests/resource_file_test.go +++ b/fwprovider/tests/resource_file_test.go @@ -43,7 +43,7 @@ func (c *nodeResolver) Resolve(_ context.Context, _ string) (ssh.ProxmoxNode, er func TestAccResourceFile(t *testing.T) { t.Parallel() - accProviders := testAccMuxProviders(context.Background(), 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" @@ -52,55 +52,55 @@ func TestAccResourceFile(t *testing.T) { fileISO := createFile(t, "file-*.iso", "pretend it is an ISO") resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: accProviders, + ProtoV6ProviderFactories: te.accProviders, PreCheck: func() { uploadSnippetFile(t, snippetFile2) }, Steps: []resource.TestStep{ { - Config: testAccResourceFileSnippetRawCreatedConfig(t, snippetRaw), + Config: testAccResourceFileSnippetRawCreatedConfig(te, snippetRaw), Check: testAccResourceFileSnippetRawCreatedCheck(snippetRaw), }, { - Config: testAccResourceFileCreatedConfig(t, snippetFile1.Name()), + Config: testAccResourceFileCreatedConfig(te, snippetFile1.Name()), Check: testAccResourceFileCreatedCheck("snippets", snippetFile1.Name()), }, { - Config: testAccResourceFileCreatedConfig(t, snippetURL), + Config: testAccResourceFileCreatedConfig(te, snippetURL), Check: testAccResourceFileCreatedCheck("snippets", snippetURL), }, { - Config: testAccResourceFileCreatedConfig(t, fileISO.Name()), + Config: testAccResourceFileCreatedConfig(te, fileISO.Name()), Check: testAccResourceFileCreatedCheck("iso", fileISO.Name()), }, { - Config: testAccResourceFileTwoSourcesCreatedConfig(t), + Config: testAccResourceFileTwoSourcesCreatedConfig(te), ExpectError: regexp.MustCompile("please specify .* - not both"), }, { - Config: testAccResourceFileCreatedConfig(t, "https://github.com", "content_type = \"iso\""), + Config: testAccResourceFileCreatedConfig(te, "https://github.com", "content_type = \"iso\""), ExpectError: regexp.MustCompile("failed to determine file name from the URL"), }, { - Config: testAccResourceFileMissingSourceConfig(t), + Config: testAccResourceFileMissingSourceConfig(te), ExpectError: regexp.MustCompile("missing argument"), }, // Do not allow to overwrite the file { - Config: testAccResourceFileCreatedConfig(t, snippetFile2.Name(), "overwrite = false"), + Config: testAccResourceFileCreatedConfig(te, snippetFile2.Name(), "overwrite = false"), ExpectError: regexp.MustCompile("already exists"), }, // Allow to overwrite the file by default { - Config: testAccResourceFileCreatedConfig(t, snippetFile2.Name()), + Config: testAccResourceFileCreatedConfig(te, snippetFile2.Name()), Check: testAccResourceFileCreatedCheck("snippets", snippetFile2.Name()), }, // Update testing { PreConfig: func() { - deleteSnippet(t, filepath.Base(snippetFile1.Name())) + deleteSnippet(te, filepath.Base(snippetFile1.Name())) }, - Config: testAccResourceFileSnippetUpdateConfig(t, snippetFile1.Name()), + Config: testAccResourceFileSnippetUpdateConfig(te, snippetFile1.Name()), Check: testAccResourceFileSnippetUpdatedCheck(snippetFile1.Name()), }, // ImportState testing @@ -174,15 +174,15 @@ func createFile(t *testing.T, namePattern string, content string) *os.File { return f } -func deleteSnippet(t *testing.T, fname string) { - t.Helper() +func deleteSnippet(te *testEnvironment, fname string) { + te.t.Helper() - err := getNodeStorageClient().DeleteDatastoreFile(context.Background(), fmt.Sprintf("snippets/%s", fname)) - require.NoError(t, err) + err := te.nodeStorageClient().DeleteDatastoreFile(context.Background(), fmt.Sprintf("snippets/%s", fname)) + require.NoError(te.t, err) } -func testAccResourceFileSnippetRawCreatedConfig(t *testing.T, fname string) string { - t.Helper() +func testAccResourceFileSnippetRawCreatedConfig(te *testEnvironment, fname string) string { + te.t.Helper() return fmt.Sprintf(`%s resource "proxmox_virtual_environment_file" "test_raw" { @@ -196,11 +196,11 @@ test snippet file_name = "%s" } } - `, getProviderConfig(t), accTestNodeName, fname) + `, te.providerConfig, te.nodeName, fname) } -func testAccResourceFileCreatedConfig(t *testing.T, fname string, extra ...string) string { - t.Helper() +func testAccResourceFileCreatedConfig(te *testEnvironment, fname string, extra ...string) string { + te.t.Helper() return fmt.Sprintf(`%s resource "proxmox_virtual_environment_file" "test" { @@ -211,11 +211,11 @@ resource "proxmox_virtual_environment_file" "test" { } %s } - `, getProviderConfig(t), accTestNodeName, strings.ReplaceAll(fname, `\`, `/`), strings.Join(extra, "\n")) + `, te.providerConfig, te.nodeName, strings.ReplaceAll(fname, `\`, `/`), strings.Join(extra, "\n")) } -func testAccResourceFileTwoSourcesCreatedConfig(t *testing.T) string { - t.Helper() +func testAccResourceFileTwoSourcesCreatedConfig(te *testEnvironment) string { + te.t.Helper() return fmt.Sprintf(`%s resource "proxmox_virtual_environment_file" "test" { @@ -231,18 +231,18 @@ test snippet path = "bar.yaml" } } - `, getProviderConfig(t), accTestNodeName) + `, te.providerConfig, te.nodeName) } -func testAccResourceFileMissingSourceConfig(t *testing.T) string { - t.Helper() +func testAccResourceFileMissingSourceConfig(te *testEnvironment) string { + te.t.Helper() return fmt.Sprintf(`%s resource "proxmox_virtual_environment_file" "test" { datastore_id = "local" node_name = "%s" } - `, getProviderConfig(t), accTestNodeName) + `, te.providerConfig, te.nodeName) } func testAccResourceFileSnippetRawCreatedCheck(fname string) resource.TestCheckFunc { @@ -263,8 +263,8 @@ func testAccResourceFileCreatedCheck(ctype string, fname string) resource.TestCh ) } -func testAccResourceFileSnippetUpdateConfig(t *testing.T, fname string) string { - t.Helper() +func testAccResourceFileSnippetUpdateConfig(te *testEnvironment, fname string) string { + te.t.Helper() return fmt.Sprintf(`%s resource "proxmox_virtual_environment_file" "test" { @@ -274,7 +274,7 @@ resource "proxmox_virtual_environment_file" "test" { path = "%s" } } - `, getProviderConfig(t), accTestNodeName, strings.ReplaceAll(fname, `\`, `/`)) + `, te.providerConfig, te.nodeName, strings.ReplaceAll(fname, `\`, `/`)) } func testAccResourceFileSnippetUpdatedCheck(fname string) resource.TestCheckFunc { diff --git a/fwprovider/tests/resource_linux_bridge_test.go b/fwprovider/tests/resource_linux_bridge_test.go index 452bf944e..40ede33f8 100644 --- a/fwprovider/tests/resource_linux_bridge_test.go +++ b/fwprovider/tests/resource_linux_bridge_test.go @@ -7,7 +7,6 @@ package tests import ( - "context" "fmt" "testing" @@ -17,7 +16,7 @@ import ( ) func TestAccResourceLinuxBridge(t *testing.T) { - accProviders := testAccMuxProviders(context.Background(), t) + te := initTestEnvironment(t) iface := fmt.Sprintf("vmbr%d", gofakeit.Number(10, 9999)) ipV4cidr1 := fmt.Sprintf("%s/24", gofakeit.IPv4Address()) @@ -25,7 +24,7 @@ func TestAccResourceLinuxBridge(t *testing.T) { ipV6cidr := "FE80:0000:0000:0000:0202:B3FF:FE1E:8329/64" resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: accProviders, + ProtoV6ProviderFactories: te.accProviders, Steps: []resource.TestStep{ // Create and Read testing { @@ -39,7 +38,7 @@ func TestAccResourceLinuxBridge(t *testing.T) { node_name = "%s" vlan_aware = true } - `, ipV4cidr1, iface, accTestNodeName), + `, ipV4cidr1, iface, te.nodeName), Check: resource.ComposeTestCheckFunc( testResourceAttributes("proxmox_virtual_environment_network_linux_bridge.test", map[string]string{ "address": ipV4cidr1, @@ -66,7 +65,7 @@ func TestAccResourceLinuxBridge(t *testing.T) { name = "%s" node_name = "%s" vlan_aware = false - }`, ipV4cidr2, ipV6cidr, iface, accTestNodeName), + }`, ipV4cidr2, ipV6cidr, iface, te.nodeName), Check: resource.ComposeTestCheckFunc( testResourceAttributes("proxmox_virtual_environment_network_linux_bridge.test", map[string]string{ "address": ipV4cidr2, diff --git a/fwprovider/tests/resource_linux_vlan_test.go b/fwprovider/tests/resource_linux_vlan_test.go index e2dd381b8..4854ba046 100644 --- a/fwprovider/tests/resource_linux_vlan_test.go +++ b/fwprovider/tests/resource_linux_vlan_test.go @@ -7,7 +7,6 @@ package tests import ( - "context" "fmt" "strconv" "testing" @@ -21,7 +20,7 @@ const ( ) func TestAccResourceLinuxVLAN(t *testing.T) { - accProviders := testAccMuxProviders(context.Background(), t) + te := initTestEnvironment(t) iface := "ens18" vlan1 := gofakeit.Number(10, 4094) @@ -30,11 +29,11 @@ func TestAccResourceLinuxVLAN(t *testing.T) { ipV4cidr := fmt.Sprintf("%s/24", gofakeit.IPv4Address()) resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: accProviders, + ProtoV6ProviderFactories: te.accProviders, Steps: []resource.TestStep{ // Create and Read testing { - Config: testAccResourceLinuxVLANCreatedConfig(iface, vlan1), + Config: testAccResourceLinuxVLANCreatedConfig(te, iface, vlan1), Check: testAccResourceLinuxVLANCreatedCheck(iface, vlan1), }, // ImportState testing @@ -45,7 +44,7 @@ func TestAccResourceLinuxVLAN(t *testing.T) { }, // Create and Read with a custom name { - Config: testAccResourceLinuxVLANCustomNameCreatedConfig(customName, iface, vlan2), + Config: testAccResourceLinuxVLANCustomNameCreatedConfig(te, customName, iface, vlan2), Check: testAccResourceLinuxVLANCustomNameCreatedCheck(customName, iface, vlan2), // PVE API is unreliable. Sometimes it returns a wrong VLAN ID for this second interface. SkipFunc: func() (bool, error) { @@ -54,14 +53,14 @@ func TestAccResourceLinuxVLAN(t *testing.T) { }, // Update testing { - Config: testAccResourceLinuxVLANUpdatedConfig(iface, vlan1, ipV4cidr), + Config: testAccResourceLinuxVLANUpdatedConfig(te, iface, vlan1, ipV4cidr), Check: testAccResourceLinuxVLANUpdatedCheck(iface, vlan1, ipV4cidr), }, }, }) } -func testAccResourceLinuxVLANCreatedConfig(iface string, vlan int) string { +func testAccResourceLinuxVLANCreatedConfig(te *testEnvironment, iface string, vlan int) string { return fmt.Sprintf(` resource "proxmox_virtual_environment_network_linux_vlan" "test" { comment = "created by terraform" @@ -69,7 +68,7 @@ func testAccResourceLinuxVLANCreatedConfig(iface string, vlan int) string { name = "%s.%d" node_name = "%s" } - `, iface, vlan, accTestNodeName) + `, iface, vlan, te.nodeName) } func testAccResourceLinuxVLANCreatedCheck(iface string, vlan int) resource.TestCheckFunc { @@ -82,7 +81,7 @@ func testAccResourceLinuxVLANCreatedCheck(iface string, vlan int) resource.TestC ) } -func testAccResourceLinuxVLANCustomNameCreatedConfig(name string, iface string, vlan int) string { +func testAccResourceLinuxVLANCustomNameCreatedConfig(te *testEnvironment, name string, iface string, vlan int) string { return fmt.Sprintf(` resource "proxmox_virtual_environment_network_linux_vlan" "%s" { comment = "created by terraform" @@ -92,7 +91,7 @@ func testAccResourceLinuxVLANCustomNameCreatedConfig(name string, iface string, node_name = "%s" vlan = %d } - `, name, iface, name, accTestNodeName, vlan) + `, name, iface, name, te.nodeName, vlan) } func testAccResourceLinuxVLANCustomNameCreatedCheck(name string, iface string, vlan int) resource.TestCheckFunc { @@ -107,7 +106,7 @@ func testAccResourceLinuxVLANCustomNameCreatedCheck(name string, iface string, v ) } -func testAccResourceLinuxVLANUpdatedConfig(iface string, vlan int, ipV4cidr string) string { +func testAccResourceLinuxVLANUpdatedConfig(te *testEnvironment, iface string, vlan int, ipV4cidr string) string { return fmt.Sprintf(` resource "proxmox_virtual_environment_network_linux_vlan" "test" { address = "%s" @@ -116,7 +115,7 @@ func testAccResourceLinuxVLANUpdatedConfig(iface string, vlan int, ipV4cidr stri name = "%s.%d" node_name = "%s" } - `, ipV4cidr, iface, vlan, accTestNodeName) + `, ipV4cidr, iface, vlan, te.nodeName) } func testAccResourceLinuxVLANUpdatedCheck(iface string, vlan int, ipV4cidr string) resource.TestCheckFunc { diff --git a/fwprovider/tests/resource_options_test.go b/fwprovider/tests/resource_options_test.go index 570135d6b..56a8e677a 100644 --- a/fwprovider/tests/resource_options_test.go +++ b/fwprovider/tests/resource_options_test.go @@ -7,7 +7,6 @@ package tests import ( - "context" "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -18,10 +17,10 @@ const accTestClusterOptionsName = "proxmox_virtual_environment_cluster_options.t func TestAccResourceClusterOptions(t *testing.T) { t.Parallel() - accProviders := testAccMuxProviders(context.Background(), t) + te := initTestEnvironment(t) resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: accProviders, + ProtoV6ProviderFactories: te.accProviders, Steps: []resource.TestStep{ // Create and Read testing { diff --git a/fwprovider/tests/resource_user_test.go b/fwprovider/tests/resource_user_test.go index 812f3e058..68d4fd53f 100644 --- a/fwprovider/tests/resource_user_test.go +++ b/fwprovider/tests/resource_user_test.go @@ -7,13 +7,16 @@ package tests import ( - "context" "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestAccResourceUser(t *testing.T) { + t.Parallel() + + te := initTestEnvironment(t) + tests := []struct { name string steps []resource.TestStep @@ -27,7 +30,6 @@ func TestAccResourceUser(t *testing.T) { expiration_date = "2034-01-01T22:00:00Z" first_name = "First" last_name = "Last" - //password = "password" user_id = "user1@pve" } `, @@ -60,12 +62,10 @@ func TestAccResourceUser(t *testing.T) { }}}, } - accProviders := testAccMuxProviders(context.Background(), t) - for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: accProviders, + ProtoV6ProviderFactories: te.accProviders, Steps: tt.steps, }) }) diff --git a/fwprovider/tests/resource_vm_test.go b/fwprovider/tests/resource_vm_test.go index 16c1e8b0a..e467b6eda 100644 --- a/fwprovider/tests/resource_vm_test.go +++ b/fwprovider/tests/resource_vm_test.go @@ -7,7 +7,7 @@ package tests import ( - "context" + "fmt" "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -16,16 +16,16 @@ import ( func TestAccResourceVM(t *testing.T) { t.Parallel() - providerConfig := getProviderConfig(t) + te := initTestEnvironment(t) tests := []struct { name string step []resource.TestStep }{ {"multiline description", []resource.TestStep{{ - Config: providerConfig + ` + Config: te.providerConfig + fmt.Sprintf(` resource "proxmox_virtual_environment_vm" "test_vm1" { - node_name = "pve" + node_name = "%s" started = false description = <<-EOT @@ -33,7 +33,7 @@ func TestAccResourceVM(t *testing.T) { description value EOT - }`, + }`, te.nodeName), Check: resource.ComposeTestCheckFunc( testResourceAttributes("proxmox_virtual_environment_vm.test_vm1", map[string]string{ "description": "my\ndescription\nvalue", @@ -41,13 +41,13 @@ func TestAccResourceVM(t *testing.T) { ), }}}, {"single line description", []resource.TestStep{{ - Config: providerConfig + ` + Config: te.providerConfig + fmt.Sprintf(` resource "proxmox_virtual_environment_vm" "test_vm2" { - node_name = "pve" + node_name = "%s" started = false description = "my description value" - }`, + }`, te.nodeName), Check: resource.ComposeTestCheckFunc( testResourceAttributes("proxmox_virtual_environment_vm.test_vm2", map[string]string{ "description": "my description value", @@ -55,13 +55,13 @@ func TestAccResourceVM(t *testing.T) { ), }}}, {"no description", []resource.TestStep{{ - Config: ` + Config: fmt.Sprintf(` resource "proxmox_virtual_environment_vm" "test_vm3" { - node_name = "pve" + node_name = "%s" started = false description = "" - }`, + }`, te.nodeName), Check: resource.ComposeTestCheckFunc( testResourceAttributes("proxmox_virtual_environment_vm.test_vm3", map[string]string{ "description": "", @@ -70,26 +70,26 @@ func TestAccResourceVM(t *testing.T) { }}}, { "protection", []resource.TestStep{{ - Config: ` + Config: fmt.Sprintf(` resource "proxmox_virtual_environment_vm" "test_vm4" { - node_name = "pve" + node_name = "%s" started = false protection = true - }`, + }`, te.nodeName), Check: resource.ComposeTestCheckFunc( testResourceAttributes("proxmox_virtual_environment_vm.test_vm4", map[string]string{ "protection": "true", }), ), }, { - Config: ` + Config: fmt.Sprintf(` resource "proxmox_virtual_environment_vm" "test_vm4" { - node_name = "pve" + node_name = "%s" started = false protection = false - }`, + }`, te.nodeName), Check: resource.ComposeTestCheckFunc( testResourceAttributes("proxmox_virtual_environment_vm.test_vm4", map[string]string{ "protection": "false", @@ -165,14 +165,12 @@ func TestAccResourceVM(t *testing.T) { }, } - accProviders := testAccMuxProviders(context.Background(), t) - for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: accProviders, + ProtoV6ProviderFactories: te.accProviders, Steps: tt.step, }) }) @@ -264,18 +262,18 @@ EOF } func TestAccResourceVMNetwork(t *testing.T) { - providerConfig := getProviderConfig(t) + te := initTestEnvironment(t) tests := []struct { name string step []resource.TestStep }{ {"network interfaces", []resource.TestStep{{ - Config: providerConfig + ` + Config: te.providerConfig + fmt.Sprintf(` resource "proxmox_virtual_environment_file" "cloud_config" { content_type = "snippets" datastore_id = "local" - node_name = "pve" + node_name = "%[1]s" source_raw { data = < Date: Sat, 23 Mar 2024 19:36:10 -0400 Subject: [PATCH 02/10] update ci Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- .github/workflows/testacc.yml | 16 +++++++++++++--- CONTRIBUTING.md | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/testacc.yml b/.github/workflows/testacc.yml index 478b75efb..272733ee5 100644 --- a/.github/workflows/testacc.yml +++ b/.github/workflows/testacc.yml @@ -11,9 +11,17 @@ on: jobs: acceptance: strategy: - max-parallel: 1 matrix: - os: [ ubuntu-latest, windows-latest, macos-latest ] + include: + - os: ubuntu-latest + node: pve1 + port: 13451 + - os: windows-latest + node: pve2 + port: 13452 + - os: macos-latest + node: pve3 + port: 13453 terraform: [ 1.6 ] runs-on: ${{ matrix.os }} environment: pve-acc @@ -53,5 +61,7 @@ jobs: PROXMOX_VE_SSH_AGENT: false PROXMOX_VE_SSH_USERNAME: "terraform" PROXMOX_VE_SSH_PRIVATE_KEY: "${{ secrets.PROXMOX_VE_SSH_PRIVATE_KEY }}" + PROXMOX_VE_ACC_NODE_NAME: ${{ matrix.node }} + PROXMOX_VE_ACC_NODE_SSH_ADDRESS: ${{ secrets.PROXMOX_VE_HOST }} + PROXMOX_VE_ACC_NODE_SSH_PORT: ${{ matrix.port }} run: make testacc - diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e098e1fda..3ae506898 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -61,6 +61,9 @@ PROXMOX_VE_API_TOKEN="root@pam!=" PROXMOX_VE_ENDPOINT="https://:8006/" PROXMOX_VE_SSH_AGENT="true" PROXMOX_VE_SSH_USERNAME="root" +# optionally, youcan override the default node name and ssh address +#PROXMOX_VE_ACC_NODE_NAME="pve1" +#PROXMOX_VE_ACC_NODE_SSH_ADDRESS="10.0.0.11" ``` Then use `make testacc` to run the acceptance tests. From e0a33b6bf0a745169f5db317664045fc7861d2d1 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Sat, 6 Apr 2024 17:33:16 -0400 Subject: [PATCH 03/10] fix tests after merge Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- fwprovider/tests/datasource_node_test.go | 9 +++-- fwprovider/tests/resource_vm_test.go | 44 ++++++++++-------------- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/fwprovider/tests/datasource_node_test.go b/fwprovider/tests/datasource_node_test.go index 75264928d..aa61b5a67 100644 --- a/fwprovider/tests/datasource_node_test.go +++ b/fwprovider/tests/datasource_node_test.go @@ -7,7 +7,6 @@ package tests import ( - "context" "fmt" "testing" @@ -17,12 +16,14 @@ import ( func TestAccDatasourceNode(t *testing.T) { t.Parallel() + te := initTestEnvironment(t) + tests := []struct { name string steps []resource.TestStep }{ {"read node attributes", []resource.TestStep{{ - Config: fmt.Sprintf(`data "proxmox_virtual_environment_node" "test" { node_name = "%s" }`, accTestNodeName), + Config: fmt.Sprintf(`data "proxmox_virtual_environment_node" "test" { node_name = "%s" }`, te.nodeName), Check: resource.ComposeTestCheckFunc( testResourceAttributesSet("data.proxmox_virtual_environment_node.test", []string{ "cpu_count", @@ -37,14 +38,12 @@ func TestAccDatasourceNode(t *testing.T) { }}}, } - accProviders := testAccMuxProviders(context.Background(), t) - for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: accProviders, + ProtoV6ProviderFactories: te.accProviders, Steps: tt.steps, }) }) diff --git a/fwprovider/tests/resource_vm_test.go b/fwprovider/tests/resource_vm_test.go index e467b6eda..5cc7bf8f4 100644 --- a/fwprovider/tests/resource_vm_test.go +++ b/fwprovider/tests/resource_vm_test.go @@ -99,30 +99,28 @@ func TestAccResourceVM(t *testing.T) { }, { "update cpu block", []resource.TestStep{{ - Config: ` - resource "proxmox_virtual_environment_vm" "test_vm5" { - node_name = "pve" + Config: fmt.Sprintf(`resource "proxmox_virtual_environment_vm" "test_vm5" { + node_name = "%s" started = false cpu { cores = 2 } - }`, + }`, te.nodeName), Check: resource.ComposeTestCheckFunc( testResourceAttributes("proxmox_virtual_environment_vm.test_vm5", map[string]string{ "cpu.0.sockets": "1", }), ), }, { - Config: ` - resource "proxmox_virtual_environment_vm" "test_vm5" { - node_name = "pve" + Config: fmt.Sprintf(`resource "proxmox_virtual_environment_vm" "test_vm5" { + node_name = "%s" started = false cpu { cores = 1 } - }`, + }`, te.nodeName), Check: resource.ComposeTestCheckFunc( testResourceAttributes("proxmox_virtual_environment_vm.test_vm5", map[string]string{ "cpu.0.sockets": "1", @@ -132,30 +130,28 @@ func TestAccResourceVM(t *testing.T) { }, { "update memory block", []resource.TestStep{{ - Config: ` - resource "proxmox_virtual_environment_vm" "test_vm6" { - node_name = "pve" + Config: fmt.Sprintf(`resource "proxmox_virtual_environment_vm" "test_vm6" { + node_name = "%s" started = false memory { dedicated = 2048 } - }`, + }`, te.nodeName), Check: resource.ComposeTestCheckFunc( testResourceAttributes("proxmox_virtual_environment_vm.test_vm6", map[string]string{ "memory.0.dedicated": "2048", }), ), }, { - Config: ` - resource "proxmox_virtual_environment_vm" "test_vm6" { - node_name = "pve" + Config: fmt.Sprintf(`resource "proxmox_virtual_environment_vm" "test_vm6" { + node_name = "%s" started = false memory { dedicated = 1024 } - }`, + }`, te.nodeName), Check: resource.ComposeTestCheckFunc( testResourceAttributes("proxmox_virtual_environment_vm.test_vm6", map[string]string{ "memory.0.dedicated": "1024", @@ -178,18 +174,18 @@ func TestAccResourceVM(t *testing.T) { } func TestAccResourceVMInitialization(t *testing.T) { - providerConfig := getProviderConfig(t) + te := initTestEnvironment(t) tests := []struct { name string step []resource.TestStep }{ {"initialization works with cloud-init config provided over SCSI interface", []resource.TestStep{{ - Config: providerConfig + ` + Config: te.providerConfig + fmt.Sprintf(` resource "proxmox_virtual_environment_file" "cloud_config" { content_type = "snippets" datastore_id = "local" - node_name = "pve" + node_name = "%[1]s" source_raw { data = < Date: Sat, 6 Apr 2024 18:24:05 -0400 Subject: [PATCH 04/10] test tests Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- .github/workflows/testacc.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/testacc.yml b/.github/workflows/testacc.yml index 272733ee5..956a96c18 100644 --- a/.github/workflows/testacc.yml +++ b/.github/workflows/testacc.yml @@ -7,6 +7,7 @@ on: description: 'Branch or tag to run tests against' required: true default: 'main' + pull_request: jobs: acceptance: From a7b13087f4b8b3f87c7f1b1477a924f34f132b30 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Sat, 6 Apr 2024 22:22:00 -0400 Subject: [PATCH 05/10] fix matrix Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- .github/workflows/testacc.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testacc.yml b/.github/workflows/testacc.yml index 956a96c18..302567c16 100644 --- a/.github/workflows/testacc.yml +++ b/.github/workflows/testacc.yml @@ -12,7 +12,10 @@ on: jobs: acceptance: strategy: + fail-fast: false matrix: + terraform: [ 1.6 ] + os: [ ubuntu-latest, windows-latest, macos-latest ] include: - os: ubuntu-latest node: pve1 @@ -23,7 +26,6 @@ jobs: - os: macos-latest node: pve3 port: 13453 - terraform: [ 1.6 ] runs-on: ${{ matrix.os }} environment: pve-acc steps: From d734ecb121909e68170c8dddf10bd6df73802188 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Sat, 6 Apr 2024 23:06:07 -0400 Subject: [PATCH 06/10] cleanup CI Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- .github/workflows/test.yml | 8 -------- .github/workflows/testacc.yml | 3 +++ fwprovider/tests/resource_vm_test.go | 4 ++-- fwprovider/tests/test_environment.go | 3 ++- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9aaf12e96..d38ffab54 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -99,11 +99,3 @@ jobs: filters: | go: - '**/*.go' - -# - name: Invoke acceptance tests workflow -# if: ${{ steps.filter.outputs.go == 'true' }} -# uses: benc-uk/workflow-dispatch@v1 -# with: -# workflow: testacc.yml -# ref: ${{ github.event.pull_request.head.ref }} -# inputs: '{"ref": "${{ github.head_ref }}" }' diff --git a/.github/workflows/testacc.yml b/.github/workflows/testacc.yml index 302567c16..417f5bef7 100644 --- a/.github/workflows/testacc.yml +++ b/.github/workflows/testacc.yml @@ -7,6 +7,9 @@ on: description: 'Branch or tag to run tests against' required: true default: 'main' + push: + branches: + - main pull_request: jobs: diff --git a/fwprovider/tests/resource_vm_test.go b/fwprovider/tests/resource_vm_test.go index 5cc7bf8f4..b0d4318bb 100644 --- a/fwprovider/tests/resource_vm_test.go +++ b/fwprovider/tests/resource_vm_test.go @@ -332,7 +332,7 @@ EOF ), }}}, {"network device disconnected", []resource.TestStep{{ - Config: fmt.Sprintf(` + Config: te.providerConfig + fmt.Sprintf(` resource "proxmox_virtual_environment_vm" "test_vm_network2" { node_name = "%s" started = false @@ -348,7 +348,7 @@ EOF }), ), }, { - Config: fmt.Sprintf(` + Config: te.providerConfig + fmt.Sprintf(` resource "proxmox_virtual_environment_vm" "test_vm_network2" { node_name = "%s" started = false diff --git a/fwprovider/tests/test_environment.go b/fwprovider/tests/test_environment.go index e4c0ef47b..0f0698e2b 100644 --- a/fwprovider/tests/test_environment.go +++ b/fwprovider/tests/test_environment.go @@ -68,7 +68,8 @@ provider "proxmox" { port = %s } } -}`, nodeName, nodeAddress, nodePort) +} +`, nodeName, nodeAddress, nodePort) return &testEnvironment{ t: t, From c5e8821650b7a5b20a715c3d9e33394f52c88247 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Sat, 6 Apr 2024 23:59:55 -0400 Subject: [PATCH 07/10] fix file tests Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- fwprovider/tests/resource_file_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fwprovider/tests/resource_file_test.go b/fwprovider/tests/resource_file_test.go index 184b717e5..5e9e409ec 100644 --- a/fwprovider/tests/resource_file_test.go +++ b/fwprovider/tests/resource_file_test.go @@ -184,7 +184,7 @@ func deleteSnippet(te *testEnvironment, fname string) { func testAccResourceFileSnippetRawCreatedConfig(te *testEnvironment, fname string) string { te.t.Helper() - return fmt.Sprintf(`%s + return te.providerConfig + fmt.Sprintf(`%s resource "proxmox_virtual_environment_file" "test_raw" { content_type = "snippets" datastore_id = "local" @@ -202,7 +202,7 @@ test snippet func testAccResourceFileCreatedConfig(te *testEnvironment, fname string, extra ...string) string { te.t.Helper() - return fmt.Sprintf(`%s + return te.providerConfig + fmt.Sprintf(`%s resource "proxmox_virtual_environment_file" "test" { datastore_id = "local" node_name = "%s" @@ -217,7 +217,7 @@ resource "proxmox_virtual_environment_file" "test" { func testAccResourceFileTwoSourcesCreatedConfig(te *testEnvironment) string { te.t.Helper() - return fmt.Sprintf(`%s + return te.providerConfig + fmt.Sprintf(`%s resource "proxmox_virtual_environment_file" "test" { datastore_id = "local" node_name = "%s" @@ -237,7 +237,7 @@ test snippet func testAccResourceFileMissingSourceConfig(te *testEnvironment) string { te.t.Helper() - return fmt.Sprintf(`%s + return te.providerConfig + fmt.Sprintf(`%s resource "proxmox_virtual_environment_file" "test" { datastore_id = "local" node_name = "%s" @@ -266,7 +266,7 @@ func testAccResourceFileCreatedCheck(ctype string, fname string) resource.TestCh func testAccResourceFileSnippetUpdateConfig(te *testEnvironment, fname string) string { te.t.Helper() - return fmt.Sprintf(`%s + return te.providerConfig + fmt.Sprintf(`%s resource "proxmox_virtual_environment_file" "test" { datastore_id = "local" node_name = "%s" From fa1776b206a8e10fd4b95ce493f461c8716ca43b Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Sun, 7 Apr 2024 00:12:50 -0400 Subject: [PATCH 08/10] more acc test fixes Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- fwprovider/tests/resource_file_test.go | 13 +++++++------ utils/env.go | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/fwprovider/tests/resource_file_test.go b/fwprovider/tests/resource_file_test.go index 5e9e409ec..646b05c08 100644 --- a/fwprovider/tests/resource_file_test.go +++ b/fwprovider/tests/resource_file_test.go @@ -129,13 +129,14 @@ func uploadSnippetFile(t *testing.T, file *os.File) { sshUsername := utils.GetAnyStringEnv("PROXMOX_VE_SSH_USERNAME") sshAgentSocket := utils.GetAnyStringEnv("SSH_AUTH_SOCK", "PROXMOX_VE_SSH_AUTH_SOCK") sshPrivateKey := utils.GetAnyStringEnv("PROXMOX_VE_SSH_PRIVATE_KEY") + sshPort := utils.GetAnyIntEnv("PROXMOX_VE_ACC_NODE_SSH_PORT") sshClient, err := ssh.NewClient( sshUsername, "", sshAgent, sshAgentSocket, sshPrivateKey, "", "", "", &nodeResolver{ node: ssh.ProxmoxNode{ Address: u.Hostname(), - Port: 22, + Port: int32(sshPort), }, }, ) @@ -184,7 +185,7 @@ func deleteSnippet(te *testEnvironment, fname string) { func testAccResourceFileSnippetRawCreatedConfig(te *testEnvironment, fname string) string { te.t.Helper() - return te.providerConfig + fmt.Sprintf(`%s + return fmt.Sprintf(`%s resource "proxmox_virtual_environment_file" "test_raw" { content_type = "snippets" datastore_id = "local" @@ -202,7 +203,7 @@ test snippet func testAccResourceFileCreatedConfig(te *testEnvironment, fname string, extra ...string) string { te.t.Helper() - return te.providerConfig + fmt.Sprintf(`%s + return fmt.Sprintf(`%s resource "proxmox_virtual_environment_file" "test" { datastore_id = "local" node_name = "%s" @@ -217,7 +218,7 @@ resource "proxmox_virtual_environment_file" "test" { func testAccResourceFileTwoSourcesCreatedConfig(te *testEnvironment) string { te.t.Helper() - return te.providerConfig + fmt.Sprintf(`%s + return fmt.Sprintf(`%s resource "proxmox_virtual_environment_file" "test" { datastore_id = "local" node_name = "%s" @@ -237,7 +238,7 @@ test snippet func testAccResourceFileMissingSourceConfig(te *testEnvironment) string { te.t.Helper() - return te.providerConfig + fmt.Sprintf(`%s + return fmt.Sprintf(`%s resource "proxmox_virtual_environment_file" "test" { datastore_id = "local" node_name = "%s" @@ -266,7 +267,7 @@ func testAccResourceFileCreatedCheck(ctype string, fname string) resource.TestCh func testAccResourceFileSnippetUpdateConfig(te *testEnvironment, fname string) string { te.t.Helper() - return te.providerConfig + fmt.Sprintf(`%s + return fmt.Sprintf(`%s resource "proxmox_virtual_environment_file" "test" { datastore_id = "local" node_name = "%s" diff --git a/utils/env.go b/utils/env.go index 43c36622c..84db53535 100644 --- a/utils/env.go +++ b/utils/env.go @@ -6,7 +6,10 @@ package utils -import "os" +import ( + "os" + "strconv" +) // GetAnyStringEnv returns the first non-empty string value from the environment variables. func GetAnyStringEnv(ks ...string) string { @@ -32,3 +35,16 @@ func GetAnyBoolEnv(ks ...string) bool { return val == "true" || val == "1" } + +// GetAnyIntEnv returns the first non-empty integer value from the environment variables. +func GetAnyIntEnv(ks ...string) int { + for _, k := range ks { + if v := os.Getenv(k); v != "" { + if i, err := strconv.Atoi(v); err == nil { + return i + } + } + } + + return 0 +} From e1fae7601594741ac5d980545bc1e3bc4c6cf860 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Sun, 7 Apr 2024 00:35:30 -0400 Subject: [PATCH 09/10] cleanup Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- .github/workflows/testacc.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/testacc.yml b/.github/workflows/testacc.yml index 417f5bef7..9d32cb977 100644 --- a/.github/workflows/testacc.yml +++ b/.github/workflows/testacc.yml @@ -10,7 +10,6 @@ on: push: branches: - main - pull_request: jobs: acceptance: From c908e570ae02c1f3a0a902f8dc3dd6bcd2b3607b Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Sun, 7 Apr 2024 00:38:22 -0400 Subject: [PATCH 10/10] fix linter Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- fwprovider/tests/resource_container_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fwprovider/tests/resource_container_test.go b/fwprovider/tests/resource_container_test.go index 7876c8e3b..551c7de8b 100644 --- a/fwprovider/tests/resource_container_test.go +++ b/fwprovider/tests/resource_container_test.go @@ -28,7 +28,7 @@ var ( accCloneContainerID = 200000 + rand.Intn(99999) //nolint:gosec ) -func TestAccResourceContainer(t *testing.T) { +func TestAccResourceContainer(t *testing.T) { //nolint:wsl // download fails with 404 or "exit code 8" if run in parallel // t.Parallel()