Skip to content

Commit

Permalink
Merge pull request #8992 from hashicorp/b-tests-failover-copy
Browse files Browse the repository at this point in the history
tests: failover to copying when symlinking fails
  • Loading branch information
Mahmood Ali authored Sep 30, 2020
2 parents 5621407 + 6e9edd5 commit 235f938
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
3 changes: 0 additions & 3 deletions drivers/java/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 23 additions & 1 deletion drivers/shared/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 235f938

Please sign in to comment.