Don't dirty work tree when running tests

Because we run our golang integration tests "in tree" (due to
the need to be under $GOPATH and have a vendor folder around), the
"command-output" folder was getting left behind, dirtying the worktree
after building.

This change does two things:

1. On a succecssful run, remove the folder.
2. Ignore the folder via .gitignore (this way if a test fails and you
do `git add .` you don't end up commiting this folder).
This commit is contained in:
Matt Ellis 2018-06-14 15:58:37 -07:00
parent 9ccd07714a
commit 2669f65b39
4 changed files with 20 additions and 9 deletions

6
.gitignore vendored
View file

@ -3,7 +3,7 @@
**/.vscode/
coverage.cov
*.coverprofile
custom_node/
# Too much awesome to store in Git.
.pulumi
# Go tests run "in tree" and this folder will linger if they fail (the integration test framework cleans
# it up when they pass.)
**/command-output/

View file

@ -474,8 +474,8 @@ func (pt *programTester) testLifeCycleInitAndDestroy() error {
}
testFinished := false
if tmpdir != "" {
defer func() {
defer func() {
if tmpdir != "" {
if !testFinished || pt.t.Failed() {
// Test aborted or failed. Maybe copy to "failed tests" directory.
failedTestsDir := os.Getenv("PULUMI_FAILED_TESTS_DIR")
@ -486,8 +486,15 @@ func (pt *programTester) testLifeCycleInitAndDestroy() error {
} else {
contract.IgnoreError(os.RemoveAll(tmpdir))
}
}()
}
} else {
// When tmpdir is empty, we ran "in tree", which means we wrote output
// to the "command-output" folder in the projdir, and we should clean
// it up if the test passed
if testFinished && !pt.t.Failed() {
contract.IgnoreError(os.RemoveAll(filepath.Join(projdir, commandOutputFolderName)))
}
}
}()
err = pt.testLifeCycleInitialize(projdir)
if err != nil {

View file

@ -58,7 +58,7 @@ func TestRunCommandLog(t *testing.T) {
err = RunCommand(nil, "node", args, tempdir, opts)
assert.Nil(t, err)
matches, err := filepath.Glob(filepath.Join(tempdir, "command-output", "node.*"))
matches, err := filepath.Glob(filepath.Join(tempdir, commandOutputFolderName, "node.*"))
assert.Nil(t, err)
assert.Equal(t, 1, len(matches))

View file

@ -64,8 +64,12 @@ func uniqueSuffix() string {
return suffix
}
const (
commandOutputFolderName = "command-output"
)
func writeCommandOutput(commandName, runDir string, output []byte) (string, error) {
logFileDir := filepath.Join(runDir, "command-output")
logFileDir := filepath.Join(runDir, commandOutputFolderName)
if err := os.MkdirAll(logFileDir, 0700); err != nil {
return "", errors.Wrapf(err, "Failed to create '%s'", logFileDir)
}