Skip to content

Commit 55a6798

Browse files
authored
Merge pull request #285 from hupfdule/cleanupAfterTest
Cleanup tmp dirs after test
2 parents 885e22b + 90a7db6 commit 55a6798

File tree

7 files changed

+97
-2
lines changed

7 files changed

+97
-2
lines changed

internal/testutil/testutil.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package testutil
22

33
import (
44
"fmt"
5-
"github.com/pkg/errors"
65
"io/ioutil"
76
"os"
87
"os/exec"
@@ -13,6 +12,8 @@ import (
1312
"strings"
1413
"testing"
1514

15+
"github.com/pkg/errors"
16+
1617
"github.com/vim-volt/volt/config"
1718
"github.com/vim-volt/volt/fileutil"
1819
"github.com/vim-volt/volt/lockjson"
@@ -58,6 +59,13 @@ func SetUpEnv(t *testing.T) {
5859
}
5960
}
6061

62+
func CleanUpEnv(t *testing.T) {
63+
for _, env := range []string{"VOLTPATH", "HOME"} {
64+
parent, _ := filepath.Split(os.Getenv(env))
65+
os.RemoveAll(parent)
66+
}
67+
}
68+
6169
func RunVolt(args ...string) ([]byte, error) {
6270
cmd := exec.Command(voltCommand, args...)
6371
// cmd.Env = append(os.Environ(), "VOLTPATH="+voltpath)
@@ -141,6 +149,7 @@ func SetUpRepos(t *testing.T, testdataName string, rType lockjson.ReposType, rep
141149
t.Fatalf("failed to set VOLTPATH: %s", err)
142150
}
143151
defer os.Setenv("HOME", home)
152+
defer os.RemoveAll(home)
144153
if err := os.Setenv("VOLTPATH", tmpVoltpath); err != nil {
145154
t.Fatal("failed to set VOLTPATH")
146155
}

subcmd/build_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func TestVoltBuildT1ProfileVimrcGvimrcExists(t *testing.T) {
6969
// =============== setup =============== //
7070

7171
testutil.SetUpEnv(t)
72+
defer testutil.CleanUpEnv(t)
7273

7374
installProfileRC(t, "default", "vimrc-nomagic.vim", pathutil.ProfileVimrc)
7475
installProfileRC(t, "default", "gvimrc-nomagic.vim", pathutil.ProfileGvimrc)
@@ -93,6 +94,7 @@ func TestVoltBuildT1ProfileVimrcExists(t *testing.T) {
9394
// =============== setup =============== //
9495

9596
testutil.SetUpEnv(t)
97+
defer testutil.CleanUpEnv(t)
9698

9799
installProfileRC(t, "default", "vimrc-nomagic.vim", pathutil.ProfileVimrc)
98100

@@ -116,6 +118,7 @@ func TestVoltBuildT1ProfileGvimrcExists(t *testing.T) {
116118
// =============== setup =============== //
117119

118120
testutil.SetUpEnv(t)
121+
defer testutil.CleanUpEnv(t)
119122

120123
installProfileRC(t, "default", "gvimrc-nomagic.vim", pathutil.ProfileGvimrc)
121124

@@ -139,6 +142,7 @@ func TestVoltBuildT2UserVimrcGvimrcExists(t *testing.T) {
139142
// =============== setup =============== //
140143

141144
testutil.SetUpEnv(t)
145+
defer testutil.CleanUpEnv(t)
142146

143147
installVimRC(t, "vimrc-nomagic.vim", pathutil.Vimrc)
144148
installVimRC(t, "gvimrc-nomagic.vim", pathutil.Gvimrc)
@@ -163,6 +167,7 @@ func TestVoltBuildT2UserVimrcExists(t *testing.T) {
163167
// =============== setup =============== //
164168

165169
testutil.SetUpEnv(t)
170+
defer testutil.CleanUpEnv(t)
166171

167172
installVimRC(t, "vimrc-nomagic.vim", pathutil.Vimrc)
168173

@@ -187,6 +192,7 @@ func TestErrVoltBuildT2CannotOverwriteUserVimrc(t *testing.T) {
187192
// =============== setup =============== //
188193

189194
testutil.SetUpEnv(t)
195+
defer testutil.CleanUpEnv(t)
190196

191197
installProfileRC(t, "default", "vimrc-nomagic.vim", pathutil.ProfileVimrc)
192198
installVimRC(t, "vimrc-nomagic.vim", pathutil.Vimrc)
@@ -212,6 +218,7 @@ func TestErrVoltBuildT2CannotOverwriteUserGvimrc(t *testing.T) {
212218
// =============== setup =============== //
213219

214220
testutil.SetUpEnv(t)
221+
defer testutil.CleanUpEnv(t)
215222

216223
installProfileRC(t, "default", "gvimrc-nomagic.vim", pathutil.ProfileGvimrc)
217224
installVimRC(t, "gvimrc-nomagic.vim", pathutil.Gvimrc)
@@ -237,6 +244,7 @@ func TestErrVoltBuildT2DontInstallVimrc(t *testing.T) {
237244
// =============== setup =============== //
238245

239246
testutil.SetUpEnv(t)
247+
defer testutil.CleanUpEnv(t)
240248

241249
installProfileRC(t, "default", "vimrc-nomagic.vim", pathutil.ProfileVimrc)
242250
installProfileRC(t, "default", "gvimrc-nomagic.vim", pathutil.ProfileGvimrc)
@@ -263,6 +271,7 @@ func TestErrVoltBuildT2DontInstallGvimrc(t *testing.T) {
263271
// =============== setup =============== //
264272

265273
testutil.SetUpEnv(t)
274+
defer testutil.CleanUpEnv(t)
266275

267276
installProfileRC(t, "default", "vimrc-nomagic.vim", pathutil.ProfileVimrc)
268277
installProfileRC(t, "default", "gvimrc-nomagic.vim", pathutil.ProfileGvimrc)
@@ -289,6 +298,7 @@ func TestVoltBuildT2CanInstallUserVimrc(t *testing.T) {
289298
// =============== setup =============== //
290299

291300
testutil.SetUpEnv(t)
301+
defer testutil.CleanUpEnv(t)
292302

293303
installProfileRC(t, "default", "vimrc-nomagic.vim", pathutil.ProfileVimrc)
294304
installVimRC(t, "gvimrc-nomagic.vim", pathutil.Gvimrc)
@@ -314,6 +324,7 @@ func TestVoltBuildT3OverwriteUserVimrcGvimrcByProfileVimrcGvimrc(t *testing.T) {
314324
// =============== setup =============== //
315325

316326
testutil.SetUpEnv(t)
327+
defer testutil.CleanUpEnv(t)
317328

318329
installProfileRC(t, "default", "vimrc-nomagic.vim", pathutil.ProfileVimrc)
319330
installProfileRC(t, "default", "gvimrc-nomagic.vim", pathutil.ProfileGvimrc)
@@ -341,6 +352,7 @@ func TestVoltBuildT3OverwriteUserGvimrcByProfileGvimrc(t *testing.T) {
341352
// =============== setup =============== //
342353

343354
testutil.SetUpEnv(t)
355+
defer testutil.CleanUpEnv(t)
344356

345357
installProfileRC(t, "default", "gvimrc-nomagic.vim", pathutil.ProfileGvimrc)
346358
installVimRC(t, "gvimrc-magic.vim", pathutil.Gvimrc)
@@ -366,6 +378,7 @@ func TestVoltBuildT3OverwriteUserVimrcByProfileVimrc(t *testing.T) {
366378
// =============== setup =============== //
367379

368380
testutil.SetUpEnv(t)
381+
defer testutil.CleanUpEnv(t)
369382

370383
installProfileRC(t, "default", "vimrc-nomagic.vim", pathutil.ProfileVimrc)
371384
installVimRC(t, "vimrc-magic.vim", pathutil.Vimrc)
@@ -391,6 +404,7 @@ func TestVoltBuildT3RemoveUserVimrcGvimrc(t *testing.T) {
391404
// =============== setup =============== //
392405

393406
testutil.SetUpEnv(t)
407+
defer testutil.CleanUpEnv(t)
394408

395409
installVimRC(t, "vimrc-magic.vim", pathutil.Vimrc)
396410
installVimRC(t, "gvimrc-magic.vim", pathutil.Gvimrc)
@@ -416,6 +430,7 @@ func TestVoltBuildT3InstallGvimrcAndRemoveUserVimrc(t *testing.T) {
416430
// =============== setup =============== //
417431

418432
testutil.SetUpEnv(t)
433+
defer testutil.CleanUpEnv(t)
419434

420435
installProfileRC(t, "default", "gvimrc-nomagic.vim", pathutil.ProfileGvimrc)
421436
installVimRC(t, "vimrc-magic.vim", pathutil.Vimrc)
@@ -441,6 +456,7 @@ func TestVoltBuildT3InstallVimrcAndRemoveUserGvimrc(t *testing.T) {
441456
// =============== setup =============== //
442457

443458
testutil.SetUpEnv(t)
459+
defer testutil.CleanUpEnv(t)
444460

445461
installProfileRC(t, "default", "vimrc-nomagic.vim", pathutil.ProfileVimrc)
446462
installVimRC(t, "gvimrc-magic.vim", pathutil.Gvimrc)
@@ -466,6 +482,7 @@ func TestVoltBuildT4NoVimrcGvimrc(t *testing.T) {
466482
// =============== setup =============== //
467483

468484
testutil.SetUpEnv(t)
485+
defer testutil.CleanUpEnv(t)
469486

470487
// =============== run =============== //
471488

@@ -490,6 +507,7 @@ func voltBuildGitNoVimRepos(t *testing.T, full bool, strategy string) {
490507
// =============== setup =============== //
491508

492509
testutil.SetUpEnv(t)
510+
defer testutil.CleanUpEnv(t)
493511
reposPathList := []pathutil.ReposPath{"github.com/tyru/caw.vim"}
494512
teardown := testutil.SetUpRepos(t, "caw.vim", lockjson.ReposGitType, reposPathList, strategy)
495513
defer teardown()
@@ -536,6 +554,7 @@ func voltBuildGitVimDirOlder(t *testing.T, full bool, strategy string) {
536554
// =============== setup =============== //
537555

538556
testutil.SetUpEnv(t)
557+
defer testutil.CleanUpEnv(t)
539558
reposPathList := []pathutil.ReposPath{"github.com/tyru/caw.vim"}
540559
teardown := testutil.SetUpRepos(t, "caw.vim", lockjson.ReposGitType, reposPathList, strategy)
541560
defer teardown()
@@ -587,6 +606,7 @@ func voltBuildGitVimDirNewer(t *testing.T, full bool, strategy string) {
587606
// =============== setup =============== //
588607

589608
testutil.SetUpEnv(t)
609+
defer testutil.CleanUpEnv(t)
590610
reposPathList := []pathutil.ReposPath{"github.com/tyru/caw.vim"}
591611
teardown := testutil.SetUpRepos(t, "caw.vim", lockjson.ReposGitType, reposPathList, strategy)
592612
defer teardown()
@@ -639,6 +659,7 @@ func voltBuildStaticNoVimRepos(t *testing.T, full bool, strategy string) {
639659
// =============== setup =============== //
640660

641661
testutil.SetUpEnv(t)
662+
defer testutil.CleanUpEnv(t)
642663
reposPathList := []pathutil.ReposPath{"localhost/local/hello"}
643664
teardown := testutil.SetUpRepos(t, "hello", lockjson.ReposStaticType, reposPathList, strategy)
644665
defer teardown()
@@ -685,6 +706,7 @@ func voltBuildStaticVimDirOlder(t *testing.T, full bool, strategy string) {
685706
// =============== setup =============== //
686707

687708
testutil.SetUpEnv(t)
709+
defer testutil.CleanUpEnv(t)
688710
reposPathList := []pathutil.ReposPath{"localhost/local/hello"}
689711
teardown := testutil.SetUpRepos(t, "hello", lockjson.ReposStaticType, reposPathList, strategy)
690712
defer teardown()
@@ -736,6 +758,7 @@ func voltBuildStaticVimDirNewer(t *testing.T, full bool, strategy string) {
736758
// =============== setup =============== //
737759

738760
testutil.SetUpEnv(t)
761+
defer testutil.CleanUpEnv(t)
739762
reposPathList := []pathutil.ReposPath{"localhost/local/hello"}
740763
teardown := testutil.SetUpRepos(t, "hello", lockjson.ReposStaticType, reposPathList, strategy)
741764
defer teardown()

subcmd/get_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package subcmd
33
import (
44
"bytes"
55
"fmt"
6-
"github.com/pkg/errors"
76
"io/ioutil"
87
"path/filepath"
98
"strings"
109
"testing"
1110
"time"
1211

12+
"github.com/pkg/errors"
13+
1314
"github.com/vim-volt/volt/internal/testutil"
1415
"github.com/vim-volt/volt/lockjson"
1516
"github.com/vim-volt/volt/pathutil"
@@ -54,6 +55,7 @@ func TestVoltGetOnePlugin(t *testing.T) {
5455
// =============== setup =============== //
5556

5657
testutil.SetUpEnv(t)
58+
defer testutil.CleanUpEnv(t)
5759
testutil.InstallConfig(t, "strategy-"+strategy+".toml")
5860

5961
// =============== run =============== //
@@ -111,6 +113,7 @@ func TestVoltGetMsg(t *testing.T) {
111113
// =============== setup =============== //
112114

113115
testutil.SetUpEnv(t)
116+
defer testutil.CleanUpEnv(t)
114117
testutil.InstallConfig(t, "strategy-"+strategy+".toml")
115118
reposPath := pathutil.ReposPath("github.com/tyru/caw.vim")
116119

@@ -314,6 +317,7 @@ func TestVoltGetTwoOrMorePlugin(t *testing.T) {
314317
// =============== setup =============== //
315318

316319
testutil.SetUpEnv(t)
320+
defer testutil.CleanUpEnv(t)
317321
testutil.InstallConfig(t, "strategy-"+strategy+".toml")
318322

319323
// =============== run =============== //
@@ -378,6 +382,7 @@ func TestVoltGetLoptMustNotAddDisabledPlugins(t *testing.T) {
378382
// =============== setup =============== //
379383

380384
testutil.SetUpEnv(t)
385+
defer testutil.CleanUpEnv(t)
381386

382387
// =============== run =============== //
383388

@@ -408,6 +413,7 @@ func TestErrVoltGetInvalidArgs(t *testing.T) {
408413
// =============== setup =============== //
409414

410415
testutil.SetUpEnv(t)
416+
defer testutil.CleanUpEnv(t)
411417

412418
// =============== run =============== //
413419

@@ -453,6 +459,7 @@ func TestErrVoltGetNotFound(t *testing.T) {
453459
// =============== setup =============== //
454460

455461
testutil.SetUpEnv(t)
462+
defer testutil.CleanUpEnv(t)
456463

457464
// =============== run =============== //
458465

subcmd/help_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func TestVoltHelpDiffOutput(t *testing.T) {
1212
// =============== setup =============== //
1313

1414
testutil.SetUpEnv(t)
15+
defer testutil.CleanUpEnv(t)
1516

1617
// =============== run =============== //
1718

@@ -35,6 +36,7 @@ func TestErrVoltHelpNonExistingCmd(t *testing.T) {
3536
// =============== setup =============== //
3637

3738
testutil.SetUpEnv(t)
39+
defer testutil.CleanUpEnv(t)
3840

3941
// =============== run =============== //
4042

@@ -50,6 +52,7 @@ func TestVoltHelpE478(t *testing.T) {
5052
// =============== setup =============== //
5153

5254
testutil.SetUpEnv(t)
55+
defer testutil.CleanUpEnv(t)
5356

5457
// =============== run =============== //
5558

subcmd/list_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func TestVoltListAndVoltProfileAreSame(t *testing.T) {
1818
// =============== setup =============== //
1919

2020
testutil.SetUpEnv(t)
21+
defer testutil.CleanUpEnv(t)
2122

2223
// =============== run =============== //
2324

@@ -43,6 +44,7 @@ func TestVoltListFunctions(t *testing.T) {
4344
// =============== setup =============== //
4445

4546
testutil.SetUpEnv(t)
47+
defer testutil.CleanUpEnv(t)
4648

4749
// =============== run =============== //
4850

@@ -60,6 +62,7 @@ func TestVoltListFunctions(t *testing.T) {
6062
// =============== setup =============== //
6163

6264
testutil.SetUpEnv(t)
65+
defer testutil.CleanUpEnv(t)
6366

6467
// =============== run =============== //
6568

@@ -81,6 +84,7 @@ func TestVoltListFunctions(t *testing.T) {
8184
// =============== setup =============== //
8285

8386
testutil.SetUpEnv(t)
87+
defer testutil.CleanUpEnv(t)
8488

8589
// =============== run =============== //
8690

@@ -98,6 +102,7 @@ func TestVoltListFunctions(t *testing.T) {
98102
// =============== setup =============== //
99103

100104
testutil.SetUpEnv(t)
105+
defer testutil.CleanUpEnv(t)
101106

102107
// =============== run =============== //
103108

@@ -115,6 +120,7 @@ func TestVoltListFunctions(t *testing.T) {
115120
// =============== setup =============== //
116121

117122
testutil.SetUpEnv(t)
123+
defer testutil.CleanUpEnv(t)
118124

119125
// =============== run =============== //
120126

@@ -133,6 +139,7 @@ func TestVoltListFunctions(t *testing.T) {
133139
// =============== setup =============== //
134140

135141
testutil.SetUpEnv(t)
142+
defer testutil.CleanUpEnv(t)
136143

137144
// =============== run =============== //
138145

@@ -151,6 +158,7 @@ func TestVoltListFunctions(t *testing.T) {
151158
// =============== setup =============== //
152159

153160
testutil.SetUpEnv(t)
161+
defer testutil.CleanUpEnv(t)
154162

155163
// =============== run =============== //
156164

0 commit comments

Comments
 (0)