Skip to content

Commit

Permalink
rebase changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeenkaur committed Sep 20, 2023
1 parent 79ef527 commit b15031e
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 143 deletions.
16 changes: 8 additions & 8 deletions tools/integration_tests/implicit_dir/local_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestNewFileUnderImplicitDirectoryShouldNotGetSyncedToGCSTillClose(t *testin
CreateImplicitDir(ctx, storageClient, testDirName, t)
fileName := path.Join(ImplicitDirName, FileName1)

fh := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, fileName, t)
_, fh := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, fileName, t)
operations.WriteWithoutClose(fh, FileContents, t)
ValidateObjectNotFoundErrOnGCS(ctx, storageClient, testDirName, fileName, t)

Expand All @@ -58,8 +58,8 @@ func TestReadDirForImplicitDirWithLocalFile(t *testing.T) {
CreateImplicitDir(ctx, storageClient, testDirName, t)
fileName1 := path.Join(ImplicitDirName, FileName1)
fileName2 := path.Join(ImplicitDirName, FileName2)
fh1 := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, fileName1, t)
fh2 := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, fileName2, t)
_, fh1 := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, fileName1, t)
_, fh2 := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, fileName2, t)

// Attempt to list implicit directory.
entries := operations.ReadDirectory(path.Join(testDirPath, ImplicitDirName), t)
Expand All @@ -68,7 +68,7 @@ func TestReadDirForImplicitDirWithLocalFile(t *testing.T) {
operations.VerifyCountOfDirectoryEntries(3, len(entries), t)
operations.VerifyFileEntry(entries[0], FileName1, 0, t)
operations.VerifyFileEntry(entries[1], FileName2, 0, t)
operations.VerifyFileEntry(entries[2], ImplicitFileName1, ImplicitFileSize, t)
operations.VerifyFileEntry(entries[2], ImplicitFileName1, GCSFileSize, t)
// Close the local files.
CloseFileAndValidateContentFromGCS(ctx, storageClient, testDirName, fh1, fileName1, "", t)
CloseFileAndValidateContentFromGCS(ctx, storageClient, testDirName, fh2, fileName2, "", t)
Expand All @@ -88,13 +88,13 @@ func TestRecursiveListingWithLocalFiles(t *testing.T) {
fileName2 := path.Join(ExplicitDirName, ExplicitFileName1)
fileName3 := path.Join(ImplicitDirName, FileName2)
// Create local file in mnt/ dir.
fh1 := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, FileName1, t)
_, fh1 := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, FileName1, t)
// Create explicit dir with 1 local file.
operations.CreateDirectory(path.Join(testDirPath, ExplicitDirName), t)
fh2 := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, fileName2, t)
_, fh2 := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, fileName2, t)
// Create implicit dir with 1 local file1 and 1 synced file.
CreateImplicitDir(ctx, storageClient, testDirName, t)
fh3 := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, fileName3, t)
_, fh3 := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, fileName3, t)

// Recursively list mntDir/ directory.
err := filepath.WalkDir(testDirPath,
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestRecursiveListingWithLocalFiles(t *testing.T) {
// numberOfObjects = 2
operations.VerifyCountOfDirectoryEntries(2, len(objs), t)
operations.VerifyFileEntry(objs[0], FileName2, 0, t)
operations.VerifyFileEntry(objs[1], ImplicitFileName1, ImplicitFileSize, t)
operations.VerifyFileEntry(objs[1], ImplicitFileName1, GCSFileSize, t)
}
return nil
})
Expand Down
18 changes: 9 additions & 9 deletions tools/integration_tests/local_file/create_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,37 @@ import (
"path"
"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 TestNewFileShouldNotGetSyncedToGCSTillClose(t *testing.T) {
testDirPath = setup.SetupTestDirectory(LocalFileTestDirInBucket)
testDirPath = setup.SetupTestDirectory(testDirName)

// Validate.
NewFileShouldGetSyncedToGCSAtClose(testDirPath, FileName1, t)
NewFileShouldGetSyncedToGCSAtClose(ctx, storageClient, testDirPath, FileName1, t)
}

