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

Handle the error variables and filehandles properly across all integration tests #1197

Merged
Merged
Show file tree
Hide file tree
Changes from 23 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
6 changes: 3 additions & 3 deletions tools/integration_tests/explicit_dir/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import (
)

func TestListOnlyExplicitObjectsFromBucket(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

// Directory Structure
// testBucket/implicitDirectory -- Dir
// testBucket/implicitDirectory/fileInImplicitDir1 -- File
Expand All @@ -40,9 +43,6 @@ func TestListOnlyExplicitObjectsFromBucket(t *testing.T) {
implicit_and_explicit_dir_setup.CreateImplicitDirectory()
implicit_and_explicit_dir_setup.CreateExplicitDirectory(t)

// Delete objects from bucket after testing.
defer os.RemoveAll(setup.MntDir())

err := filepath.WalkDir(setup.MntDir(), func(path string, dir fs.DirEntry, err error) error {
if err != nil {
fmt.Printf("prevent panic by handling failure accessing a path %q: %v\n", path, err)
Expand Down
6 changes: 3 additions & 3 deletions tools/integration_tests/implicit_dir/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import (
)

func TestListImplicitObjectsFromBucket(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

// Directory Structure
// testBucket/implicitDirectory -- Dir
// testBucket/implicitDirectory/fileInImplicitDir1 -- File
Expand All @@ -40,9 +43,6 @@ func TestListImplicitObjectsFromBucket(t *testing.T) {
implicit_and_explicit_dir_setup.CreateImplicitDirectory()
implicit_and_explicit_dir_setup.CreateExplicitDirectory(t)

// Delete objects from bucket after testing.
defer os.RemoveAll(setup.MntDir())

err := filepath.WalkDir(setup.MntDir(), func(path string, dir fs.DirEntry, err error) error {
if err != nil {
fmt.Printf("prevent panic by handling failure accessing a path %q: %v\n", path, err)
Expand Down
15 changes: 6 additions & 9 deletions tools/integration_tests/operations/copy_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import (
// srcCopyDir/copy.txt -- File
// srcCopyDir/subSrcCopyDir -- Dir
func createSrcDirectoryWithObjects(dirPath string, t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

// testBucket/srcCopyDir
err := os.Mkdir(dirPath, setup.FilePermission_0600)
if err != nil {
Expand Down Expand Up @@ -57,6 +60,9 @@ func createSrcDirectoryWithObjects(dirPath string, t *testing.T) {
if err != nil {
t.Errorf("File at %v", err)
}

// Closing file at the end
defer operations.CloseFile(file)
}

func checkIfCopiedDirectoryHasCorrectData(destDir string, t *testing.T) {
Expand Down Expand Up @@ -115,9 +121,6 @@ func TestCopyDirectoryInNonExistingDirectory(t *testing.T) {
}

checkIfCopiedDirectoryHasCorrectData(destDir, t)

os.RemoveAll(srcDir)
sethiay marked this conversation as resolved.
Show resolved Hide resolved
os.RemoveAll(destDir)
}

// Copy SrcDirectory in DestDirectory
Expand Down Expand Up @@ -162,9 +165,6 @@ func TestCopyDirectoryInEmptyDirectory(t *testing.T) {

destSrc := path.Join(destDir, SrcCopyDirectory)
checkIfCopiedDirectoryHasCorrectData(destSrc, t)

os.RemoveAll(srcDir)
os.RemoveAll(destDir)
}

func TestCopyDirectoryInNonEmptyDirectory(t *testing.T) {
Expand Down Expand Up @@ -219,7 +219,4 @@ func TestCopyDirectoryInNonEmptyDirectory(t *testing.T) {

destSrc := path.Join(destDir, SrcCopyDirectory)
checkIfCopiedDirectoryHasCorrectData(destSrc, t)

os.RemoveAll(srcDir)
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
os.RemoveAll(destDir)
}
3 changes: 3 additions & 0 deletions tools/integration_tests/operations/copy_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
)

func TestCopyFile(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

fileName := setup.CreateTempFile()

content, err := operations.ReadFile(fileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ func TestCreateThreeLevelDirectories(t *testing.T) {
// testBucket/dirOneInCreateThreeLevelDirTest/dirTwoInCreateThreeLevelDirTest -- Dir
// testBucket/dirOneInCreateThreeLevelDirTest/dirTwoInCreateThreeLevelDirTest/dirThreeInCreateThreeLevelDirTest -- Dir
// testBucket/dirOneInCreateThreeLevelDirTest/dirTwoInCreateThreeLevelDirTest/dirThreeInCreateThreeLevelDirTest/fileInDirThreeInCreateThreeLevelDirTest -- File
os.RemoveAll(setup.MntDir())

// Clean the mountedDirectory before running test.
setup.CleanMntDir()

dirPath := path.Join(setup.MntDir(), DirOneInCreateThreeLevelDirTest)

Expand Down Expand Up @@ -143,6 +145,4 @@ func TestCreateThreeLevelDirectories(t *testing.T) {
t.Errorf("error walking the path : %v\n", err)
return
}

os.RemoveAll(setup.MntDir())
}
6 changes: 6 additions & 0 deletions tools/integration_tests/operations/delete_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (
)

func TestDeleteEmptyExplicitDir(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

dirPath := path.Join(setup.MntDir(), EmptyExplicitDirectoryForDeleteTest)
operations.CreateDirectoryWithNFiles(0, dirPath, "", t)

Expand All @@ -40,6 +43,9 @@ func TestDeleteEmptyExplicitDir(t *testing.T) {
}

func TestDeleteNonEmptyExplicitDir(t *testing.T) {
// Clean the mountedDirectory before running tests.
setup.CleanMntDir()

dirPath := path.Join(setup.MntDir(), NonEmptyExplicitDirectoryForDeleteTest)
operations.CreateDirectoryWithNFiles(NumberOfFilesInNonEmptyExplicitDirectoryForDeleteTest, dirPath, PrefixFilesInNonEmptyExplicitDirectoryForDeleteTest, t)

Expand Down
12 changes: 11 additions & 1 deletion tools/integration_tests/operations/delete_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"path"
"testing"

"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/operations"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup"
)

Expand All @@ -41,14 +42,20 @@ func checkIfFileDeletionSucceeded(filePath string, t *testing.T) {
}

func createFile(filePath string, t *testing.T) {
_, err := os.Create(filePath)
file, err := os.Create(filePath)
if err != nil {
t.Errorf("Error in creating file: %v", err)
}

// Closing file at the end
operations.CloseFile(file)
}

// Remove testBucket/A.txt
func TestDeleteFileFromBucket(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

filePath := path.Join(setup.MntDir(), FileNameInTestBucket)

createFile(filePath, t)
Expand All @@ -58,6 +65,9 @@ func TestDeleteFileFromBucket(t *testing.T) {

// Remove testBucket/A/a.txt
func TestDeleteFileFromBucketDirectory(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

dirPath := path.Join(setup.MntDir(), DirNameInTestBucket)
err := os.Mkdir(dirPath, setup.FilePermission_0600)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions tools/integration_tests/operations/file_attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (
)

func TestFileAttributes(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

preCreateTime := time.Now()
fileName := setup.CreateTempFile()
postCreateTime := time.Now()
Expand Down
6 changes: 2 additions & 4 deletions tools/integration_tests/operations/list_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func createDirectoryStructureForTest(t *testing.T) {
}

func TestListDirectoryRecursively(t *testing.T) {
// Clean the bucket for list testing.
os.RemoveAll(setup.MntDir())
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

// Create directory structure for testing.
createDirectoryStructureForTest(t)
Expand Down Expand Up @@ -178,6 +178,4 @@ func TestListDirectoryRecursively(t *testing.T) {
t.Errorf("error walking the path : %v\n", err)
return
}

os.RemoveAll(setup.MntDir())
}
14 changes: 10 additions & 4 deletions tools/integration_tests/operations/move_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import (
// Test -- Directory
// Test/move.txt -- File
func createSrcDirectoryAndFile(dirPath string, filePath string, t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

err := os.Mkdir(dirPath, setup.FilePermission_0600)
if err != nil {
t.Errorf("Mkdir at %q: %v", dirPath, err)
Expand All @@ -39,6 +42,13 @@ func createSrcDirectoryAndFile(dirPath string, filePath string, t *testing.T) {
t.Errorf("Error in creating file %v:", err)
}

// Closing file at the end.
defer func() {
if err := file.Close(); err != nil {
t.Errorf("error in closing: %v", err)
}
}()

err = operations.WriteFile(file.Name(), MoveFileContent)
if err != nil {
t.Errorf("File at %v", err)
Expand Down Expand Up @@ -78,8 +88,6 @@ func TestMoveFileWithinSameDirectory(t *testing.T) {
}

checkIfFileMoveOperationSucceeded(filePath, destDirPath, t)

os.RemoveAll(dirPath)
sethiay marked this conversation as resolved.
Show resolved Hide resolved
}

// Move file from Test/move.txt to Test1/move.txt
Expand All @@ -96,6 +104,4 @@ func TestMoveFileWithinDifferentDirectory(t *testing.T) {
}

checkIfFileMoveOperationSucceeded(filePath, destDirPath, t)

os.RemoveAll(dirPath)
}
7 changes: 7 additions & 0 deletions tools/integration_tests/operations/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
)

func TestReadAfterWrite(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved

tmpDir, err := os.MkdirTemp(setup.MntDir(), "tmpDir")
if err != nil {
t.Errorf("Mkdir at %q: %v", setup.MntDir(), err)
Expand All @@ -35,6 +38,10 @@ func TestReadAfterWrite(t *testing.T) {
t.Errorf("Create file at %q: %v", tmpDir, err)
return
}

// Closing file at the end
operations.CloseFile(tmpFile)

fileName := tmpFile.Name()

err = operations.WriteFileInAppendMode(fileName, "line 1\n")
Expand Down
3 changes: 3 additions & 0 deletions tools/integration_tests/operations/rename_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
)

func TestRenameFile(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

fileName := setup.CreateTempFile()

content, err := operations.ReadFile(fileName)
Expand Down
15 changes: 14 additions & 1 deletion tools/integration_tests/operations/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (
)

func TestWriteAtEndOfFile(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

fileName := setup.CreateTempFile()

err := operations.WriteFileInAppendMode(fileName, "line 3\n")
Expand All @@ -36,6 +39,9 @@ func TestWriteAtEndOfFile(t *testing.T) {
}

func TestWriteAtStartOfFile(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

fileName := setup.CreateTempFile()

err := operations.WriteFile(fileName, "line 4\n")
Expand All @@ -47,6 +53,9 @@ func TestWriteAtStartOfFile(t *testing.T) {
}

func TestWriteAtRandom(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

fileName := setup.CreateTempFile()

f, err := os.OpenFile(fileName, os.O_WRONLY|syscall.O_DIRECT, setup.FilePermission_0600)
Expand All @@ -59,12 +68,16 @@ func TestWriteAtRandom(t *testing.T) {
if _, err = f.WriteAt([]byte("line 5\n"), 7); err != nil {
t.Errorf("WriteString-Random: %v", err)
}
f.Close()
// Closing file at the end
operations.CloseFile(f)

setup.CompareFileContents(t, fileName, "line 1\nline 5\n")
}

func TestCreateFile(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

fileName := setup.CreateTempFile()

// Stat the file to check if it exists.
Expand Down
4 changes: 1 addition & 3 deletions tools/integration_tests/readonly/create_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ import (
)

func checkIfFileCreationFailed(filePath string, t *testing.T) {
file, err := os.OpenFile(filePath, os.O_CREATE, setup.FilePermission_0600)
_, err := os.OpenFile(filePath, os.O_CREATE, setup.FilePermission_0600)

if err == nil {
t.Errorf("File is created in read-only file system.")
}

checkErrorForReadOnlyFileSystem(err, t)

defer file.Close()
}

func TestCreateFile(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions tools/integration_tests/readonly/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ func TestReadFileFromBucketSubDirectory(t *testing.T) {
}

func checkIfNonExistentFileFailedToOpen(filePath string, t *testing.T) {
file, err := os.OpenFile(filePath, os.O_RDONLY|syscall.O_DIRECT, setup.FilePermission_0600)
_, err := os.OpenFile(filePath, os.O_RDONLY|syscall.O_DIRECT, setup.FilePermission_0600)

checkErrorForObjectNotExist(err, t)

if err == nil {
t.Errorf("Nonexistent file opened to read.")
}
defer file.Close()
}

func TestReadNonExistentFile(t *testing.T) {
Expand Down
Loading
Loading