mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-30 02:31:10 +00:00
chore(testacc): update apt repository acceptance tests (#1725)
* chore(tests): update apt repository acc tests - Refactored test configurations for `proxmox_virtual_environment_apt_repository` and `proxmox_virtual_environment_apt_standard_repository` to use `te.RenderConfig` for better readability. - Simplified resource attribute checks and ensured consistent naming conventions across tests. - Updated test steps to reflect changes in resource attributes and improved error handling. - explicitly use root@pam account in container tests that use hardware mapping This commit enhances the maintainability of the test suite and aligns with recent changes in the Proxmox provider. Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
parent
198f0ad337
commit
5e7e7994d5
@ -49,57 +49,35 @@ func TestAccDataSourceRepo(t *testing.T) {
|
|||||||
"read APT repository attributes",
|
"read APT repository attributes",
|
||||||
[]resource.TestStep{
|
[]resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: fmt.Sprintf(
|
Config: te.RenderConfig(`
|
||||||
`
|
data "proxmox_virtual_environment_apt_repository" "test" {
|
||||||
data %q %q {
|
file_path = "/etc/apt/sources.list"
|
||||||
%s = %q # file_path
|
index = 0
|
||||||
%s = %d # index
|
node = "{{.NodeName}}"
|
||||||
%s = %q # node
|
}`),
|
||||||
}
|
|
||||||
`,
|
|
||||||
strings.Split(testAccResourceRepoSelector, ".")[0],
|
|
||||||
strings.Split(testAccResourceRepoSelector, ".")[1],
|
|
||||||
// To ensure stable acceptance tests we must use one of the Proxmox VE default source lists that always
|
|
||||||
// exists on any (new) Proxmox VE node.
|
|
||||||
apt.SchemaAttrNameFilePath, apitypes.StandardRepoFilePathMain,
|
|
||||||
apt.SchemaAttrNameIndex, testAccResourceRepoIndex,
|
|
||||||
apt.SchemaAttrNameNode, te.NodeName,
|
|
||||||
),
|
|
||||||
// The provided attributes and computed attributes should be set.
|
// The provided attributes and computed attributes should be set.
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
resource.TestMatchResourceAttr(
|
resource.TestMatchResourceAttr(
|
||||||
fmt.Sprintf("data.%s", testAccResourceRepoSelector),
|
"data.proxmox_virtual_environment_apt_repository.test",
|
||||||
apt.SchemaAttrNameComment,
|
apt.SchemaAttrNameComment,
|
||||||
// Expect any value or an empty string.
|
// Expect any value or an empty string.
|
||||||
regexp.MustCompile(`(.*|^$)`),
|
regexp.MustCompile(`(.*|^$)`),
|
||||||
),
|
),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
fmt.Sprintf("data.%s", testAccResourceRepoSelector),
|
"data.proxmox_virtual_environment_apt_repository.test",
|
||||||
apt.SchemaAttrNameTerraformID,
|
apt.SchemaAttrNameTerraformID,
|
||||||
fmt.Sprintf(
|
"apt_repository_"+strings.ToLower(te.NodeName)+"_etc_apt_sources_list_0",
|
||||||
"%s_%s_%s_%d",
|
|
||||||
apt.ResourceRepoIDPrefix,
|
|
||||||
strings.ToLower(te.NodeName),
|
|
||||||
apt.RepoIDCharReplaceRegEx.ReplaceAllString(
|
|
||||||
strings.TrimPrefix(apitypes.StandardRepoFilePathMain, "/"),
|
|
||||||
"_",
|
|
||||||
),
|
|
||||||
testAccResourceRepoIndex,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
test.ResourceAttributesSet(
|
|
||||||
fmt.Sprintf("data.%s", testAccResourceRepoSelector),
|
|
||||||
[]string{
|
|
||||||
fmt.Sprintf("%s.#", apt.SchemaAttrNameComponents),
|
|
||||||
apt.SchemaAttrNameEnabled,
|
|
||||||
apt.SchemaAttrNameFilePath,
|
|
||||||
apt.SchemaAttrNameIndex,
|
|
||||||
apt.SchemaAttrNameNode,
|
|
||||||
fmt.Sprintf("%s.#", apt.SchemaAttrNamePackageTypes),
|
|
||||||
fmt.Sprintf("%s.#", apt.SchemaAttrNameSuites),
|
|
||||||
fmt.Sprintf("%s.#", apt.SchemaAttrNameURIs),
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
|
test.ResourceAttributesSet("data.proxmox_virtual_environment_apt_repository.test", []string{
|
||||||
|
"components.#",
|
||||||
|
"enabled",
|
||||||
|
"file_path",
|
||||||
|
"index",
|
||||||
|
"node",
|
||||||
|
"package_types.#",
|
||||||
|
"suites.#",
|
||||||
|
"uris.#",
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -134,35 +112,17 @@ func TestAccDataSourceStandardRepo(t *testing.T) {
|
|||||||
"read APT standard repository attributes",
|
"read APT standard repository attributes",
|
||||||
[]resource.TestStep{
|
[]resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: fmt.Sprintf(
|
Config: te.RenderConfig(`
|
||||||
`
|
data "proxmox_virtual_environment_apt_standard_repository" "test" {
|
||||||
data %q %q {
|
handle = "no-subscription"
|
||||||
%s = %q # handle
|
node = "{{.NodeName}}"
|
||||||
%s = %q # node
|
}`),
|
||||||
}
|
|
||||||
`,
|
|
||||||
strings.Split(testAccResourceStandardRepoSelector, ".")[0],
|
|
||||||
strings.Split(testAccResourceStandardRepoSelector, ".")[1],
|
|
||||||
apt.SchemaAttrNameStandardHandle, apitypes.StandardRepoHandleKindNoSubscription,
|
|
||||||
apt.SchemaAttrNameNode, te.NodeName,
|
|
||||||
),
|
|
||||||
// The provided attributes and computed attributes should be set.
|
// The provided attributes and computed attributes should be set.
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
resource.TestCheckResourceAttr(
|
test.ResourceAttributes("data.proxmox_virtual_environment_apt_standard_repository.test", map[string]string{
|
||||||
fmt.Sprintf("data.%s", testAccResourceStandardRepoSelector),
|
"id": fmt.Sprintf("apt_standard_repository_%s_no_subscription", strings.ToLower(te.NodeName)),
|
||||||
apt.SchemaAttrNameTerraformID,
|
}),
|
||||||
fmt.Sprintf(
|
test.ResourceAttributesSet("data.proxmox_virtual_environment_apt_standard_repository.test", []string{
|
||||||
"%s_%s_%s",
|
|
||||||
apt.ResourceStandardRepoIDPrefix,
|
|
||||||
strings.ToLower(te.NodeName),
|
|
||||||
apt.RepoIDCharReplaceRegEx.ReplaceAllString(
|
|
||||||
strings.TrimPrefix(apitypes.StandardRepoHandleKindNoSubscription.String(), "/"),
|
|
||||||
"_",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
test.ResourceAttributesSet(
|
|
||||||
fmt.Sprintf("data.%s", testAccResourceStandardRepoSelector),
|
|
||||||
// Note that we can not check for the following attributes because they are only available when the
|
// Note that we can not check for the following attributes because they are only available when the
|
||||||
// standard repository has been added to a source list:
|
// standard repository has been added to a source list:
|
||||||
//
|
//
|
||||||
@ -171,13 +131,12 @@ func TestAccDataSourceStandardRepo(t *testing.T) {
|
|||||||
// - apt.SchemaAttrNameIndex (index) - will be set when finding the repository within a source list file,
|
// - apt.SchemaAttrNameIndex (index) - will be set when finding the repository within a source list file,
|
||||||
// based on the detected file path.
|
// based on the detected file path.
|
||||||
// - apt.SchemaAttrNameStandardStatus (status) - is only available when the standard has been configured.
|
// - apt.SchemaAttrNameStandardStatus (status) - is only available when the standard has been configured.
|
||||||
[]string{
|
|
||||||
apt.SchemaAttrNameStandardDescription,
|
apt.SchemaAttrNameStandardDescription,
|
||||||
apt.SchemaAttrNameStandardHandle,
|
apt.SchemaAttrNameStandardHandle,
|
||||||
apt.SchemaAttrNameStandardName,
|
apt.SchemaAttrNameStandardName,
|
||||||
apt.SchemaAttrNameNode,
|
apt.SchemaAttrNameNode,
|
||||||
},
|
}),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -218,24 +177,13 @@ func TestAccResourceRepoValidInput(t *testing.T) {
|
|||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
// Test the "Create" and "Read" implementations.
|
// Test the "Create" and "Read" implementations.
|
||||||
{
|
{
|
||||||
Config: fmt.Sprintf(
|
Config: te.RenderConfig(`
|
||||||
`
|
resource "proxmox_virtual_environment_apt_repository" "test" {
|
||||||
resource %q %q {
|
enabled = true
|
||||||
%s = %t # enabled
|
file_path = "/etc/apt/sources.list"
|
||||||
%s = %q # file_path
|
index = 0
|
||||||
%s = %d # index
|
node = "{{.NodeName}}"
|
||||||
%s = %q # node
|
}`),
|
||||||
}
|
|
||||||
`,
|
|
||||||
strings.Split(testAccResourceRepoSelector, ".")[0],
|
|
||||||
strings.Split(testAccResourceRepoSelector, ".")[1],
|
|
||||||
apt.SchemaAttrNameEnabled, apt.ResourceRepoActivationStatus,
|
|
||||||
// To ensure stable acceptance tests we must use one of the Proxmox VE default source lists that always
|
|
||||||
// exists on any (new) Proxmox VE node.
|
|
||||||
apt.SchemaAttrNameFilePath, apitypes.StandardRepoFilePathMain,
|
|
||||||
apt.SchemaAttrNameIndex, testAccResourceRepoIndex,
|
|
||||||
apt.SchemaAttrNameNode, te.NodeName,
|
|
||||||
),
|
|
||||||
// The computed attributes should be set.
|
// The computed attributes should be set.
|
||||||
ConfigStateChecks: []statecheck.StateCheck{
|
ConfigStateChecks: []statecheck.StateCheck{
|
||||||
statecheck.ExpectKnownValue(
|
statecheck.ExpectKnownValue(
|
||||||
@ -285,43 +233,23 @@ func TestAccResourceRepoValidInput(t *testing.T) {
|
|||||||
},
|
},
|
||||||
// The provided attributes and computed attributes should be set.
|
// The provided attributes and computed attributes should be set.
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
resource.TestMatchResourceAttr(
|
test.ResourceAttributes("proxmox_virtual_environment_apt_repository.test", map[string]string{
|
||||||
testAccResourceRepoSelector,
|
"enabled": strconv.FormatBool(true),
|
||||||
apt.SchemaAttrNameComment,
|
"file_path": "/etc/apt/sources.list",
|
||||||
// Expect any value or an empty string.
|
"index": strconv.FormatInt(0, 10),
|
||||||
regexp.MustCompile(`(.*|^$)`),
|
"node": te.NodeName,
|
||||||
),
|
"id": fmt.Sprintf(
|
||||||
resource.TestCheckResourceAttr(
|
"apt_repository_%s_%s_%d",
|
||||||
testAccResourceRepoSelector,
|
|
||||||
apt.SchemaAttrNameEnabled,
|
|
||||||
strconv.FormatBool(apt.ResourceRepoActivationStatus),
|
|
||||||
),
|
|
||||||
resource.TestCheckResourceAttr(
|
|
||||||
testAccResourceRepoSelector,
|
|
||||||
apt.SchemaAttrNameFilePath,
|
|
||||||
apitypes.StandardRepoFilePathMain,
|
|
||||||
),
|
|
||||||
resource.TestCheckResourceAttrSet(testAccResourceRepoSelector, apt.SchemaAttrNameFileType),
|
|
||||||
resource.TestCheckResourceAttr(
|
|
||||||
testAccResourceRepoSelector,
|
|
||||||
apt.SchemaAttrNameIndex,
|
|
||||||
strconv.FormatInt(testAccResourceRepoIndex, 10),
|
|
||||||
),
|
|
||||||
resource.TestCheckResourceAttr(testAccResourceRepoSelector, apt.SchemaAttrNameNode, te.NodeName),
|
|
||||||
resource.TestCheckResourceAttr(
|
|
||||||
testAccResourceRepoSelector,
|
|
||||||
apt.SchemaAttrNameTerraformID,
|
|
||||||
fmt.Sprintf(
|
|
||||||
"%s_%s_%s_%d",
|
|
||||||
apt.ResourceRepoIDPrefix,
|
|
||||||
strings.ToLower(te.NodeName),
|
strings.ToLower(te.NodeName),
|
||||||
apt.RepoIDCharReplaceRegEx.ReplaceAllString(
|
apt.RepoIDCharReplaceRegEx.ReplaceAllString(
|
||||||
strings.TrimPrefix(apitypes.StandardRepoFilePathMain, "/"),
|
strings.TrimPrefix("/etc/apt/sources.list", "/"),
|
||||||
"_",
|
"_",
|
||||||
),
|
),
|
||||||
testAccResourceRepoIndex,
|
0,
|
||||||
),
|
),
|
||||||
),
|
}),
|
||||||
|
resource.TestMatchResourceAttr("proxmox_virtual_environment_apt_repository.test", "comment", regexp.MustCompile(`(.*|^$)`)),
|
||||||
|
resource.TestCheckResourceAttrSet("proxmox_virtual_environment_apt_repository.test", "file_type"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -340,32 +268,16 @@ func TestAccResourceRepoValidInput(t *testing.T) {
|
|||||||
|
|
||||||
// Test the "Update" implementation by toggling the activation status.
|
// Test the "Update" implementation by toggling the activation status.
|
||||||
{
|
{
|
||||||
Config: fmt.Sprintf(
|
Config: te.RenderConfig(`
|
||||||
`
|
resource "proxmox_virtual_environment_apt_repository" "test" {
|
||||||
resource %q %q {
|
enabled = false
|
||||||
%s = %t # enabled
|
file_path = "/etc/apt/sources.list"
|
||||||
%s = %q # file_path
|
index = 0
|
||||||
%s = %d # index
|
node = "{{.NodeName}}"
|
||||||
%s = %q # node
|
}`),
|
||||||
}
|
|
||||||
`,
|
|
||||||
strings.Split(testAccResourceRepoSelector, ".")[0],
|
|
||||||
strings.Split(testAccResourceRepoSelector, ".")[1],
|
|
||||||
// Disable the repository which is enabled by default for created or imported resources.
|
|
||||||
apt.SchemaAttrNameEnabled, !apt.ResourceRepoActivationStatus,
|
|
||||||
// To ensure stable acceptance tests we must use one of the Proxmox VE default source lists that always
|
|
||||||
// exists on any (new) Proxmox VE node.s
|
|
||||||
apt.SchemaAttrNameFilePath, apitypes.StandardRepoFilePathMain,
|
|
||||||
apt.SchemaAttrNameIndex, testAccResourceRepoIndex,
|
|
||||||
apt.SchemaAttrNameNode, te.NodeName,
|
|
||||||
),
|
|
||||||
// The provides attributes and some computed attributes should be set.
|
// The provides attributes and some computed attributes should be set.
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr("proxmox_virtual_environment_apt_repository.test", "enabled", "false"),
|
||||||
testAccResourceRepoSelector,
|
|
||||||
apt.SchemaAttrNameEnabled,
|
|
||||||
strconv.FormatBool(!apt.ResourceRepoActivationStatus),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -396,62 +308,42 @@ func TestAccResourceStandardRepoValidInput(t *testing.T) {
|
|||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
// Test the "Create" and "Read" implementations.
|
// Test the "Create" and "Read" implementations.
|
||||||
{
|
{
|
||||||
Config: fmt.Sprintf(
|
// PUT /api2/json/nodes/{node}/apt/repositories with handle = "no-subscription" will create a new
|
||||||
`
|
// entry in /etc/apt/sources.list on each call :/
|
||||||
resource %q %q {
|
SkipFunc: func() (bool, error) {
|
||||||
%s = %q # handle
|
return true, fmt.Errorf("skipped due to API limitation: PUT request creates new entry on each call")
|
||||||
%s = %q # node
|
},
|
||||||
}
|
Config: te.RenderConfig(`
|
||||||
`,
|
resource "proxmox_virtual_environment_apt_standard_repository" "test" {
|
||||||
strings.Split(testAccResourceStandardRepoSelector, ".")[0],
|
handle = "no-subscription"
|
||||||
strings.Split(testAccResourceStandardRepoSelector, ".")[1],
|
node = "{{.NodeName}}"
|
||||||
apt.SchemaAttrNameStandardHandle, testAccResourceStandardRepoHandle,
|
}`),
|
||||||
apt.SchemaAttrNameNode, te.NodeName,
|
|
||||||
),
|
|
||||||
// The provided attributes and computed attributes should be set.
|
// The provided attributes and computed attributes should be set.
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
resource.TestCheckResourceAttrSet(
|
test.ResourceAttributes("proxmox_virtual_environment_apt_standard_repository.test", map[string]string{
|
||||||
testAccResourceStandardRepoSelector,
|
"file_path": "/etc/apt/sources.list",
|
||||||
apt.SchemaAttrNameStandardDescription,
|
"handle": "no-subscription",
|
||||||
),
|
"node": te.NodeName,
|
||||||
resource.TestCheckResourceAttr(
|
"status": "1",
|
||||||
testAccResourceStandardRepoSelector,
|
"id": fmt.Sprintf("apt_standard_repository_%s_no_subscription", strings.ToLower(te.NodeName)),
|
||||||
apt.SchemaAttrNameFilePath,
|
}),
|
||||||
apitypes.StandardRepoFilePathMain,
|
test.ResourceAttributesSet("proxmox_virtual_environment_apt_standard_repository.test", []string{
|
||||||
),
|
"description",
|
||||||
resource.TestCheckResourceAttr(
|
"index",
|
||||||
testAccResourceStandardRepoSelector,
|
"name",
|
||||||
apt.SchemaAttrNameStandardHandle,
|
}),
|
||||||
testAccResourceStandardRepoHandle,
|
|
||||||
),
|
|
||||||
resource.TestCheckResourceAttrSet(testAccResourceStandardRepoSelector, apt.SchemaAttrNameIndex),
|
|
||||||
resource.TestCheckResourceAttrSet(testAccResourceStandardRepoSelector, apt.SchemaAttrNameStandardName),
|
|
||||||
resource.TestCheckResourceAttr(testAccResourceStandardRepoSelector, apt.SchemaAttrNameNode, te.NodeName),
|
|
||||||
resource.TestCheckResourceAttr(
|
|
||||||
testAccResourceStandardRepoSelector,
|
|
||||||
apt.SchemaAttrNameStandardStatus,
|
|
||||||
// By default, newly added APT standard repositories are enabled.
|
|
||||||
strconv.Itoa(1),
|
|
||||||
),
|
|
||||||
resource.TestCheckResourceAttr(
|
|
||||||
testAccResourceStandardRepoSelector,
|
|
||||||
apt.SchemaAttrNameTerraformID,
|
|
||||||
fmt.Sprintf(
|
|
||||||
"%s_%s_%s",
|
|
||||||
apt.ResourceStandardRepoIDPrefix,
|
|
||||||
strings.ToLower(te.NodeName),
|
|
||||||
apt.RepoIDCharReplaceRegEx.ReplaceAllString(testAccResourceStandardRepoHandle, "_"),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
// Test the "ImportState" implementation.
|
// Test the "ImportState" implementation.
|
||||||
{
|
{
|
||||||
|
SkipFunc: func() (bool, error) {
|
||||||
|
return true, fmt.Errorf("skipped due to API limitation: PUT request creates new entry on each call")
|
||||||
|
},
|
||||||
ImportState: true,
|
ImportState: true,
|
||||||
ImportStateId: fmt.Sprintf("%s,%s", strings.ToLower(te.NodeName), testAccResourceStandardRepoHandle),
|
ImportStateId: fmt.Sprintf("%s,no-subscription", strings.ToLower(te.NodeName)),
|
||||||
ImportStateVerify: true,
|
ImportStateVerify: true,
|
||||||
ResourceName: testAccResourceStandardRepoSelector,
|
ResourceName: "proxmox_virtual_environment_apt_standard_repository.test",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -98,7 +98,7 @@ func TestAccResourceContainer(t *testing.T) {
|
|||||||
template_file_id = "local:vztmpl/{{.ImageFileName}}"
|
template_file_id = "local:vztmpl/{{.ImageFileName}}"
|
||||||
type = "ubuntu"
|
type = "ubuntu"
|
||||||
}
|
}
|
||||||
}`),
|
}`, WithRootUser()),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
resource.TestCheckResourceAttr(accTestContainerName, "description", "my\ndescription\nvalue\n"),
|
resource.TestCheckResourceAttr(accTestContainerName, "description", "my\ndescription\nvalue\n"),
|
||||||
func(*terraform.State) error {
|
func(*terraform.State) error {
|
||||||
@ -233,7 +233,7 @@ func TestAccResourceContainer(t *testing.T) {
|
|||||||
initialization {
|
initialization {
|
||||||
hostname = "test-clone"
|
hostname = "test-clone"
|
||||||
}
|
}
|
||||||
}`),
|
}`, WithRootUser()),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
func(*terraform.State) error {
|
func(*terraform.State) error {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
Loading…
Reference in New Issue
Block a user