0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-03 20:12:59 +00:00
terraform-provider-proxmox/proxmoxtf/resource/utils_test.go
Leah 4147ff6a29
feat: add import support for a lot of resources (#390)
* add import support for a lot of resources

* fix lints

* set user_id after importing

(cherry picked from commit c3d09ed00f6e1d7b0bb3ab01a1fc5c81510aa2e1)

* add tests, fix empty ID

* add import docs

* fix lint
2023-07-04 21:37:14 -04:00

82 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 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()
require := require.New(t)
f := getCPUTypeValidator()
res := f(tt.value, nil)
if tt.valid {
require.Empty(res, "validate: '%s'", tt.value)
} else {
require.NotEmpty(res, "validate: '%s'", tt.value)
}
})
}
}
func Test_parseImportIDWIthNodeName(t *testing.T) {
t.Parallel()
tests := []struct {
name string
value string
valid bool
expectedNodeName string
expectedID string
}{
{"empty", "", false, "", ""},
{"missing slash", "invalid", false, "", ""},
{"valid", "host/id", true, "host", "id"},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
require := require.New(t)
nodeName, id, err := parseImportIDWithNodeName(tt.value)
if !tt.valid {
require.Error(err)
return
}
require.Nil(err)
require.Equal(tt.expectedNodeName, nodeName)
require.Equal(tt.expectedID, id)
})
}
}