Skip to content

Commit b00213a

Browse files
committed
Fix staticcheck QF1003 warnings
Use switch instead of if/else where appropriate. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 5bae0b9 commit b00213a

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

cmd/runtimetest/main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,10 @@ func testFileReadAccess(path string) (readable bool, err error) {
454454
defer f.Close()
455455
b := make([]byte, 1)
456456
_, err = f.Read(b)
457-
if err == nil {
457+
switch err {
458+
case nil:
458459
return true, nil
459-
} else if err == io.EOF {
460+
case io.EOF:
460461
// Our validation/ tests only use non-empty files for read-access
461462
// tests. So if we get an EOF on the first read, the runtime did
462463
// successfully block readability.
@@ -1310,10 +1311,11 @@ func run(context *cli.Context) error {
13101311
}
13111312

13121313
validations := defaultValidations
1313-
if platform == "linux" {
1314+
switch platform {
1315+
case "linux":
13141316
validations = append(validations, posixValidations...)
13151317
validations = append(validations, linuxValidations...)
1316-
} else if platform == "solaris" {
1318+
case "solaris":
13171319
validations = append(validations, posixValidations...)
13181320
}
13191321

generate/generate.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ func New(os string) (generator Generator, err error) {
8989
}
9090
}
9191

92-
if os == "linux" {
92+
switch os {
93+
case "linux":
9394
config.Process.Capabilities = &rspec.LinuxCapabilities{
9495
Bounding: []string{
9596
"CAP_CHOWN",
@@ -238,7 +239,7 @@ func New(os string) (generator Generator, err error) {
238239
},
239240
Seccomp: seccomp.DefaultProfile(&config),
240241
}
241-
} else if os == "freebsd" {
242+
case "freebsd":
242243
config.Mounts = []rspec.Mount{
243244
{
244245
Destination: "/dev",

validate/validate.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,17 +719,18 @@ func (v *Validator) rlimitValid(rlimit rspec.POSIXRlimit) (errs error) {
719719
errs = multierror.Append(errs, fmt.Errorf("hard limit of rlimit %s should not be less than soft limit", rlimit.Type))
720720
}
721721

722-
if v.platform == "linux" {
722+
switch v.platform {
723+
case "linux":
723724
if slices.Contains(linuxRlimits, rlimit.Type) {
724725
return
725726
}
726727
errs = multierror.Append(errs, specerror.NewError(specerror.PosixProcRlimitsTypeValueError, fmt.Errorf("rlimit type %q may not be valid", rlimit.Type), v.spec.Version))
727-
} else if v.platform == "solaris" {
728+
case "solaris":
728729
if slices.Contains(posixRlimits, rlimit.Type) {
729730
return
730731
}
731732
errs = multierror.Append(errs, specerror.NewError(specerror.PosixProcRlimitsTypeValueError, fmt.Errorf("rlimit type %q may not be valid", rlimit.Type), v.spec.Version))
732-
} else {
733+
default:
733734
logrus.Warnf("process.rlimits validation not yet implemented for platform %q", v.platform)
734735
}
735736

0 commit comments

Comments
 (0)