Skip to content

Commit 0631bc8

Browse files
authored
Merge pull request #565 from atombrella/feature/switch_case
Staticcheck/QF1003: Replace if-else with switch-case for OSType checks.
2 parents 66c62a8 + 3702406 commit 0631bc8

4 files changed

Lines changed: 12 additions & 10 deletions

File tree

builder/azure/arm/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,15 +1575,16 @@ func assertRequiredParametersSet(c *Config, errs *packersdk.MultiError) {
15751575
if c.LicenseType != "" {
15761576
// Assumes OS is case-sensitive match as it has already been
15771577
// normalized earlier in function
1578-
if c.OSType == constants.Target_Linux {
1578+
switch c.OSType {
1579+
case constants.Target_Linux:
15791580
if strings.EqualFold(c.LicenseType, constants.License_RHEL) {
15801581
c.LicenseType = constants.License_RHEL
15811582
} else if strings.EqualFold(c.LicenseType, constants.License_SUSE) {
15821583
c.LicenseType = constants.License_SUSE
15831584
} else {
15841585
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("The license_type %q is invalid for Linux, only RHEL_BYOS or SLES_BYOS are supported", c.LicenseType))
15851586
}
1586-
} else if c.OSType == constants.Target_Windows {
1587+
case constants.Target_Windows:
15871588
if strings.EqualFold(c.LicenseType, constants.License_Windows_Client) {
15881589
c.LicenseType = constants.License_Windows_Client
15891590
} else if strings.EqualFold(c.LicenseType, constants.License_Windows_Server) {
@@ -1774,7 +1775,6 @@ func (c *Config) validateLocationZoneResiliency(say func(s string)) {
17741775
zones["switzerlandnorth"] = struct{}{}
17751776
zones["uksouth"] = struct{}{}
17761777
zones["usgovvirginia"] = struct{}{}
1777-
zones["westeurope"] = struct{}{}
17781778
zones["westus2"] = struct{}{}
17791779
zones["westus3"] = struct{}{}
17801780

builder/azure/chroot/step_verify_shared_image_source_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ func TestStepVerifySharedImageSource_Run(t *testing.T) {
130130
if !tt.shouldCallGetVersion {
131131
t.Fatalf("Expected test to not call getVersion but it did")
132132
}
133-
switch {
134-
case id.VersionName == "1.2.3":
133+
switch id.VersionName {
134+
case "1.2.3":
135135
return &galleryimageversions.GalleryImageVersion{
136136
Id: common.StringPtr("image-version-id"),
137137
Properties: &galleryimageversions.GalleryImageVersionProperties{

builder/azure/dtl/builder.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
194194
ui.Say(fmt.Sprintf("No lab network information provided. Using %s Virtual network and %s subnet for Virtual Machine creation", b.config.LabVirtualNetworkName, b.config.LabSubnetName))
195195
}
196196

197-
if b.config.OSType == constants.Target_Linux {
197+
switch b.config.OSType {
198+
case constants.Target_Linux:
198199
steps = []multistep.Step{
199200
NewStepDeployTemplate(azureClient, ui, &b.config, deploymentName, GetVirtualMachineDeployment),
200201
&communicator.StepConnectSSH{
@@ -208,7 +209,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
208209
},
209210
NewStepPowerOffCompute(azureClient, ui, &b.config),
210211
}
211-
} else if b.config.OSType == constants.Target_Windows {
212+
case constants.Target_Windows:
212213
steps = []multistep.Step{
213214
NewStepDeployTemplate(azureClient, ui, &b.config, deploymentName, GetVirtualMachineDeployment),
214215
&StepSaveWinRMPassword{
@@ -230,7 +231,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
230231
&commonsteps.StepProvision{},
231232
NewStepPowerOffCompute(azureClient, ui, &b.config),
232233
}
233-
} else {
234+
default:
234235
return nil, fmt.Errorf("Builder does not support the os_type '%s'", b.config.OSType)
235236
}
236237

builder/azure/dtl/step_capture_image.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ func (s *StepCaptureImage) captureImageFromVM(ctx context.Context) error {
4848

4949
customImageProperties := customimages.CustomImageProperties{}
5050

51-
if s.config.OSType == constants.Target_Linux {
51+
switch s.config.OSType {
52+
case constants.Target_Linux:
5253
deprovision := customimages.LinuxOsStateDeprovisionRequested
5354
if s.config.SkipSysprep {
5455
deprovision = customimages.LinuxOsStateDeprovisionApplied
@@ -61,7 +62,7 @@ func (s *StepCaptureImage) captureImageFromVM(ctx context.Context) error {
6162
SourceVMId: &imageID,
6263
},
6364
}
64-
} else if s.config.OSType == constants.Target_Windows {
65+
case constants.Target_Windows:
6566
deprovision := customimages.WindowsOsStateSysprepRequested
6667
if s.config.SkipSysprep {
6768
deprovision = customimages.WindowsOsStateSysprepApplied

0 commit comments

Comments
 (0)