Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit c4c6c51

Browse files
committed
fix TestSourceManagerInit
- Re-create cache directory before trying to call `NewSourceManager` the 2nd time and defer it's removal. - If `NewSourceManager` fails the 2nd time, exit the error using `t.Fatal` to avoid panic in `sm.Release`
1 parent 398de52 commit c4c6c51

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

gps/manager_test.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,23 @@ func TestSourceManagerInit(t *testing.T) {
121121
t.Fatalf("Global cache lock file not cleared correctly on Release()")
122122
}
123123

124+
err = os.MkdirAll(cpath, 0777)
125+
if err != nil {
126+
t.Errorf("Failed to re-create temp dir: %s", err)
127+
}
128+
defer func() {
129+
err = os.RemoveAll(cpath)
130+
if err != nil {
131+
t.Errorf("removeAll failed: %s", err)
132+
}
133+
}()
124134
// Set another one up at the same spot now, just to be sure
125135
sm, err = NewSourceManager(cfg)
126136
if err != nil {
127-
t.Errorf("Creating a second SourceManager should have succeeded when the first was released, but failed with err %s", err)
137+
t.Fatalf("Creating a second SourceManager should have succeeded when the first was released, but failed with err %s", err)
128138
}
129139

130140
sm.Release()
131-
err = os.RemoveAll(cpath)
132-
if err != nil {
133-
t.Errorf("removeAll failed: %s", err)
134-
}
135141
}
136142

137143
func TestSourceInit(t *testing.T) {

0 commit comments

Comments
 (0)