diff --git a/tools/integration_tests/gzip/read_gzip_test.go b/tools/integration_tests/gzip/read_gzip_test.go index 1da9b4127c..433803ee0e 100644 --- a/tools/integration_tests/gzip/read_gzip_test.go +++ b/tools/integration_tests/gzip/read_gzip_test.go @@ -56,8 +56,8 @@ func verifyFileSizeAndFullFileRead(t *testing.T, filename string) { defer operations.RemoveFile(localCopy) - diff, err := operations.DiffFiles(localCopy, mountedFilePath) - if diff != 0 { + diff, err := operations.AreFilesIdentical(localCopy, mountedFilePath) + if !diff { t.Fatalf("Tempfile (%s, download of GCS object %s) didn't match the Mounted local file (%s): %v", localCopy, gcsObjectPath, mountedFilePath, err) } } diff --git a/tools/integration_tests/util/operations/file_operations.go b/tools/integration_tests/util/operations/file_operations.go index 24562150a1..1521a973f0 100644 --- a/tools/integration_tests/util/operations/file_operations.go +++ b/tools/integration_tests/util/operations/file_operations.go @@ -315,44 +315,43 @@ func StatFile(file string) (*fs.FileInfo, error) { // If sizes match, then compares the contents of both the files. // Not a good idea for very large files as it loads both the files' contents in // the memory completely. -// Returns 0 if no error and files match. -// Returns 1 if files don't match and captures reason for mismatch in err. -// Returns 2 if any error. -func DiffFiles(filepath1, filepath2 string) (int, error) { +// Returns true if no error and files match. +// Returns false if files don't match (captures reason for mismatch in err) or if any other error. +func AreFilesIdentical(filepath1, filepath2 string) (bool, error) { if filepath1 == "" || filepath2 == "" { - return 2, fmt.Errorf("one or both files being diff'ed have empty path") + return false, fmt.Errorf("one or both files being diff'ed have empty path") } else if filepath1 == filepath2 { - return 0, nil + return true, nil } fstat1, err := StatFile(filepath1) if err != nil { - return 2, err + return false, err } fstat2, err := StatFile(filepath2) if err != nil { - return 2, err + return false, err } file1size := (*fstat1).Size() file2size := (*fstat2).Size() if file1size != file2size { - return 1, fmt.Errorf("files don't match in size: %s (%d bytes), %s (%d bytes)", filepath1, file1size, filepath2, file2size) + return false, fmt.Errorf("files don't match in size: %s (%d bytes), %s (%d bytes)", filepath1, file1size, filepath2, file2size) } if file1size == 0 { - return 0, nil + return true, nil } f1, err := os.OpenFile(filepath1, os.O_RDONLY|syscall.O_DIRECT, FilePermission_0400) if err != nil { - return 2, fmt.Errorf("failed to read file %s: %v", filepath1, err) + return false, fmt.Errorf("failed to read file %s: %v", filepath1, err) } f2, err := os.OpenFile(filepath2, os.O_RDONLY|syscall.O_DIRECT, FilePermission_0400) if err != nil { - return 2, fmt.Errorf("failed to read file %s: %v", filepath2, err) + return false, fmt.Errorf("failed to read file %s: %v", filepath2, err) } sizeRemaining := int(file1size) @@ -368,26 +367,26 @@ func DiffFiles(filepath1, filepath2 string) (int, error) { numBytesRead1, err := f1.Read(b1) if err != nil { - return 2, fmt.Errorf("failed to read file %s: %v", filepath1, err) + return false, fmt.Errorf("failed to read file %s: %v", filepath1, err) } else if numBytesRead1 != numBytesBeingRead { - return 2, fmt.Errorf("failed to read file %s, expected read bytes = %d, actual read bytes = %d", filepath1, numBytesBeingRead, numBytesRead1) + return false, fmt.Errorf("failed to read file %s, expected read bytes = %d, actual read bytes = %d", filepath1, numBytesBeingRead, numBytesRead1) } numBytesRead2, err := f2.Read(b2) if err != nil { - return 2, fmt.Errorf("failed to read file %s", filepath2) + return false, fmt.Errorf("failed to read file %s", filepath2) } else if numBytesRead2 != numBytesBeingRead { - return 2, fmt.Errorf("failed to read file %s, expected read bytes = %d, actual read bytes = %d", filepath2, numBytesBeingRead, numBytesRead2) + return false, fmt.Errorf("failed to read file %s, expected read bytes = %d, actual read bytes = %d", filepath2, numBytesBeingRead, numBytesRead2) } if !bytes.Equal(b1[:numBytesBeingRead], b2[:numBytesBeingRead]) { - return 1, fmt.Errorf("files don't match in content: %s, %s", filepath1, filepath2) + return false, fmt.Errorf("files don't match in content: %s, %s", filepath1, filepath2) } sizeRemaining -= numBytesBeingRead } - return 0, nil + return true, nil } // Returns size of a give GCS object with path (without 'gs://'). diff --git a/tools/integration_tests/write_large_files/write_large_files_test.go b/tools/integration_tests/write_large_files/write_large_files_test.go index 6dc3a83099..1be548e263 100644 --- a/tools/integration_tests/write_large_files/write_large_files_test.go +++ b/tools/integration_tests/write_large_files/write_large_files_test.go @@ -43,8 +43,8 @@ func compareFileFromGCSBucketAndMntDir(gcsFile, mntDirFile, localFilePathToDownl // DiffFiles loads the entire files into memory. These are both 500 MiB files, hence would have a 1 GiB // requirement just for this step - diff, err := operations.DiffFiles(mntDirFile, localFilePathToDownloadGcsFile) - if diff != 0 { + diff, err := operations.AreFilesIdentical(mntDirFile, localFilePathToDownloadGcsFile) + if !diff { err = fmt.Errorf("Download of GCS object %s didn't match the Mounted local file (%s): %v", localFilePathToDownloadGcsFile, mntDirFile, err) return }