Skip to content

Commit

Permalink
test: add test for replicateAdditionCallback
Browse files Browse the repository at this point in the history
Signed-off-by: prakharagarwal1 <[email protected]>
  • Loading branch information
Prakhar-Agarwal-byte committed Aug 8, 2023
1 parent 11cfea1 commit 00ab810
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions filesystem/replicator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,33 @@ import (
}
})
}

func TestReplicateAdditionCallBack(t *testing.T) {
t.Run("test for destination dir is removed", func(t *testing.T) {
sourceDir := "test_data/replicator_test/source"
destinationDir := "test_data/replicator_test/destination"
destinationFilePath := destinationDir + "/existing-file.txt"
// Prepare the destination directory with an existing file
err := os.MkdirAll(destinationDir, 0755)
if err != nil {
t.Fatal(err)
}
_, err = os.Create(destinationFilePath)
if err != nil {
t.Fatal(err)
}

// Call the addition callback
err = replicateAdditionCallBack(sourceDir, destinationDir, nil)
if err != nil {
t.Fatalf("Expected no error, got %s", err)
}

// Check if the destination directory is removed
_, err = os.Stat(destinationDir)
if err == nil {
t.Error("Expected destination directory to be removed, but it still exists")
}
})
}

1 change: 1 addition & 0 deletions filesystem/test_data/replicator_test/source/file1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is file1

0 comments on commit 00ab810

Please sign in to comment.