Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Description can't be cleared #347

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions proxmox/config_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type ConfigQemu struct {
Boot string `json:"boot,omitempty"` // TODO should be an array of custom enums
BootDisk string `json:"bootdisk,omitempty"` // TODO discuss deprecation? Only returned as it's deprecated in the proxmox api
CloudInit *CloudInit `json:"cloudinit,omitempty"`
Description string `json:"description,omitempty"`
Description *string `json:"description,omitempty"`
Disks *QemuStorages `json:"disks,omitempty"`
EFIDisk QemuDevice `json:"efidisk,omitempty"` // TODO should be a struct
FullClone *int `json:"fullclone,omitempty"` // TODO should probably be a bool
Expand Down Expand Up @@ -189,8 +189,12 @@ func (config ConfigQemu) mapToAPI(currentConfig ConfigQemu, version Version) (re
if config.QemuCpu != "" {
params["cpu"] = config.QemuCpu
}
if config.Description != "" {
params["description"] = config.Description
if config.Description != nil {
if *config.Description != "" {
params["description"] = *config.Description
} else if currentConfig.Description != nil {
itemsToDelete += ",description"
}
}
if config.Hookscript != "" {
params["hookscript"] = config.Hookscript
Expand Down Expand Up @@ -356,7 +360,8 @@ func (ConfigQemu) mapToStruct(vmr *VmRef, params map[string]interface{}) (*Confi
config.Bios = params["bios"].(string)
}
if _, isSet := params["description"]; isSet {
config.Description = strings.TrimSpace(params["description"].(string))
tmp := params["description"].(string)
config.Description = &tmp
}
//Can be network,disk,cpu,memory,usb
if _, isSet := params["hotplug"]; isSet {
Expand Down
19 changes: 19 additions & 0 deletions proxmox/config_qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,21 @@ func Test_ConfigQemu_mapToAPI(t *testing.T) {
config: &ConfigQemu{CloudInit: &CloudInit{Username: util.Pointer("")}},
currentConfig: ConfigQemu{CloudInit: &CloudInit{Username: util.Pointer("admin")}},
output: map[string]interface{}{"delete": "ciuser"}}}},
{category: `Description`,
create: []test{
{name: `Description empty`,
config: &ConfigQemu{Description: util.Pointer("")},
output: map[string]interface{}{}}},
createUpdate: []test{
{name: `Description set`,
config: &ConfigQemu{Description: util.Pointer("test description")},
currentConfig: ConfigQemu{Description: util.Pointer("old description")},
output: map[string]interface{}{"description": "test description"}}},
update: []test{
{name: `Description empty`,
config: &ConfigQemu{Description: util.Pointer("")},
currentConfig: ConfigQemu{Description: util.Pointer("old description")},
output: map[string]interface{}{"delete": "description"}}}},
{category: `Disks.Ide`,
update: []test{
{name: `Disk.Ide.Disk_X DELETE`,
Expand Down Expand Up @@ -3388,6 +3403,10 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) {
{name: `Username empty`,
input: map[string]interface{}{"ciuser": string(" ")},
output: &ConfigQemu{}}}},
{category: `Description`,
tests: []test{
{input: map[string]interface{}{"description": string("test description")},
output: &ConfigQemu{Description: util.Pointer("test description")}}}},
{category: `Disks Ide CdRom`,
tests: []test{
{name: `none`,
Expand Down
Loading