From 17a115dbba4916cf8b92e01cb6121f81be2f3559 Mon Sep 17 00:00:00 2001 From: Satyajit Behera <105061492+satyazzz123@users.noreply.github.com> Date: Thu, 14 Dec 2023 15:43:18 +0530 Subject: [PATCH] test: added test for mergeProcessFileCallBack function (#1121) * added test for mergeProcessFileCallBack function Signed-off-by: satyazzz123 * added variable for empty string Signed-off-by: satyazzz123 * added variable for destination Signed-off-by: satyazzz123 --------- Signed-off-by: satyazzz123 --- filesystem/merger_test.go | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/filesystem/merger_test.go b/filesystem/merger_test.go index 4fca04845..097b1a253 100644 --- a/filesystem/merger_test.go +++ b/filesystem/merger_test.go @@ -18,6 +18,7 @@ package filesystem import ( "os" "testing" + "io/ioutil" ) func TestMergeDeletionCallBack(t *testing.T) { @@ -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") + } + }) +} \ No newline at end of file