File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 8
8
"context"
9
9
"encoding/json"
10
10
"os"
11
+ "path/filepath"
11
12
)
12
13
13
14
// FileCacher is the default Cacher used in whatsnew.
@@ -31,6 +32,10 @@ func (f *FileCacher) Get(context.Context) (*Info, error) {
31
32
32
33
// Set cached release Info.
33
34
func (f * FileCacher ) Set (_ context.Context , i * Info ) error {
35
+ if err := os .MkdirAll (filepath .Dir (f .Path ), 0750 ); err != nil {
36
+ return err
37
+ }
38
+
34
39
w , err := os .Create (f .Path )
35
40
if err != nil {
36
41
return err
Original file line number Diff line number Diff line change @@ -57,3 +57,35 @@ func TestFileCacher_roundTrip(t *testing.T) {
57
57
}
58
58
59
59
}
60
+
61
+ func TestFileCacher_errOnWrite (t * testing.T ) {
62
+ ctx := context .Background ()
63
+
64
+ fc := impl.FileCacher {Path : filepath .Join ("/" , "test-cache.json" )}
65
+
66
+ err := fc .Set (ctx , & impl.Info {
67
+ CheckTime : time .Now (),
68
+ Version : "v1.1.2" ,
69
+ Etag : `"some-etag"` ,
70
+ })
71
+
72
+ if err == nil {
73
+ t .Errorf ("expected err but go none" )
74
+ }
75
+ }
76
+
77
+ func TestFileCacher_errOnMkDir (t * testing.T ) {
78
+ ctx := context .Background ()
79
+
80
+ fc := impl.FileCacher {Path : filepath .Join ("/" , "whatsnew-test" , "test-cache.json" )}
81
+
82
+ err := fc .Set (ctx , & impl.Info {
83
+ CheckTime : time .Now (),
84
+ Version : "v1.1.2" ,
85
+ Etag : `"some-etag"` ,
86
+ })
87
+
88
+ if err == nil {
89
+ t .Errorf ("expected err but go none" )
90
+ }
91
+ }
You can’t perform that action at this time.
0 commit comments