Skip to content

Commit

Permalink
added test for mergeProcessFileCallBack function
Browse files Browse the repository at this point in the history
Signed-off-by: satyazzz123 <[email protected]>
  • Loading branch information
satyazzz123 committed Dec 13, 2023
1 parent 0bbafac commit 4e0463a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions filesystem/merger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package filesystem
import (
"os"
"testing"
"io/ioutil"
)

func TestMergeDeletionCallBack(t *testing.T) {
Expand Down Expand Up @@ -48,3 +49,46 @@ func TestMergeDeletionCallBack(t *testing.T) {

})
}

func TestMergeProcessFileCallBack_SameContent(t *testing.T) {
t.Run("test for source and destination files with same content", func(t *testing.T) {

sourceFile, err := ioutil.TempFile("", "source")
if err != nil {
t.Fatalf("Failed to create source file: %v", err)
}
defer os.Remove(sourceFile.Name())

destinationFile, err := ioutil.TempFile("", "destination")
if err != nil {
t.Fatalf("Failed to create destination file: %v", err)
}
defer os.Remove(destinationFile.Name())

// Write content to both files
content := "same content"
_, err = sourceFile.WriteString(content)
if err != nil {
t.Fatalf("Failed to write to source file: %v", err)
}
_, err = destinationFile.WriteString(content)
if err != nil {
t.Fatalf("Failed to write to destination file: %v", err)
}


err = mergeProcessFileCallBack(sourceFile.Name(), destinationFile.Name(), false)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}

// Assert that the destination file content is not updated
updatedContent, err := ioutil.ReadFile(destinationFile.Name())
if err != nil {
t.Fatalf("Failed to read destination file: %v", err)
}
if string(updatedContent) != content {
t.Errorf("Destination file content should not be updated")
}
})
}

0 comments on commit 4e0463a

Please sign in to comment.