Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 20b04bf

Browse files
committed
adding checks for errors in root_test.go and removing extra comment
1 parent 5cc17c6 commit 20b04bf

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

cmd/root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
pkgutil "github.com/GoogleContainerTools/container-diff/pkg/util"
2929
"github.com/GoogleContainerTools/container-diff/util"
3030
homedir "github.com/mitchellh/go-homedir"
31+
"github.com/pkg/errors"
3132
"github.com/sirupsen/logrus"
3233
"github.com/spf13/cobra"
3334
"github.com/spf13/pflag"
@@ -151,7 +152,7 @@ func getCacheDir(imageName string) (string, error) {
151152
if cacheDir == "" {
152153
dir, err := homedir.Dir()
153154
if err != nil {
154-
return "", err
155+
return "", errors.Wrap(err, "retrieving home dir")
155156
} else {
156157
cacheDir = dir
157158
}

cmd/root_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@ type testpair struct {
3131
}
3232

3333
func TestCacheDir(t *testing.T) {
34-
homeDir, _ := homedir.Dir()
34+
homeDir, err := homedir.Dir()
35+
if err != nil {
36+
t.Errorf("\nError getting home dir")
37+
}
38+
3539
tests := []struct {
3640
name string
3741
cliFlag string
3842
envVar string
3943
expectedDir string
4044
imageName string
4145
}{
42-
// name, cliFlag, envVar, expectedDir
4346
{
4447
name: "default cache is at $HOME",
4548
cliFlag: "",
@@ -80,7 +83,10 @@ func TestCacheDir(t *testing.T) {
8083
cacheDir = tt.cliFlag
8184

8285
// call getCacheDir and make sure return is equal to expected
83-
actualDir, _ := getCacheDir(tt.imageName)
86+
actualDir, err := getCacheDir(tt.imageName)
87+
if err != nil {
88+
t.Errorf("%s\nError getting cache dir", tt.name)
89+
}
8490

8591
if path.Dir(actualDir) != tt.expectedDir {
8692
t.Errorf("%s\nExpected: %v\nGot: %v", tt.name, tt.expectedDir, actualDir)

0 commit comments

Comments
 (0)