mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-05 05:24:01 +00:00
frat(vm): Add custom CPU models support (#254)
* chore: add regex for custom cpu model validation * update logic to use TF validators & add tests --------- Co-authored-by: Kai Kahllund <kai.kahllund@akra.de> Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
parent
4d447390e6
commit
82016fc8ff
@ -98,7 +98,7 @@ func getCPUFlagsValidator() schema.SchemaValidateDiagFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getCPUTypeValidator() schema.SchemaValidateDiagFunc {
|
func getCPUTypeValidator() schema.SchemaValidateDiagFunc {
|
||||||
return validation.ToDiagFunc(validation.StringInSlice([]string{
|
standardTypes := []string{
|
||||||
"486",
|
"486",
|
||||||
"Broadwell",
|
"Broadwell",
|
||||||
"Broadwell-IBRS",
|
"Broadwell-IBRS",
|
||||||
@ -144,7 +144,12 @@ func getCPUTypeValidator() schema.SchemaValidateDiagFunc {
|
|||||||
"phenom",
|
"phenom",
|
||||||
"qemu32",
|
"qemu32",
|
||||||
"qemu64",
|
"qemu64",
|
||||||
}, false))
|
}
|
||||||
|
|
||||||
|
return validation.ToDiagFunc(validation.Any(
|
||||||
|
validation.StringInSlice(standardTypes, false),
|
||||||
|
validation.StringMatch(regexp.MustCompile(`^custom-.+$`), "must be a valid custom CPU type"),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFileFormatValidator() schema.SchemaValidateDiagFunc {
|
func getFileFormatValidator() schema.SchemaValidateDiagFunc {
|
||||||
|
37
proxmoxtf/utils_test.go
Normal file
37
proxmoxtf/utils_test.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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 proxmoxtf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_getCPUTypeValidator(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 {
|
||||||
|
tt := tt
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
f := getCPUTypeValidator()
|
||||||
|
res := f(tt.value, nil)
|
||||||
|
if !res.HasError() != tt.valid {
|
||||||
|
t.Errorf("validate: '%s', want %v got %v", tt.value, tt.valid, res)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user