Skip to content

Commit

Permalink
test: added test for mergeProcessFileCallBack function (#1121)
Browse files Browse the repository at this point in the history
* added test for mergeProcessFileCallBack function

Signed-off-by: satyazzz123 <[email protected]>

* added variable for empty string

Signed-off-by: satyazzz123 <[email protected]>

* added variable for destination

Signed-off-by: satyazzz123 <[email protected]>

---------

Signed-off-by: satyazzz123 <[email protected]>
  • Loading branch information
satyazzz123 authored Dec 14, 2023
1 parent 0bbafac commit 17a115d
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 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,47 @@ 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) {
nonExistentPath := ""

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

destinationFile, err := ioutil.TempFile(nonExistentPath , "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 17a115d

Please sign in to comment.