diff --git a/cmd/nvidia-container-runtime/main_test.go b/cmd/nvidia-container-runtime/main_test.go index 185c3378..90bfbea7 100644 --- a/cmd/nvidia-container-runtime/main_test.go +++ b/cmd/nvidia-container-runtime/main_test.go @@ -193,14 +193,15 @@ func (c testConfig) getRuntimeSpec() (specs.Spec, error) { defer jsonFile.Close() jsonContent, err := io.ReadAll(jsonFile) - if err != nil { + switch { + case err != nil: return spec, err - } else if json.Valid(jsonContent) { + case json.Valid(jsonContent): err = json.Unmarshal(jsonContent, &spec) if err != nil { return spec, err } - } else { + default: err = json.NewDecoder(bytes.NewReader(jsonContent)).Decode(&spec) if err != nil { return spec, err diff --git a/internal/oci/spec_memory_test.go b/internal/oci/spec_memory_test.go index a43944a4..3e8ba0ed 100644 --- a/internal/oci/spec_memory_test.go +++ b/internal/oci/spec_memory_test.go @@ -152,12 +152,13 @@ func TestModify(t *testing.T) { err := spec.Modify(modifier{tc.modifierError}) - if tc.spec == nil { + switch { + case tc.spec == nil: require.Error(t, err, "%d: %v", i, tc) - } else if tc.modifierError != nil { + case tc.modifierError != nil: require.EqualError(t, err, tc.modifierError.Error(), "%d: %v", i, tc) require.EqualValues(t, &specs.Spec{}, spec.Spec, "%d: %v", i, tc) - } else { + default: require.NoError(t, err, "%d: %v", i, tc) require.Equal(t, "updated", spec.Spec.Version, "%d: %v", i, tc) } diff --git a/internal/platform-support/tegra/symlinks.go b/internal/platform-support/tegra/symlinks.go index c64138db..283b2f4d 100644 --- a/internal/platform-support/tegra/symlinks.go +++ b/internal/platform-support/tegra/symlinks.go @@ -80,19 +80,20 @@ func (d symlinkHook) getSpecificLinks() ([]string, error) { lib := filepath.Base(m.Path) - if strings.HasPrefix(lib, "libcuda.so") { + switch { + case strings.HasPrefix(lib, "libcuda.so"): // XXX Many applications wrongly assume that libcuda.so exists (e.g. with dlopen). target = "libcuda.so.1" link = "libcuda.so" - } else if strings.HasPrefix(lib, "libGLX_nvidia.so") { + case strings.HasPrefix(lib, "libGLX_nvidia.so"): // XXX GLVND requires this symlink for indirect GLX support. target = lib link = "libGLX_indirect.so.0" - } else if strings.HasPrefix(lib, "libnvidia-opticalflow.so") { + case strings.HasPrefix(lib, "libnvidia-opticalflow.so"): // XXX Fix missing symlink for libnvidia-opticalflow.so. target = "libnvidia-opticalflow.so.1" link = "libnvidia-opticalflow.so" - } else { + default: continue } if linkProcessed[link] { diff --git a/internal/runtime/logger.go b/internal/runtime/logger.go index 2cf2c953..a23702a4 100644 --- a/internal/runtime/logger.go +++ b/internal/runtime/logger.go @@ -104,11 +104,12 @@ func (l *Logger) Update(filename string, logLevel string, argv []string) { newLogger.SetFormatter(new(logrus.JSONFormatter)) } - if len(logFiles) == 0 { + switch len(logFiles) { + case 0: newLogger.SetOutput(io.Discard) - } else if len(logFiles) == 1 { + case 1: newLogger.SetOutput(logFiles[0]) - } else if len(logFiles) > 1 { + default: var writers []io.Writer for _, f := range logFiles { writers = append(writers, f) @@ -234,12 +235,13 @@ func parseArgs(args []string) loggerConfig { } var value string - if len(parts) == 2 { + switch { + case len(parts) == 2: value = parts[2] - } else if i+1 < len(args) { + case i+1 < len(args): value = args[i+1] i++ - } else { + default: continue }