-
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 read and write operations on local file (#…
…1383) * integration tests to verify read and write operations on local file rebase changes format * rebase changes * do not run testBucket tests if flag is not set.
- Loading branch information
1 parent
ee62245
commit 84c348e
Showing
3 changed files
with
106 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// 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 read operation on local files. | ||
package local_file_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/client" | ||
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup" | ||
) | ||
|
||
func TestReadLocalFile(t *testing.T) { | ||
testDirPath = setup.SetupTestDirectory(testDirName) | ||
// Create a local file. | ||
_, fh := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, FileName1, t) | ||
|
||
// Write FileContents twice to local file. | ||
content := FileContents + FileContents | ||
WritingToLocalFileShouldNotWriteToGCS(ctx, storageClient, fh, testDirName, FileName1, t) | ||
WritingToLocalFileShouldNotWriteToGCS(ctx, storageClient, fh, testDirName, FileName1, t) | ||
|
||
// Read the local file contents. | ||
buf := make([]byte, len(content)) | ||
n, err := fh.ReadAt(buf, 0) | ||
if err != nil || len(content) != n || content != string(buf) { | ||
t.Fatalf("Read file operation failed on local file: %v "+ | ||
"Expected content: %s, Got Content: %s", err, content, string(buf)) | ||
} | ||
|
||
// Close the file and validate that the file is created on GCS. | ||
CloseFileAndValidateContentFromGCS(ctx, storageClient, fh, testDirName, FileName1, content, 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,56 @@ | ||
// 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 write on local files. | ||
package local_file_test | ||
|
||
import ( | ||
"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 TestMultipleWritesToLocalFile(t *testing.T) { | ||
testDirPath = setup.SetupTestDirectory(testDirName) | ||
// Create a local file. | ||
_, fh := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, FileName1, t) | ||
|
||
// Write some contents to file sequentially. | ||
for i := 0; i < 3; i++ { | ||
operations.WriteWithoutClose(fh, FileContents, t) | ||
} | ||
ValidateObjectNotFoundErrOnGCS(ctx, storageClient, testDirName, FileName1, t) | ||
|
||
// Close the file and validate that the file is created on GCS. | ||
CloseFileAndValidateContentFromGCS(ctx, storageClient, fh, testDirName, | ||
FileName1, FileContents+FileContents+FileContents, t) | ||
} | ||
|
||
func TestRandomWritesToLocalFile(t *testing.T) { | ||
testDirPath = setup.SetupTestDirectory(testDirName) | ||
// Create a local file. | ||
_, fh := CreateLocalFileInTestDir(ctx, storageClient, testDirPath, FileName1, t) | ||
|
||
// Write some contents to file randomly. | ||
operations.WriteAt("string1", 0, fh, t) | ||
operations.WriteAt("string2", 2, fh, t) | ||
operations.WriteAt("string3", 3, fh, t) | ||
ValidateObjectNotFoundErrOnGCS(ctx, storageClient, testDirName, FileName1, t) | ||
|
||
// Close the file and validate that the file is created on GCS. | ||
CloseFileAndValidateContentFromGCS(ctx, storageClient, fh, testDirName, | ||
FileName1, "stsstring3", 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