Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Add unit test for copyDir and copyFile
Browse files Browse the repository at this point in the history
  • Loading branch information
MonicaisHer committed Jun 17, 2022
1 parent 0323bcd commit 5c24ded
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,28 @@ func getConfigValue(t *testing.T, key string) string {
require.NoError(t, err, "Error getting config value via snapctl.")
return strings.TrimSpace(string(out))
}

func TestCopyFile(t *testing.T) {
tmpdir := t.TempDir()
tmpfile, _ := os.CreateTemp(tmpdir, "tmpSrcFile")
srcPath := tmpfile.Name()

tmpdir = t.TempDir()
tmpfile, _ = os.CreateTemp(tmpdir, "tmpDstFile")
dstPath := tmpfile.Name()

require.NoError(t, CopyFile(srcPath, dstPath), "Error copying file.")
}

func TestCopyDir(t *testing.T) {
tmpdir := t.TempDir()
tmpSrcDir, _ := os.MkdirTemp(tmpdir, "tmpSrcDir")
os.CreateTemp(tmpSrcDir, "tmpSrcFile1")
os.CreateTemp(tmpSrcDir, "tmpSrcFile2")
os.CreateTemp(tmpSrcDir, "tmpSrcFile3")

tmpdir = t.TempDir()
tmpDstDir, _ := os.MkdirTemp(tmpdir, "tmpDstDir")

require.NoError(t, CopyDir(tmpSrcDir, tmpDstDir), "Error copying directory.")
}

0 comments on commit 5c24ded

Please sign in to comment.