0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-01 19:12:59 +00:00
terraform-provider-proxmox/proxmoxtf/resource/vm/validators_test.go
Mikael Nakajima 57c3970d54
fix(vm): fix vm machine type validation in order to support viommu (#1798)
* fix(vm): fix vm machine type validation in order to support viommu

Signed-off-by: Mikael Nakajima <nakamorichi@protonmail.com>

* docs(vm): update machine type documentation with VIOMMU details

Enhance VM machine type documentation to clarify VIOMMU configuration option for q35 machine type

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>

---------

Signed-off-by: Mikael Nakajima <nakamorichi@protonmail.com>
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
2025-03-01 03:54:45 +00:00

80 lines
1.6 KiB
Go

/*
* 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 resource
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestCPUType(t *testing.T) {
t.Parallel()
tests := []struct {
name string
value string
valid bool
}{
{"empty", "", false},
{"invalid", "invalid", false},
{"valid", "host", true},
{"valid", "qemu64", true},
{"valid", "custom-abc", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
f := CPUTypeValidator()
res := f(tt.value, nil)
if tt.valid {
require.Empty(t, res, "validate: '%s'", tt.value)
} else {
require.NotEmpty(t, res, "validate: '%s'", tt.value)
}
})
}
}
func TestMachineType(t *testing.T) {
t.Parallel()
tests := []struct {
name string
value string
valid bool
}{
{"empty is valid", "", true},
{"invalid", "invalid", false},
{"valid q35", "q35", true},
{"valid q35 with viommu", "q35,viommu=virtio", true},
{"invalid q35 with viommu", "q35,viommu=invalid", false},
{"valid pc-q35", "pc-q35-2.3", true},
{"valid i440fx", "pc-i440fx-3.1+pve0", true},
{"valid virt", "virt", true},
{"invalid i440fx", "i440fx", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
f := MachineTypeValidator()
res := f(tt.value, nil)
if tt.valid {
require.Empty(t, res, "validate: '%s'", tt.value)
} else {
require.NotEmpty(t, res, "validate: '%s'", tt.value)
}
})
}
}