Skip to content

Commit 58fd179

Browse files
authored
refactor: os checks (#350)
Replaces string literals for OS checks with predefined constants for improved maintainability and consistency. Signed-off-by: Ryan Johnson <ryan.johnson@broadcom.com>
1 parent 411910a commit 58fd179

5 files changed

Lines changed: 8 additions & 8 deletions

File tree

builder/vmware/common/driver.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,13 @@ func NewDriver(dconfig *DriverConfig, config *SSHConfig, vmName string) (Driver,
283283

284284
} else {
285285
switch runtime.GOOS {
286-
case "darwin":
286+
case osMacOS:
287287
drivers = []Driver{
288288
NewFusionDriver(dconfig, config),
289289
}
290-
case "linux":
290+
case osLinux:
291291
fallthrough
292-
case "windows":
292+
case osWindows:
293293
drivers = []Driver{
294294
NewWorkstationDriver(config),
295295
}
@@ -589,7 +589,7 @@ func (d *VmwareDriver) PotentialGuestIP(state multistep.StateBag) ([]string, err
589589
return addrs, nil
590590
}
591591

592-
if runtime.GOOS == "darwin" {
592+
if runtime.GOOS == osMacOS {
593593
// We have match no vmware DHCP lease for this MAC. We'll try to match it in Apple DHCP leases.
594594
// As a remember, VMware is no longer able to rely on its own dhcpd server on MacOS BigSur and is
595595
// forced to use Apple DHCPD server instead.

builder/vmware/common/driver_workstation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (d *WorkstationDriver) Verify() error {
261261

262262
// For non-Windows, if neither the default nor alternate configuration
263263
// paths exist, return an error.
264-
if err != nil && runtime.GOOS != "windows" {
264+
if err != nil && runtime.GOOS != osWindows {
265265
return nil, err
266266
}
267267

builder/vmware/common/driver_workstation_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func workstationNetmapConfPath() string {
139139
// workstationVerifyVersion verifies the VMware Workstation version against the
140140
// required version using workstationTestVersion.
141141
func workstationVerifyVersion(version string) error {
142-
if runtime.GOOS != "linux" {
142+
if runtime.GOOS != osLinux {
143143
return fmt.Errorf("driver is only supported on Linux, not %s", runtime.GOOS)
144144
}
145145

builder/vmware/common/hw_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func (c *HWConfig) HasSerial() bool {
269269

270270
func (c *HWConfig) ReadSerial() (*SerialUnion, error) {
271271
var defaultSerialPort string
272-
if runtime.GOOS == "windows" {
272+
if runtime.GOOS == osWindows {
273273
defaultSerialPort = "COM1"
274274
} else {
275275
defaultSerialPort = "/dev/ttyS0"

builder/vmware/common/tools_config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestToolsConfigPrepare_SourceSuccess(t *testing.T) {
5757
},
5858
{
5959
ToolsSourcePath: "path/to/tools.iso",
60-
ToolsUploadFlavor: "linux",
60+
ToolsUploadFlavor: osLinux,
6161
},
6262
} {
6363
errs := c.Prepare(interpolate.NewContext())

0 commit comments

Comments
 (0)