Skip to content

Commit

Permalink
fix: CreateSATAController to return error when no bus numbers
Browse files Browse the repository at this point in the history
Signed-off-by: Sai Diliyaer <sai.diliyaer@gmail.com>
  • Loading branch information
dilyar85 committed Oct 31, 2024
1 parent bbb6349 commit 60d4b04
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions object/virtual_device_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ func (l VirtualDeviceList) FindSATAController(name string) (types.BaseVirtualCon
func (l VirtualDeviceList) CreateSATAController() (types.BaseVirtualDevice, error) {
sata := &types.VirtualAHCIController{}
sata.BusNumber = l.newSATABusNumber()
if sata.BusNumber == -1 {
return nil, errors.New("no bus numbers available")
}

sata.Key = l.NewKey()

return sata, nil
Expand Down
18 changes: 18 additions & 0 deletions object/virtual_device_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,24 @@ func TestCreateSCSIController(t *testing.T) {
}
}

func TestCreateSATAController(t *testing.T) {
l := VirtualDeviceList{}
for _, i := range sataBusNumbers {
c, err := l.CreateSATAController()
if err != nil {
t.Error(err)
}
if j := c.(types.BaseVirtualController).GetVirtualController().BusNumber; j != int32(i) {
t.Errorf("expected bus number: %d, got: %d", i, j)
}
l = append(l, c)
}

if _, err := l.CreateSATAController(); err == nil {
t.Error("should fail")
}
}

func TestCreateEthernetCard(t *testing.T) {
_, err := EthernetCardTypes().CreateEthernetCard("enoent", nil)
if err == nil {
Expand Down

0 comments on commit 60d4b04

Please sign in to comment.