From 947ea78a69873ac8fa350a2016a0355f63daf153 Mon Sep 17 00:00:00 2001 From: Lenni Date: Sun, 10 Oct 2021 11:10:28 +0200 Subject: [PATCH] added a test for cloning a single file --- full_test/duplicate_renaming_test.go | 41 ++++++++++++++++++++++++++++ full_test/util_test.go | 13 ++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 full_test/duplicate_renaming_test.go diff --git a/full_test/duplicate_renaming_test.go b/full_test/duplicate_renaming_test.go new file mode 100644 index 0000000..a69c470 --- /dev/null +++ b/full_test/duplicate_renaming_test.go @@ -0,0 +1,41 @@ +package full_test + +import ( + "easy-copy/fs" + "testing" +) + +func TestDuplicateRenaming(t *testing.T) { + is := fs.CreateFS([]string{ + "foo/a", + "bar/", + }) + + should := fs.CreateFS([]string{ + "foo/a", + "bar/b", + }) + + t.Log("before copying:") + for _, v := range is.Tree() { + t.Log(v) + } + + line := "cp foo/a bar/b --debug" + + test := NewTest(line) + test.is = is + test.should = should + + test.Run(t) + + t.Log("after copying:") + for _, v := range is.Tree() { + t.Log(v) + } + + ok, badpath := is.Equal(should) + if !ok { + t.Error("fs differs:", badpath) + } +} diff --git a/full_test/util_test.go b/full_test/util_test.go index efd8be7..2002e00 100644 --- a/full_test/util_test.go +++ b/full_test/util_test.go @@ -22,11 +22,22 @@ func NewTest(line string) *TestSetup { return &TestSetup{line: line} } +func reset() { + progress.IteratorDone = false + progress.CopyDone = false + progress.DoneAmount = 0 + progress.FullAmount = 0 + progress.DoneSize = 0 + progress.FullSize = 0 +} + // Run runs the software with the arguments in t.line. // It fails if a warning occurs. func (test *TestSetup) Run(t *testing.T) { t.Helper() + reset() + go func() { for !progress.CopyDone { select { @@ -46,6 +57,6 @@ func (test *TestSetup) Run(t *testing.T) { test.is.Rewind() iterator.Iterate() - tasks.PrintTasks() + t.Log(" -- Starting loop -- ") tasks.CopyLoop() }