Make "delete temp dir" condition explicit

Previously we checked if the test had failed -- but the call to
`assert.NoError` that actually fails the test sometimes hasn't happened yet.
This commit is contained in:
Matthew Riley 2018-01-09 23:25:49 -08:00
parent d688910360
commit 047a6c3c56

View file

@ -304,17 +304,18 @@ func testLifeCycleInitAndDestroy(
return errors.Wrap(err, "Couldn't copy test to temporary directory")
}
// Keep the temporary test directory around for debugging unless
// the test completes successfully.
keepTestDir := true
defer func() {
if t.Failed() {
// Test failed -- keep temporary files around for debugging.
// Maybe also copy to "failed tests" directory.
if keepTestDir {
// Maybe copy to "failed tests" directory.
failedTestsDir := os.Getenv("PULUMI_FAILED_TESTS_DIR")
if failedTestsDir != "" {
dest := filepath.Join(failedTestsDir, t.Name()+uniqueSuffix())
contract.IgnoreError(fsutil.CopyFile(dest, dir, nil))
}
} else {
// Test passed -- delete temporary files.
contract.IgnoreError(os.RemoveAll(dir))
}
}()
@ -332,7 +333,13 @@ func testLifeCycleInitAndDestroy(
}
}()
return between(t, opts, dir)
err = between(t, opts, dir)
if err != nil {
return err
}
keepTestDir = false
return nil
}
func testLifeCycleInitialize(t *testing.T, opts *ProgramTestOptions, dir string) error {