Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve acceptance tests on CI #1173

Merged
merged 12 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}" }'
21 changes: 18 additions & 3 deletions .github/workflows/testacc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,27 @@ on:
description: 'Branch or tag to run tests against'
required: true
default: 'main'
push:
branches:
- main

jobs:
acceptance:
strategy:
max-parallel: 1
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
terraform: [ 1.6 ]
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
runs-on: ${{ matrix.os }}
environment: pve-acc
steps:
Expand Down Expand Up @@ -53,5 +66,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

3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ PROXMOX_VE_API_TOKEN="root@pam!<token name>=<token value>"
PROXMOX_VE_ENDPOINT="https://<pve instance>: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.
Expand Down
9 changes: 4 additions & 5 deletions fwprovider/tests/datasource_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package tests

import (
"context"
"fmt"
"testing"

Expand All @@ -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",
Expand All @@ -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,
})
})
Expand Down
5 changes: 2 additions & 3 deletions fwprovider/tests/datasource_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package tests

import (
"context"
"fmt"
"strings"
"testing"
Expand All @@ -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
{
Expand Down
49 changes: 28 additions & 21 deletions fwprovider/tests/resource_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,40 @@ var (
accCloneContainerID = 200000 + rand.Intn(99999) //nolint:gosec
)

func TestAccResourceContainer(t *testing.T) {
accProviders := testAccMuxProviders(context.Background(), t)
func TestAccResourceContainer(t *testing.T) { //nolint:wsl
// 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

Expand Down Expand Up @@ -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]
Expand All @@ -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
},
Expand Down
28 changes: 14 additions & 14 deletions fwprovider/tests/resource_download_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
)

func TestAccResourceDownloadFile(t *testing.T) {
te := initTestEnvironment(t)

tests := []struct {
name string
steps []resource.TestStep
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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)
})
},
Expand All @@ -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",
Expand All @@ -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,
})
})
Expand Down
Loading