Skip to content

Commit

Permalink
Rightly (un)set GPU fields on MachineGuest.SetSize() (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangra authored Mar 15, 2024
1 parent d63d18a commit e90a41e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ func (mg *MachineGuest) SetSize(size string) error {
mg.CPUKind = guest.CPUKind
mg.MemoryMB = guest.MemoryMB
mg.GPUKind = guest.GPUKind
mg.GPUs = guest.GPUs
return nil
}

Expand Down
18 changes: 18 additions & 0 deletions machine_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ func TestMachineGuest_SetSize(t *testing.T) {
t.Error("want error for invalid preset name")
}

// Set GPU related fields that must be unset for non-gpu-size-alias
if err := guest.SetSize("a100-40gb"); err != nil {
t.Errorf("got error for valid preset name: %v", err)
} else {
if guest.GPUs != 1 {
t.Errorf("Expected 1 gpu, got: %v", guest.GPUs)
}
if guest.GPUKind != "a100-pcie-40gb" {
t.Errorf("Expected a100-pcie-40gb gpu kind, got: %v", guest.GPUKind)
}
}

if err := guest.SetSize("performance-4x"); err != nil {
t.Errorf("got error for valid preset name: %v", err)
} else {
Expand All @@ -142,6 +154,12 @@ func TestMachineGuest_SetSize(t *testing.T) {
if guest.MemoryMB != 8192 {
t.Errorf("Expected 8192 MB of memory , got: %v", guest.MemoryMB)
}
if guest.GPUs != 0 {
t.Errorf("Expected 0 gpus, got: %v", guest.GPUs)
}
if guest.GPUKind != "" {
t.Errorf("Expected non gpu kind, got: %v", guest.GPUKind)
}
}
}

Expand Down

0 comments on commit e90a41e

Please sign in to comment.