func TestNewFileUnderExplicitDirectoryShouldNotGetSyncedToGCSTillClose(t *testing.T) {
testDirPath = setup.SetupTestDirectory(LocalFileTestDirInBucket)
testDirPath = setup.SetupTestDirectory(testDirName)
// Make explicit directory.
operations.CreateDirectory(path.Join(testDirPath, ExplicitDirName), t)

// Validate.
NewFileShouldGetSyncedToGCSAtClose(testDirPath, path.Join(ExplicitDirName, ExplicitFileName1), t)
NewFileShouldGetSyncedToGCSAtClose(ctx, storageClient, testDirPath, path.Join(ExplicitDirName, ExplicitFileName1), t)
}

func TestCreateNewFileWhenSameFileExistsOnGCS(t *testing.T) {
testDirPath = setup.SetupTestDirectory(LocalFileTestDirInBucket)
testDirPath = setup.SetupTestDirectory(testDirName)
// Create a local file.
_, fh := CreateLocalFileInTestDir(testDirPath, FileName1, t)
_, fh := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, FileName1, t)

// Create a file on GCS with the same name.
CreateObjectInGCSTestDir(FileName1, GCSFileContent, t)
CreateObjectInGCSTestDir(ctx, storageClient, testDirName, FileName1, GCSFileContent, t)

// Write to local file.
operations.WriteWithoutClose(fh, FileContents, t)
// Close the local file and ensure that the content on GCS is not overwritten.
CloseFileAndValidateObjectContentsFromGCS(fh, FileName1, GCSFileContent, t)
CloseFileAndValidateObjectContentsFromGCS(ctx, storageClient, fh, testDirName, FileName1, GCSFileContent, t)
}
103 changes: 0 additions & 103 deletions tools/integration_tests/local_file/helpers/gcs_helper.go

This file was deleted.

23 changes: 15 additions & 8 deletions tools/integration_tests/local_file/local_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,29 @@ import (
"testing"
"time"

"cloud.google.com/go/storage"
"github.com/googlecloudplatform/gcsfuse/internal/config"
"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/mounting/dynamic_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/only_dir_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/static_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup"
)

// testDirPath holds the path to the test subdirectory in the mounted bucket.
var testDirPath string
const (
testDirName = "LocalFileTest"
)

var (
testDirPath string
storageClient *storage.Client
ctx context.Context
)

func TestMain(m *testing.M) {
setup.ParseSetUpFlags()

helpers.Ctx = context.Background()
ctx = context.Background()
var cancel context.CancelFunc
var err error

Expand All @@ -51,8 +58,8 @@ func TestMain(m *testing.M) {
}

// Create storage client before running tests.
helpers.Ctx, cancel = context.WithTimeout(helpers.Ctx, time.Minute*15)
helpers.StorageClient, err = client.CreateStorageClient(helpers.Ctx)
ctx, cancel = context.WithTimeout(ctx, time.Minute*15)
storageClient, err = client.CreateStorageClient(ctx)
if err != nil {
log.Fatalf("client.CreateStorageClient: %v", err)
}
Expand Down Expand Up @@ -89,10 +96,10 @@ func TestMain(m *testing.M) {
}

// Close storage client and release resources.
helpers.StorageClient.Close()
storageClient.Close()
cancel()
// Clean up test directory created.
setup.CleanupDirectoryOnGCS(path.Join(setup.TestBucket(), helpers.LocalFileTestDirInBucket))
setup.CleanupDirectoryOnGCS(path.Join(setup.TestBucket(), testDirName))
setup.RemoveBinFileCopiedForTesting()
os.Exit(successCode)
}
63 changes: 48 additions & 15 deletions tools/integration_tests/util/client/gcs_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ import (
)

