-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration tests to verify that file creation does not creates file …
…on GCS until synced. (#1382) * verify that file creation does not creates file on GCS until synced * rebase changes * review comments * duplicate method * review comments.
- Loading branch information
1 parent
dc4a137
commit ee62245
Showing
8 changed files
with
241 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2023 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Provides integration tests for create local file. | ||
package local_file_test | ||
|
||
import ( | ||
"path" | ||
"testing" | ||
|
||
. "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(testDirName) | ||
|
||
// Validate. | ||
NewFileShouldGetSyncedToGCSAtClose(ctx, storageClient, testDirPath, FileName1, t) | ||
} | ||
|
||
func TestNewFileUnderExplicitDirectoryShouldNotGetSyncedToGCSTillClose(t *testing.T) { | ||
testDirPath = setup.SetupTestDirectory(testDirName) | ||
// Make explicit directory. | ||
operations.CreateDirectory(path.Join(testDirPath, ExplicitDirName), t) | ||
|
||
// Validate. | ||
NewFileShouldGetSyncedToGCSAtClose(ctx, storageClient, testDirPath, path.Join(ExplicitDirName, ExplicitFileName1), t) | ||
} | ||
|
||
func TestCreateNewFileWhenSameFileExistsOnGCS(t *testing.T) { | ||
testDirPath = setup.SetupTestDirectory(testDirName) | ||
// Create a local file. | ||
_, fh := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, FileName1, t) | ||
|
||
// Create a file on GCS with the same name. | ||
CreateObjectInGCSTestDir(ctx, storageClient, testDirName, FileName1, GCSFileContent, t) | ||
|
||
// Write to local file. | ||
operations.WriteWithoutClose(fh, FileContents, t) | ||
// Close the local file. | ||
operations.CloseFileShouldNotThrowError(fh, t) | ||
// Ensure that the content on GCS is not overwritten. | ||
ValidateObjectContentsFromGCS(ctx, storageClient, testDirName, FileName1, GCSFileContent, t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright 2023 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Provides integration tests for file and directory operations. | ||
|
||
package local_file_test | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"path" | ||
"testing" | ||
"time" | ||
|
||
"cloud.google.com/go/storage" | ||
"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" | ||
) | ||
|
||
const ( | ||
testDirName = "LocalFileTest" | ||
) | ||
|
||
var ( | ||
testDirPath string | ||
storageClient *storage.Client | ||
ctx context.Context | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
setup.ParseSetUpFlags() | ||
|
||
ctx = context.Background() | ||
var cancel context.CancelFunc | ||
var err error | ||
|
||
setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet() | ||
|
||
// Create storage client before running tests. | ||
ctx, cancel = context.WithTimeout(ctx, time.Minute*15) | ||
storageClient, err = client.CreateStorageClient(ctx) | ||
if err != nil { | ||
log.Fatalf("client.CreateStorageClient: %v", err) | ||
} | ||
|
||
// To run mountedDirectory tests, we need both testBucket and mountedDirectory | ||
// flags to be set, as local_file tests validates content from the bucket. | ||
if setup.AreBothMountedDirectoryAndTestBucketFlagsSet() { | ||
setup.RunTestsForMountedDirectoryFlag(m) | ||
} | ||
|
||
// Else run tests for testBucket. | ||
// Set up test directory. | ||
setup.SetUpTestDirForTestBucketFlag() | ||
|
||
// Set up flags to run tests on. | ||
// Not setting config file explicitly with 'create-empty-file: false' as it is default. | ||
flags := [][]string{ | ||
{"--implicit-dirs=true", "--rename-dir-limit=3"}, | ||
{"--implicit-dirs=false", "--rename-dir-limit=3"}} | ||
|
||
successCode := static_mounting.RunTests(flags, m) | ||
|
||
if successCode == 0 { | ||
successCode = only_dir_mounting.RunTests(flags, m) | ||
} | ||
|
||
if successCode == 0 { | ||
successCode = dynamic_mounting.RunTests(flags, m) | ||
} | ||
|
||
// Close storage client and release resources. | ||
storageClient.Close() | ||
cancel() | ||
// Clean up test directory created. | ||
setup.CleanupDirectoryOnGCS(path.Join(setup.TestBucket(), testDirName)) | ||
setup.RemoveBinFileCopiedForTesting() | ||
os.Exit(successCode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters