Skip to content

Commit b035bff

Browse files
committed
chore: add acceptance tests
Signed-off-by: Pavel Boldyrev <[email protected]>
1 parent 59736fb commit b035bff

File tree

4 files changed

+119
-8
lines changed

4 files changed

+119
-8
lines changed

fwprovider/test/resource_container_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ func TestAccResourceContainer(t *testing.T) {
3838
accTestContainerIDClone := 100000 + rand.Intn(99999)
3939

4040
te.AddTemplateVars(map[string]interface{}{
41-
"ImageFileName": imageFileName,
42-
"TestContainerID": accTestContainerID,
43-
"TestContainerIDClone": accTestContainerIDClone,
41+
"ImageFileName": imageFileName,
42+
"TestContainerID": accTestContainerID,
43+
"TestContainerIDClone": accTestContainerIDClone,
4444
})
4545

4646
err := te.NodeStorageClient().DownloadFileByURL(context.Background(), &storage.DownloadURLPostRequestBody{
@@ -685,9 +685,9 @@ func TestAccResourceContainer(t *testing.T) {
685685
}`, WithRootUser()),
686686
Check: resource.ComposeTestCheckFunc(
687687
ResourceAttributes(accTestContainerName, map[string]string{
688-
"initialization.0.hostname": "test-dns-update",
689-
"initialization.0.dns.#": "1",
690-
"initialization.0.dns.0.domain": "example.com",
688+
"initialization.0.hostname": "test-dns-update",
689+
"initialization.0.dns.#": "1",
690+
"initialization.0.dns.0.domain": "example.com",
691691
"initialization.0.dns.0.servers.#": "2",
692692
"initialization.0.dns.0.servers.0": "8.8.8.8",
693693
"initialization.0.dns.0.servers.1": "8.8.4.4",

fwprovider/test/resource_vm_test.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,117 @@ func TestAccResourceVMNetwork(t *testing.T) {
770770
),
771771
},
772772
}},
773+
{"multiple network devices removal", []resource.TestStep{
774+
{
775+
Config: te.RenderConfig(`
776+
resource "proxmox_virtual_environment_vm" "test_vm" {
777+
node_name = "{{.NodeName}}"
778+
started = false
779+
780+
network_device {
781+
bridge = "vmbr0"
782+
model = "virtio"
783+
}
784+
785+
network_device {
786+
bridge = "vmbr1"
787+
model = "virtio"
788+
}
789+
}`),
790+
Check: resource.ComposeTestCheckFunc(
791+
ResourceAttributes("proxmox_virtual_environment_vm.test_vm", map[string]string{
792+
"network_device.#": "2",
793+
"network_device.0.bridge": "vmbr0",
794+
"network_device.1.bridge": "vmbr1",
795+
}),
796+
),
797+
},
798+
{
799+
Config: te.RenderConfig(`
800+
resource "proxmox_virtual_environment_vm" "test_vm" {
801+
node_name = "{{.NodeName}}"
802+
started = false
803+
804+
# Only keep the first network device
805+
network_device {
806+
bridge = "vmbr0"
807+
model = "virtio"
808+
}
809+
}`),
810+
Check: resource.ComposeTestCheckFunc(
811+
ResourceAttributes("proxmox_virtual_environment_vm.test_vm", map[string]string{
812+
"network_device.#": "1",
813+
"network_device.0.bridge": "vmbr0",
814+
}),
815+
),
816+
},
817+
{
818+
Config: te.RenderConfig(`
819+
resource "proxmox_virtual_environment_vm" "test_vm" {
820+
node_name = "{{.NodeName}}"
821+
started = false
822+
}`),
823+
Check: resource.ComposeTestCheckFunc(
824+
ResourceAttributes("proxmox_virtual_environment_vm.test_vm", map[string]string{
825+
"network_device.#": "0",
826+
}),
827+
),
828+
},
829+
}},
830+
{"network device state consistency", []resource.TestStep{
831+
{
832+
Config: te.RenderConfig(`
833+
resource "proxmox_virtual_environment_vm" "test_vm" {
834+
node_name = "{{.NodeName}}"
835+
started = false
836+
837+
network_device {
838+
bridge = "vmbr0"
839+
model = "virtio"
840+
}
841+
}`),
842+
Check: resource.ComposeTestCheckFunc(
843+
ResourceAttributes("proxmox_virtual_environment_vm.test_vm", map[string]string{
844+
"network_device.#": "1",
845+
"network_device.0.bridge": "vmbr0",
846+
"network_device.0.model": "virtio",
847+
}),
848+
),
849+
},
850+
{
851+
// This step tests that the state is read correctly after network device removal
852+
Config: te.RenderConfig(`
853+
resource "proxmox_virtual_environment_vm" "test_vm" {
854+
node_name = "{{.NodeName}}"
855+
started = false
856+
}`),
857+
Check: resource.ComposeTestCheckFunc(
858+
ResourceAttributes("proxmox_virtual_environment_vm.test_vm", map[string]string{
859+
"network_device.#": "0",
860+
}),
861+
),
862+
},
863+
{
864+
// This step tests that we can add network devices back after removal
865+
Config: te.RenderConfig(`
866+
resource "proxmox_virtual_environment_vm" "test_vm" {
867+
node_name = "{{.NodeName}}"
868+
started = false
869+
870+
network_device {
871+
bridge = "vmbr0"
872+
model = "virtio"
873+
}
874+
}`),
875+
Check: resource.ComposeTestCheckFunc(
876+
ResourceAttributes("proxmox_virtual_environment_vm.test_vm", map[string]string{
877+
"network_device.#": "1",
878+
"network_device.0.bridge": "vmbr0",
879+
"network_device.0.model": "virtio",
880+
}),
881+
),
882+
},
883+
}},
773884
}
774885

775886
for _, tt := range tests {

proxmoxtf/provider/provider.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
8080
csrfPreventionToken = v.(string)
8181
}
8282

83-
//nolint:staticcheck
8483
if v, ok := d.GetOkExists(mkProviderAPIToken); ok {
8584
apiToken = v.(string)
8685
}
@@ -94,7 +93,6 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
9493
username = v.(string)
9594
}
9695

97-
//nolint:staticcheck
9896
if v, ok := d.GetOkExists(mkProviderPassword); ok {
9997
password = v.(string)
10098
}

proxmoxtf/resource/vm/network/network.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func valueOrDefault[T any](v *T, def T) T {
101101
if v == nil {
102102
return def
103103
}
104+
104105
return *v
105106
}
106107

@@ -171,6 +172,7 @@ func ReadNetworkDeviceObjects(d *schema.ResourceData, vmConfig *vms.GetResponseD
171172
if trunks == nil {
172173
return ""
173174
}
175+
174176
return strings.Trim(strings.Join(strings.Fields(fmt.Sprint(trunks)), ";"), "[]")
175177
}(netDevice.Trunks),
176178
})

0 commit comments

Comments
 (0)