const (
FileName1 = "foo1"
FileName2 = "foo2"
ExplicitDirName = "explicit"
ExplicitFileName1 = "explicitFile1"
ImplicitDirName = "implicit"
ImplicitFileName1 = "implicitFile1"
FileContents = "testString"
ImplicitFileContents = "GCSteststring"
ImplicitFileSize = 13
FilePerms = 0644
ReadSize = 1024
FileName1 = "foo1"
FileName2 = "foo2"
ExplicitDirName = "explicit"
ExplicitFileName1 = "explicitFile1"
ImplicitDirName = "implicit"
ImplicitFileName1 = "implicitFile1"
FileContents = "testString"
GCSFileContent = "GCSteststring"
GCSFileSize = 13
FilePerms = 0644
ReadSize = 1024
)

func CreateImplicitDir(ctx context.Context, storageClient *storage.Client,
Expand All @@ -45,7 +45,7 @@ func CreateImplicitDir(ctx context.Context, storageClient *storage.Client,
ctx,
storageClient,
path.Join(testDirName, ImplicitDirName, ImplicitFileName1),
ImplicitFileContents)
GCSFileContent)
if err != nil {
t.Errorf("Error while creating implicit directory, err: %v", err)
}
Expand Down Expand Up @@ -78,15 +78,48 @@ func CloseFileAndValidateContentFromGCS(ctx context.Context, storageClient *stor
}

func CreateLocalFileInTestDir(ctx context.Context, storageClient *storage.Client,
testDirPath, fileName string, t *testing.T) (fh *os.File) {
testDirPath, fileName string, t *testing.T) (string, *os.File) {
filePath := path.Join(testDirPath, fileName)
fh = operations.CreateFile(filePath, FilePerms, t)
fh := operations.CreateFile(filePath, FilePerms, t)
testDirName := getDirName(testDirPath)
ValidateObjectNotFoundErrOnGCS(ctx, storageClient, testDirName, fileName, t)
return
return filePath, fh
}

func getDirName(testDirPath string) string {
dirName := testDirPath[strings.LastIndex(testDirPath, "/")+1:]
return dirName
}

func WritingToLocalFileShouldNotWriteToGCS(ctx context.Context, storageClient *storage.Client, fh *os.File, testDirName, fileName string, t *testing.T) {
operations.WriteWithoutClose(fh, FileContents, t)
ValidateObjectNotFoundErrOnGCS(ctx, storageClient, testDirName, fileName, t)
}

func NewFileShouldGetSyncedToGCSAtClose(ctx context.Context, storageClient *storage.Client,
testDirPath, fileName string, t *testing.T) {
// Create a local file.
_, fh := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, fileName, t)

// Writing contents to local file shouldn't create file on GCS.
testDirName := getDirName(testDirPath)
WritingToLocalFileShouldNotWriteToGCS(ctx, storageClient, fh, testDirName, fileName, t)

// Close the file and validate if the file is created on GCS.
CloseFileAndValidateObjectContentsFromGCS(ctx, storageClient, fh, testDirName, fileName, FileContents, t)
}

func CloseFileAndValidateObjectContentsFromGCS(ctx context.Context, storageClient *storage.Client,
f *os.File, testDirName, fileName, contents string, t *testing.T) {
operations.CloseFileShouldNotThrowError(f, t)
validateObjectContentsFromGCS(ctx, storageClient, testDirName, fileName, contents, t)
}

func CreateObjectInGCSTestDir(ctx context.Context, storageClient *storage.Client,
testDirName, fileName, content string, t *testing.T) {
objectName := path.Join(testDirName, fileName)
err := CreateObjectOnGCS(ctx, storageClient, objectName, content)
if err != nil {
t.Fatalf("Create Object %s on GCS: %v.", objectName, err)
}
}

0 comments on commit b15031e

Please sign in to comment.