diff --git a/drivers/java/driver_test.go b/drivers/java/driver_test.go index b4c2c9e40..f54d8c6da 100644 --- a/drivers/java/driver_test.go +++ b/drivers/java/driver_test.go @@ -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) { diff --git a/drivers/shared/executor/executor_test.go b/drivers/shared/executor/executor_test.go index 41b141762..200fb323e 100644 --- a/drivers/shared/executor/executor_test.go +++ b/drivers/shared/executor/executor_test.go @@ -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