Skip to content

Code cleanup #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/cdi/cmd/cdi-api.go
Original file line number Diff line number Diff line change
@@ -271,7 +271,7 @@ func cdiListSpecs(verbose bool, format string, vendors ...string) {
fmt.Printf("Vendor %s:\n", vendor)
for _, spec := range cache.GetVendorSpecs(vendor) {
cdiPrintSpec(spec, verbose, format, 2)
cdiPrintSpecErrors(spec, verbose, 2)
cdiPrintSpecErrors(2)
}
}
}
@@ -284,7 +284,7 @@ func cdiPrintSpec(spec *cdi.Spec, verbose bool, format string, level int) {
}
}

func cdiPrintSpecErrors(spec *cdi.Spec, verbose bool, level int) {
func cdiPrintSpecErrors(level int) {
var (
cache = cdi.GetDefaultCache()
cdiErrors = cache.GetErrors()
8 changes: 4 additions & 4 deletions pkg/cdi/cache_test.go
Original file line number Diff line number Diff line change
@@ -557,7 +557,7 @@ devices:
cache = newCache(opts...)
require.NotNil(t, cache)
} else {
err = updateSpecDirs(t, dir, update.etc, update.run)
err = updateSpecDirs(dir, update.etc, update.run)
if err != nil {
t.Errorf("failed to update test directory: %v", err)
return
@@ -743,7 +743,7 @@ devices:
idx = 0
}
update := tc.updates[idx]
err = updateSpecDirs(t, dir, update.etc, update.run)
err = updateSpecDirs(dir, update.etc, update.run)
if err != nil {
return
}
@@ -1851,7 +1851,7 @@ func createSpecDirs(t *testing.T, etc, run map[string]string) (string, error) {
}

// Update spec directories with new data.
func updateSpecDirs(t *testing.T, dir string, etc, run map[string]string) error {
func updateSpecDirs(dir string, etc, run map[string]string) error {
updates := map[string]map[string]string{
"etc": {},
"run": {},
@@ -1869,7 +1869,7 @@ func updateSpecDirs(t *testing.T, dir string, etc, run map[string]string) error
}
}
}
return updateTestDir(t, dir, updates)
return updateTestDir(dir, updates)
}

func int64ptr(v int64) *int64 {
2 changes: 1 addition & 1 deletion pkg/cdi/default-cache_test.go
Original file line number Diff line number Diff line change
@@ -263,7 +263,7 @@ devices:
}
Configure(opts...)
} else {
err = updateSpecDirs(t, dir, update.etc, update.run)
err = updateSpecDirs(dir, update.etc, update.run)
if err != nil {
t.Errorf("failed to update test directory: %v", err)
return
11 changes: 5 additions & 6 deletions pkg/cdi/spec-dirs_test.go
Original file line number Diff line number Diff line change
@@ -175,9 +175,8 @@ devices:
dir, err = mkTestDir(t, map[string]map[string]string{
"etc": tc.files,
})
if err != nil {
t.Errorf("failed to populate test directory: %v", err)
}
require.NoError(t, err, "failed to populate test directory")

dir = filepath.Join(dir, "etc")
success = map[string]struct{}{}
failure = map[string]struct{}{}
@@ -186,7 +185,7 @@ devices:
}

dirs := []string{"/no-such-dir", dir}
err = scanSpecDirs(dirs, func(path string, prio int, spec *Spec, err error) error {
_ = scanSpecDirs(dirs, func(path string, prio int, spec *Spec, err error) error {
name := filepath.Base(path)
if err != nil {
failure[name] = struct{}{}
@@ -220,14 +219,14 @@ func mkTestDir(t *testing.T, dirs map[string]map[string]string) (string, error)
os.RemoveAll(tmp)
})

if err = updateTestDir(t, tmp, dirs); err != nil {
if err = updateTestDir(tmp, dirs); err != nil {
return "", err
}

return tmp, nil
}

func updateTestDir(t *testing.T, tmp string, dirs map[string]map[string]string) error {
func updateTestDir(tmp string, dirs map[string]map[string]string) error {
for sub, content := range dirs {
dir := filepath.Join(tmp, sub)
if err := os.MkdirAll(dir, 0755); err != nil {