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:
parent
9ccd07714a
commit
2669f65b39
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -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/
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue