Skip to content

Commit

Permalink
rebase changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeenkaur committed Sep 21, 2023
1 parent 791d10b commit b243d16
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
27 changes: 14 additions & 13 deletions tools/integration_tests/local_file/remove_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ import (
"testing"

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

func TestRmDirOfDirectoryContainingGCSAndLocalFiles(t *testing.T) {
testDirPath = setup.SetupTestDirectory(LocalFileTestDirInBucket)
testDirPath = setup.SetupTestDirectory(testDirName)
// Create explicit directory with one synced and one local file.
operations.CreateDirectory(path.Join(testDirPath, ExplicitDirName), t)
syncedFile := path.Join(ExplicitDirName, FileName1)
localFile := path.Join(ExplicitDirName, FileName2)
_, fh1 := CreateLocalFileInTestDir(testDirPath, syncedFile, t)
CloseFileAndValidateObjectContentsFromGCS(fh1, syncedFile, "", t)
_, fh2 := CreateLocalFileInTestDir(testDirPath, localFile, t)
_, fh1 := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, syncedFile, t)
CloseFileAndValidateContentFromGCS(ctx, storageClient, fh1, testDirName, syncedFile, "", t)
_, fh2 := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, localFile, t)

// Attempt to remove explicit directory.
operations.RemoveDir(path.Join(testDirPath, ExplicitDirName))
Expand All @@ -43,20 +44,20 @@ func TestRmDirOfDirectoryContainingGCSAndLocalFiles(t *testing.T) {
operations.WriteWithoutClose(fh2, FileContents, t)
// Validate flush file does not throw error and does not create object on GCS.
operations.CloseFileShouldNotThrowError(fh2, t)
ValidateObjectNotFoundErrOnGCS(localFile, t)
ValidateObjectNotFoundErrOnGCS(ctx, storageClient, testDirName, localFile, t)
// Validate synced files are also deleted.
ValidateObjectNotFoundErrOnGCS(syncedFile, t)
ValidateObjectNotFoundErrOnGCS(ExplicitDirName, t)
ValidateObjectNotFoundErrOnGCS(ctx, storageClient, testDirName, syncedFile, t)
ValidateObjectNotFoundErrOnGCS(ctx, storageClient, testDirName, ExplicitDirName, t)
}

func TestRmDirOfDirectoryContainingOnlyLocalFiles(t *testing.T) {
testDirPath = setup.SetupTestDirectory(LocalFileTestDirInBucket)
testDirPath = setup.SetupTestDirectory(testDirName)
// Create a directory with two local files.
operations.CreateDirectory(path.Join(testDirPath, ExplicitDirName), t)
localFile1 := path.Join(ExplicitDirName, FileName1)
localFile2 := path.Join(ExplicitDirName, FileName2)
_, fh1 := CreateLocalFileInTestDir(testDirPath, localFile1, t)
_, fh2 := CreateLocalFileInTestDir(testDirPath, localFile2, t)
_, fh1 := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, localFile1, t)
_, fh2 := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, localFile2, t)

// Attempt to remove explicit directory.
operations.RemoveDir(path.Join(testDirPath, ExplicitDirName))
Expand All @@ -65,9 +66,9 @@ func TestRmDirOfDirectoryContainingOnlyLocalFiles(t *testing.T) {
ValidateNoFileOrDirError(path.Join(testDirPath, ExplicitDirName), t)
// Close the local files and validate they are not present on GCS.
operations.CloseFileShouldNotThrowError(fh1, t)
ValidateObjectNotFoundErrOnGCS(localFile1, t)
ValidateObjectNotFoundErrOnGCS(ctx, storageClient, testDirName, localFile1, t)
operations.CloseFileShouldNotThrowError(fh2, t)
ValidateObjectNotFoundErrOnGCS(localFile2, t)
ValidateObjectNotFoundErrOnGCS(ctx, storageClient, testDirName, localFile2, t)
// Validate directory is also deleted.
ValidateObjectNotFoundErrOnGCS(ExplicitDirName, t)
ValidateObjectNotFoundErrOnGCS(ctx, storageClient, testDirName, ExplicitDirName, t)
}
46 changes: 28 additions & 18 deletions tools/integration_tests/local_file/rename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ import (
"testing"

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

func TestRenameOfLocalFileFails(t *testing.T) {
testDirPath = setup.SetupTestDirectory(LocalFileTestDirInBucket)
testDirPath = setup.SetupTestDirectory(testDirName)
// Create local file with some content.
_, fh := CreateLocalFileInTestDir(testDirPath, FileName1, t)
WritingToLocalFileShouldNotWriteToGCS(fh, FileName1, t)
_, fh := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, FileName1, t)
WritingToLocalFileShouldNotWriteToGCS(ctx, storageClient, fh, testDirName, FileName1, t)

// Attempt to rename local file.
err := os.Rename(
Expand All @@ -39,20 +40,24 @@ func TestRenameOfLocalFileFails(t *testing.T) {
// Verify rename operation fails.
VerifyRenameOperationNotSupported(err, t)
// write more content to local file.
WritingToLocalFileShouldNotWriteToGCS(fh, FileName1, t)
WritingToLocalFileShouldNotWriteToGCS(ctx, storageClient, fh, testDirName, FileName1, t)
// Close the local file.
CloseFileAndValidateObjectContentsFromGCS(fh, FileName1, FileContents+FileContents, t)
CloseFileAndValidateContentFromGCS(ctx, storageClient, fh, testDirName,
FileName1, FileContents+FileContents, t)
}

func TestRenameOfDirectoryWithLocalFileFails(t *testing.T) {
testDirPath = setup.SetupTestDirectory(LocalFileTestDirInBucket)
testDirPath = setup.SetupTestDirectory(testDirName)
//Create directory with 1 synced and 1 local file.
operations.CreateDirectory(path.Join(testDirPath, ExplicitDirName), t)
// Create synced file.
CreateObjectInGCSTestDir(path.Join(ExplicitDirName, FileName1), GCSFileContent, t)
CreateObjectInGCSTestDir(ctx, storageClient, testDirName,
path.Join(ExplicitDirName, FileName1), GCSFileContent, t)
// Create local file with some content.
_, fh := CreateLocalFileInTestDir(testDirPath, path.Join(ExplicitDirName, FileName2), t)
WritingToLocalFileShouldNotWriteToGCS(fh, path.Join(ExplicitDirName, FileName2), t)
_, fh := CreateLocalFileInTestDir(ctx, storageClient, testDirPath,
path.Join(ExplicitDirName, FileName2), t)
WritingToLocalFileShouldNotWriteToGCS(ctx, storageClient, fh, testDirName,
path.Join(ExplicitDirName, FileName2), t)

// Attempt to rename directory containing local file.
err := os.Rename(
Expand All @@ -62,10 +67,10 @@ func TestRenameOfDirectoryWithLocalFileFails(t *testing.T) {
// Verify rename operation fails.
VerifyRenameOperationNotSupported(err, t)
// Write more content to local file.
WritingToLocalFileShouldNotWriteToGCS(fh, FileName2, t)
WritingToLocalFileShouldNotWriteToGCS(ctx, storageClient, fh, testDirName, FileName2, t)
// Close the local file.
CloseFileAndValidateObjectContentsFromGCS(fh, path.Join(ExplicitDirName, FileName2),
FileContents+FileContents, t)
CloseFileAndValidateContentFromGCS(ctx, storageClient, fh, testDirName,
path.Join(ExplicitDirName, FileName2), FileContents+FileContents, t)
}

func TestRenameOfLocalFileSucceedsAfterSync(t *testing.T) {
Expand All @@ -80,8 +85,9 @@ func TestRenameOfLocalFileSucceedsAfterSync(t *testing.T) {
if err != nil {
t.Fatalf("os.Rename() failed on synced file: %v", err)
}
ValidateObjectContentsFromGCS(NewFileName, FileContents+FileContents, t)
ValidateObjectNotFoundErrOnGCS(FileName1, t)
ValidateObjectContentsFromGCS(ctx, storageClient, testDirName, NewFileName,
FileContents+FileContents, t)
ValidateObjectNotFoundErrOnGCS(ctx, storageClient, testDirName, FileName1, t)
}

func TestRenameOfDirectoryWithLocalFileSucceedsAfterSync(t *testing.T) {
Expand All @@ -96,8 +102,12 @@ func TestRenameOfDirectoryWithLocalFileSucceedsAfterSync(t *testing.T) {
if err != nil {
t.Fatalf("os.Rename() failed on directory containing synced files: %v", err)
}
ValidateObjectContentsFromGCS(path.Join(NewDirName, FileName1), GCSFileContent, t)
ValidateObjectNotFoundErrOnGCS(path.Join(ExplicitDirName, FileName1), t)
ValidateObjectContentsFromGCS(path.Join(NewDirName, FileName2), FileContents+FileContents, t)
ValidateObjectNotFoundErrOnGCS(path.Join(ExplicitDirName, FileName2), t)
ValidateObjectContentsFromGCS(ctx, storageClient, testDirName,
path.Join(NewDirName, FileName1), GCSFileContent, t)
ValidateObjectNotFoundErrOnGCS(ctx, storageClient, testDirName,
path.Join(ExplicitDirName, FileName1), t)
ValidateObjectContentsFromGCS(ctx, storageClient, testDirName,
path.Join(NewDirName, FileName2), FileContents+FileContents, t)
ValidateObjectNotFoundErrOnGCS(ctx, storageClient, testDirName,
path.Join(ExplicitDirName, FileName2), t)
}
2 changes: 2 additions & 0 deletions tools/integration_tests/util/client/gcs_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (
GCSFileSize = 13
FilePerms = 0644
ReadSize = 1024
NewFileName = "newName"
NewDirName = "newDirName"
)

func CreateImplicitDir(ctx context.Context, storageClient *storage.Client,
Expand Down

0 comments on commit b243d16

Please sign in to comment.