Merge pull request #8992 from hashicorp/b-tests-failover-copy

tests: failover to copying when symlinking fails
This commit is contained in:
Mahmood Ali 2020-09-30 09:22:24 -05:00 committed by GitHub
commit eb5ff115a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 4 deletions

View file

@ -332,9 +332,6 @@ func copyFile(src, dst string, t *testing.T) {
if _, err = io.Copy(out, in); err != nil {
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
}
if err := out.Sync(); err != nil {
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
}
}
func TestConfig_ParseAllHCL(t *testing.T) {

View file

@ -482,7 +482,29 @@ func setupRootfsBinary(t *testing.T, rootfs, path string) {
)
err = os.Link(src, dst)
require.NoError(t, err)
if err != nil {
// On failure, fallback to copying the file directly.
// Linking may fail if the test source code lives on a separate
// volume/partition from the temp dir used for testing
copyFile(t, src, dst)
}
}
func copyFile(t *testing.T, src, dst string) {
in, err := os.Open(src)
require.NoErrorf(t, err, "copying %v -> %v", src, dst)
defer in.Close()
out, err := os.Create(dst)
require.NoErrorf(t, err, "copying %v -> %v", src, dst)
defer func() {
if err := out.Close(); err != nil {
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
}
}()
_, err = io.Copy(out, in)
require.NoErrorf(t, err, "copying %v -> %v", src, dst)
}
// TestExecutor_Start_Kill_Immediately_NoGrace asserts that executors shutdown