-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor out consent test file helper functions into testutils
- Loading branch information
Showing
3 changed files
with
71 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// TiCS: disabled // Test helpers. | ||
|
||
package testutils | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// CleanupDir removes the temporary directory including its contents. | ||
func CleanupDir(t *testing.T, dir string) { | ||
t.Helper() | ||
assert.NoError(t, os.RemoveAll(dir), "Cleanup: failed to remove temporary directory") | ||
} | ||
|
||
// CopyFile copies a file from source to destination. | ||
func CopyFile(src, dst string) error { | ||
sourceFile, err := os.Open(src) | ||
if err != nil { | ||
return err | ||
} | ||
defer sourceFile.Close() | ||
|
||
destinationFile, err := os.Create(dst) | ||
if err != nil { | ||
return err | ||
} | ||
defer destinationFile.Close() | ||
|
||
_, err = io.Copy(destinationFile, sourceFile) | ||
return err | ||
} | ||
|
||
// CopyDir copies the contents of a directory to another directory. | ||
func CopyDir(srcDir, dstDir string) error { | ||
return filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
relPath, err := filepath.Rel(srcDir, path) | ||
if err != nil { | ||
return err | ||
} | ||
dstPath := filepath.Join(dstDir, relPath) | ||
if info.IsDir() { | ||
return os.MkdirAll(dstPath, info.Mode()) | ||
} | ||
return CopyFile(path, dstPath) | ||
}) | ||
} |