This repository was archived by the owner on Mar 27, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import (
28
28
pkgutil "github.com/GoogleContainerTools/container-diff/pkg/util"
29
29
"github.com/GoogleContainerTools/container-diff/util"
30
30
homedir "github.com/mitchellh/go-homedir"
31
+ "github.com/pkg/errors"
31
32
"github.com/sirupsen/logrus"
32
33
"github.com/spf13/cobra"
33
34
"github.com/spf13/pflag"
@@ -151,7 +152,7 @@ func getCacheDir(imageName string) (string, error) {
151
152
if cacheDir == "" {
152
153
dir , err := homedir .Dir ()
153
154
if err != nil {
154
- return "" , err
155
+ return "" , errors . Wrap ( err , "retrieving home dir" )
155
156
} else {
156
157
cacheDir = dir
157
158
}
Original file line number Diff line number Diff line change @@ -31,15 +31,18 @@ type testpair struct {
31
31
}
32
32
33
33
func TestCacheDir (t * testing.T ) {
34
- homeDir , _ := homedir .Dir ()
34
+ homeDir , err := homedir .Dir ()
35
+ if err != nil {
36
+ t .Errorf ("\n Error getting home dir" )
37
+ }
38
+
35
39
tests := []struct {
36
40
name string
37
41
cliFlag string
38
42
envVar string
39
43
expectedDir string
40
44
imageName string
41
45
}{
42
- // name, cliFlag, envVar, expectedDir
43
46
{
44
47
name : "default cache is at $HOME" ,
45
48
cliFlag : "" ,
@@ -80,7 +83,10 @@ func TestCacheDir(t *testing.T) {
80
83
cacheDir = tt .cliFlag
81
84
82
85
// 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\n Error getting cache dir" , tt .name )
89
+ }
84
90
85
91
if path .Dir (actualDir ) != tt .expectedDir {
86
92
t .Errorf ("%s\n Expected: %v\n Got: %v" , tt .name , tt .expectedDir , actualDir )
You can’t perform that action at this time.
0 commit comments