Skip to content

Commit

Permalink
add test when both host and mapping keys are specified
Browse files Browse the repository at this point in the history
  • Loading branch information
romantomjak committed Jul 17, 2023
1 parent dcd8971 commit 78bb40a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions builder/proxmox/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ func (c *Config) Prepare(upper interface{}, raws ...interface{}) ([]string, []st
if device.Host == "" && device.Mapping == "" {
errs = packersdk.MultiErrorAppend(errs, errors.New("either the host or the mapping key must be specified"))
}
if device.Host != "" && device.Mapping != "" {
errs = packersdk.MultiErrorAppend(errs, errors.New("the host and the mapping key cannot both be set"))
}
if device.Host != "" && !validPCIIDre.MatchString(device.Host) {
errs = packersdk.MultiErrorAppend(errs, errors.New("host contains invalid PCI ID"))
}
Expand Down
7 changes: 7 additions & 0 deletions builder/proxmox/common/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,13 @@ func TestPCIDeviceMapping(t *testing.T) {
{
expectedError: fmt.Errorf("either the host or the mapping key must be specified"),
},
{
expectedError: fmt.Errorf("the host and the mapping key cannot both be set"),
pciDeviceConfig: pciDeviceConfig{
Host: "0000:03:00.0",
Mapping: "someNic",
},
},
{
expectedError: fmt.Errorf("host contains invalid PCI ID"),
pciDeviceConfig: pciDeviceConfig{
Expand Down

0 comments on commit 78bb40a

Please sign in to comment.