Skip to content

Commit

Permalink
added checks for destinatioDir and file contents
Browse files Browse the repository at this point in the history
Signed-off-by: satyazzz123 <beherasatyajit716@gmail.com>
  • Loading branch information
satyazzz123 committed Jan 8, 2024
1 parent e248d66 commit f54d902
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions filesystem/delta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,43 @@ func TestGenerateDelta(t *testing.T) {
t.Run("This test scenario covers the creation of source and destination directory and successful execution of function", func(t *testing.T) {
sourceDir, err := ioutil.TempDir("", "source")
if err != nil {
t.Fatal(err)
t.Fatalf("failed to create source directory")
}
defer os.RemoveAll(sourceDir)

destinationDir, err := ioutil.TempDir("", "destination")
if err != nil {
t.Fatal(err)
t.Fatalf("failed to create destination directory")
}
defer os.RemoveAll(destinationDir)

storeDir, err := ioutil.TempDir("", "store")
if err != nil {
t.Fatal(err)
t.Fatalf("failed to create store directory")
}
defer os.RemoveAll(storeDir)

// Add a file to the source directory that isn't in the destination
sourceOnlyFile := filepath.Join(sourceDir, "source_only.txt")
if err := ioutil.WriteFile(sourceOnlyFile, []byte("source only"), 0644); err != nil {
t.Fatal(err)
t.Fatalf("Failed to add to source only file: %v", err)
}

// Add a file to both directories and then modify it in the source
commonFile := "common.txt"
sourceCommonFilePath := filepath.Join(sourceDir, commonFile)
destCommonFilePath := filepath.Join(destinationDir, commonFile)
if err := ioutil.WriteFile(sourceCommonFilePath, []byte("original"), 0644); err != nil {
t.Fatal(err)
t.Fatalf("Failed to write original content to source common file: %v", err)

}
if err := ioutil.WriteFile(destCommonFilePath, []byte("original"), 0644); err != nil {
t.Fatal(err)
t.Fatalf("Failed to write original content to destinatio common file: %v", err)

}
if err := ioutil.WriteFile(sourceCommonFilePath, []byte("modified"), 0644); err != nil {
t.Fatal(err)
t.Fatalf("Failed to modify common file in source directory: %v", err)

}

// Call GenerateDelta
Expand All @@ -74,7 +77,7 @@ func TestGenerateDelta(t *testing.T) {
expectedFiles := []string{commonFile}
files, err := ioutil.ReadDir(destinationDir)
if err != nil {
t.Fatal(err)
t.Errorf("destination directory contents mismatch. got: %v, want: %v", destFiles, expectedFiles)

Check failure on line 80 in filesystem/delta_test.go

View workflow job for this annotation

GitHub Actions / Build and test

undefined: destFiles
}

var destFiles []string
Expand Down

0 comments on commit f54d902

Please sign in to comment.