Skip to content

Commit

Permalink
EVENT: Update Move() to take additional file arg.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cian911 committed Dec 28, 2021
1 parent 4c8d669 commit 93baf23
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func New(file, path, dest, ext string) *Event {
}

// Move moves the file to the destination
func (e *Event) Move(path string) error {
func (e *Event) Move(path, file string) error {
log.Printf("Moving e.Path: %s to %s/%s\n", path, e.Destination, e.File)

err := os.Rename(path, fmt.Sprintf("%s/%s", e.Destination, e.File))
err := os.Rename(fmt.Sprintf("%s%s", path, file), fmt.Sprintf("%s/%s", e.Destination, e.File))
return err
}

Expand Down
4 changes: 2 additions & 2 deletions event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestEvent(t *testing.T) {

t.Run("It moves file from one dir to another dir", func(t *testing.T) {
event := eventSetup(t)
event.Move(event.Path)
event.Move(event.Path, "")

// If the file does not exist, log an error
if _, err := os.Stat(fmt.Sprintf("%s/%s", event.Destination, event.File)); errors.Is(err, os.ErrNotExist) {
Expand All @@ -54,7 +54,7 @@ func TestEvent(t *testing.T) {
t.Run("It does not move file from one dir to another dir", func(t *testing.T) {
event := eventSetup(t)
event.Destination = "/abcdefg"
err := event.Move(event.Path)
err := event.Move(event.Path, "")

if err == nil {
log.Fatal("event.Move() should have thrown error but didn't.")
Expand Down

0 comments on commit 93baf23

Please sign in to comment.