Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: added test for TestMergeProcessFileCallBack different content case #1129

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion filesystem/merger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestMergeDeletionCallBack(t *testing.T) {
})
}

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

Expand Down Expand Up @@ -137,4 +137,45 @@ func TestMergeProcessFileCallBack_SameContent(t *testing.T) {
t.Errorf("Destination file content should not be updated")
}
})
t.Run("test for source and destination files with different 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 different content to both files
sourceContent := "source content"
destinationContent := "different content"
_, err = sourceFile.WriteString(sourceContent)
if err != nil {
t.Fatalf("Failed to write to source file: %v", err)
}
_, err = destinationFile.WriteString(destinationContent)
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)
}

// checking for 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) != sourceContent {
t.Errorf("Destination file content should be updated to match the source")
}
})
}
Loading