Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion internal/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package testutil

import (
"fmt"
"github.com/pkg/errors"
"io/ioutil"
"os"
"os/exec"
Expand All @@ -13,6 +12,8 @@ import (
"strings"
"testing"

"github.com/pkg/errors"

"github.com/vim-volt/volt/config"
"github.com/vim-volt/volt/fileutil"
"github.com/vim-volt/volt/lockjson"
Expand Down Expand Up @@ -58,6 +59,13 @@ func SetUpEnv(t *testing.T) {
}
}

func CleanUpEnv(t *testing.T) {
for _, env := range []string{"VOLTPATH", "HOME"} {
parent, _ := filepath.Split(os.Getenv(env))
os.RemoveAll(parent)
}
}

func RunVolt(args ...string) ([]byte, error) {
cmd := exec.Command(voltCommand, args...)
// cmd.Env = append(os.Environ(), "VOLTPATH="+voltpath)
Expand Down Expand Up @@ -141,6 +149,7 @@ func SetUpRepos(t *testing.T, testdataName string, rType lockjson.ReposType, rep
t.Fatalf("failed to set VOLTPATH: %s", err)
}
defer os.Setenv("HOME", home)
defer os.RemoveAll(home)
if err := os.Setenv("VOLTPATH", tmpVoltpath); err != nil {
t.Fatal("failed to set VOLTPATH")
}
Expand Down
23 changes: 23 additions & 0 deletions subcmd/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func TestVoltBuildT1ProfileVimrcGvimrcExists(t *testing.T) {
// =============== setup =============== //

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

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

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

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

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

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

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

// =============== run =============== //

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

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

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

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

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

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)
reposPathList := []pathutil.ReposPath{"localhost/local/hello"}
teardown := testutil.SetUpRepos(t, "hello", lockjson.ReposStaticType, reposPathList, strategy)
defer teardown()
Expand Down
9 changes: 8 additions & 1 deletion subcmd/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package subcmd
import (
"bytes"
"fmt"
"github.com/pkg/errors"
"io/ioutil"
"path/filepath"
"strings"
"testing"
"time"

"github.com/pkg/errors"

"github.com/vim-volt/volt/internal/testutil"
"github.com/vim-volt/volt/lockjson"
"github.com/vim-volt/volt/pathutil"
Expand Down Expand Up @@ -54,6 +55,7 @@ func TestVoltGetOnePlugin(t *testing.T) {
// =============== setup =============== //

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)
testutil.InstallConfig(t, "strategy-"+strategy+".toml")

// =============== run =============== //
Expand Down Expand Up @@ -111,6 +113,7 @@ func TestVoltGetMsg(t *testing.T) {
// =============== setup =============== //

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

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)
testutil.InstallConfig(t, "strategy-"+strategy+".toml")

// =============== run =============== //
Expand Down Expand Up @@ -378,6 +382,7 @@ func TestVoltGetLoptMustNotAddDisabledPlugins(t *testing.T) {
// =============== setup =============== //

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

// =============== run =============== //

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

// =============== run =============== //

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

// =============== run =============== //

Expand Down
3 changes: 3 additions & 0 deletions subcmd/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func TestVoltHelpDiffOutput(t *testing.T) {
// =============== setup =============== //

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

// =============== run =============== //

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

// =============== run =============== //

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

// =============== run =============== //

Expand Down
8 changes: 8 additions & 0 deletions subcmd/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestVoltListAndVoltProfileAreSame(t *testing.T) {
// =============== setup =============== //

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

// =============== run =============== //

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

// =============== run =============== //

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

// =============== run =============== //

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

// =============== run =============== //

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

// =============== run =============== //

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

// =============== run =============== //

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

// =============== run =============== //

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

testutil.SetUpEnv(t)
defer testutil.CleanUpEnv(t)

// =============== run =============== //

Expand Down
Loading