From d9160b9bf7615a581cb7765fa8d4e9abe834ed88 Mon Sep 17 00:00:00 2001 From: Cian Gallagher Date: Sun, 23 Jan 2022 18:13:48 +0000 Subject: [PATCH] EVENT: Add test case for file removal after successful copy. --- event/event_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/event/event_test.go b/event/event_test.go index 97e3960..ca37578 100644 --- a/event/event_test.go +++ b/event/event_test.go @@ -49,6 +49,11 @@ func TestEvent(t *testing.T) { if _, err := os.Stat(fmt.Sprintf("%s/%s", event.Destination, event.File)); errors.Is(err, os.ErrNotExist) { t.Fatalf("Failed to move from %s/%s to %s/%s: %v : %v", event.Path, event.File, event.Destination, event.File, err, *event) } + + // If the file still exists in the source directory, log an error + if _, err := os.Stat(fmt.Sprintf("%s/%s", event.Path, event.File)); !errors.Is(err, os.ErrNotExist) { + t.Fatalf("Failed to delete file from %s/%s to %s/%s after Move: %v : %v", event.Path, event.File, event.Destination, event.File, err, *event) + } }) t.Run("It moves file from one dir to another dir with valid destPath", func(t *testing.T) { @@ -59,6 +64,11 @@ func TestEvent(t *testing.T) { if _, err := os.Stat(fmt.Sprintf("%s/%s", event.Destination, event.File)); errors.Is(err, os.ErrNotExist) { t.Fatalf("Failed to move from %s/%s to %s/%s: %v : %v", event.Path, event.File, event.Destination, event.File, err, *event) } + + // If the file still exists in the source directory, log an error + if _, err := os.Stat(fmt.Sprintf("%s/%s", event.Path, event.File)); !errors.Is(err, os.ErrNotExist) { + t.Fatalf("Failed to delete file from %s/%s to %s/%s after Move: %v : %v", event.Path, event.File, event.Destination, event.File, err, *event) + } }) t.Run("It does not move file from one dir to another dir", func(t *testing.T) {