0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-01 02:52:58 +00:00
terraform-provider-proxmox/proxmox/nodes/vms/custom_virtiofs_share_test.go
Fina 55b3f7391a
feat(vm): add support for virtiofs (#1900)
Signed-off-by: Fina Wilke <code@felinira.net>
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
2025-04-15 13:10:37 -04:00

80 lines
1.9 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 vms
import (
"testing"
"github.com/bpg/terraform-provider-proxmox/proxmox/helpers/ptr"
"github.com/bpg/terraform-provider-proxmox/proxmox/types"
)
func TestCustomVirtiofsShare_UnmarshalJSON(t *testing.T) {
t.Parallel()
tests := []struct {
name string
line string
want *CustomVirtiofsShare
wantErr bool
}{
{
name: "id only virtiofs share",
line: `"test"`,
want: &CustomVirtiofsShare{
DirId: "test",
},
},
{
name: "virtiofs share with more details",
line: `"folder,cache=always"`,
want: &CustomVirtiofsShare{
DirId: "folder",
Cache: ptr.Ptr("always"),
},
},
{
name: "virtiofs share with flags",
line: `"folder,cache=never,direct-io=1,expose-acl=1"`,
want: &CustomVirtiofsShare{
DirId: "folder",
Cache: ptr.Ptr("never"),
DirectIo: types.CustomBool(true).Pointer(),
ExposeAcl: types.CustomBool(true).Pointer(),
ExposeXattr: types.CustomBool(true).Pointer(),
},
},
{
name: "virtiofs share with xattr",
line: `"folder,expose-xattr=1"`,
want: &CustomVirtiofsShare{
DirId: "folder",
Cache: nil,
DirectIo: types.CustomBool(false).Pointer(),
ExposeAcl: types.CustomBool(false).Pointer(),
ExposeXattr: types.CustomBool(true).Pointer(),
},
},
{
name: "virtiofs share invalid combination",
line: `"folder,expose-acl=1,expose-xattr=0"`,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
r := &CustomVirtiofsShare{}
if err := r.UnmarshalJSON([]byte(tt.line)); (err != nil) != tt.wantErr {
t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}