-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Readonly Integration Tests - Create, Delete, List (#1067)
* adding list, delete and create object tests * adding more test cases * small fix * updating variable name * updating file name * adding more tests for create * fixing lint test * small fix * local test * revert local changes * adding clear bucket * adding extra line * fixing bucket argument * fixing comments * updating path with path.join * changing function name * making variable for bucket objects * small fix * adding comment for directory structure * replace with variable * lint test * lint test
- Loading branch information
Showing
4 changed files
with
189 additions
and
1 deletion.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
tools/integration_tests/readonly/create_and_delete_object_test.go
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,98 @@ | ||
// 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 operations with --o=ro flag set. | ||
package readonly_test | ||
|
||
import ( | ||
"io/fs" | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/setup" | ||
) | ||
|
||
func ensureFileSystemLockedForFileCreation(filePath string, t *testing.T) { | ||
file, err := os.OpenFile(filePath, os.O_CREATE, setup.FilePermission_0600) | ||
|
||
// It will throw an error read-only file system or permission denied. | ||
if err == nil { | ||
t.Errorf("File is created in read-only file system.") | ||
} | ||
|
||
defer file.Close() | ||
} | ||
|
||
func TestCreateFile(t *testing.T) { | ||
filePath := path.Join(setup.MntDir(), "testFile.txt") | ||
ensureFileSystemLockedForFileCreation(filePath, t) | ||
} | ||
|
||
func TestCreateFileInSubDirectory(t *testing.T) { | ||
filePath := path.Join(setup.MntDir(), DirectoryNameInTestBucket, "testFile.txt") | ||
ensureFileSystemLockedForFileCreation(filePath, t) | ||
} | ||
|
||
func ensureFileSystemLockedForDirCreation(dirPath string, t *testing.T) { | ||
err := os.Mkdir(dirPath, fs.ModeDir) | ||
|
||
// It will throw an error read-only file system or permission denied. | ||
if err == nil { | ||
t.Errorf("Directory is created in read-only file system.") | ||
} | ||
} | ||
|
||
func TestCreateDir(t *testing.T) { | ||
dirPath := path.Join(setup.MntDir(), "test") | ||
ensureFileSystemLockedForDirCreation(dirPath, t) | ||
} | ||
|
||
func TestCreateDirInSubDirectory(t *testing.T) { | ||
dirPath := path.Join(setup.MntDir(), DirectoryNameInTestBucket, "test") | ||
ensureFileSystemLockedForDirCreation(dirPath, t) | ||
} | ||
|
||
func ensureFileSystemLockedForDeletion(objPath string, t *testing.T) { | ||
err := os.RemoveAll(objPath) | ||
|
||
// It will throw an error read-only file system or permission denied. | ||
if err == nil { | ||
t.Errorf("Objects are deleted in read-only file system.") | ||
} | ||
} | ||
|
||
func TestDeleteDir(t *testing.T) { | ||
objPath := path.Join(setup.MntDir(), DirectoryNameInTestBucket) | ||
ensureFileSystemLockedForDeletion(objPath, t) | ||
} | ||
|
||
func TestDeleteFile(t *testing.T) { | ||
objPath := path.Join(setup.MntDir(), FileNameInTestBucket) | ||
ensureFileSystemLockedForDeletion(objPath, t) | ||
} | ||
|
||
func TestDeleteSubDirectory(t *testing.T) { | ||
objPath := path.Join(setup.MntDir(), DirectoryNameInTestBucket, SubDirectoryNameInTestBucket) | ||
ensureFileSystemLockedForDeletion(objPath, t) | ||
} | ||
|
||
func TestDeleteFileInSubDirectory(t *testing.T) { | ||
objPath := path.Join(setup.MntDir(), DirectoryNameInTestBucket, FileInSubDirectoryNameInTestBucket) | ||
ensureFileSystemLockedForDeletion(objPath, t) | ||
} | ||
|
||
func TestDeleteAllObjectsInBucket(t *testing.T) { | ||
ensureFileSystemLockedForDeletion(setup.MntDir(), 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,74 @@ | ||
// 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 operations with --o=ro flag set. | ||
package readonly_test | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/setup" | ||
) | ||
|
||
func TestListObjectsInBucket(t *testing.T) { | ||
// ** Directory structure ** | ||
// testBucket | ||
// testBucket/Test -- Dir | ||
// testBucket/Test1.txt -- File | ||
|
||
obj, err := os.ReadDir(setup.MntDir()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if len(obj) != NumberOfObjectsInTestBucket { | ||
t.Errorf("The number of objects in the current directory doesn't match.") | ||
} | ||
|
||
if obj[0].Name() != DirectoryNameInTestBucket && obj[0].IsDir() != true { | ||
t.Errorf("Listed object is incorrect.") | ||
} | ||
|
||
if obj[1].Name() != FileNameInTestBucket && obj[1].IsDir() != false { | ||
t.Errorf("Listed object is incorrect.") | ||
} | ||
} | ||
|
||
func TestListObjectsInBucketSubDirectory(t *testing.T) { | ||
// ** SubDirectory structure ** | ||
// testBucket/Test | ||
// testBucket/Test/a.txt -- File | ||
// testBucket/Test/b/ -- Dir | ||
|
||
Dir := path.Join(setup.MntDir(), DirectoryNameInTestBucket) | ||
obj, err := os.ReadDir(Dir) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if len(obj) != NumberOfObjectsInTestBucketSubDirectory { | ||
t.Errorf("The number of objects in the current directory doesn't match.") | ||
} | ||
|
||
if obj[0].Name() != FileInSubDirectoryNameInTestBucket && obj[0].IsDir() != false { | ||
t.Errorf("Listed object is incorrect.") | ||
} | ||
|
||
if obj[1].Name() != SubDirectoryNameInTestBucket && obj[1].IsDir() != true { | ||
t.Errorf("Listed object is incorrect.") | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,8 @@ | ||
# Here $1 refers to the testBucket argument | ||
gsutil rm -a gs://$1/** | ||
|
||
# If bucket is empty it will throw an CommandException. | ||
if [ $? -eq 1 ]; then | ||
echo "Bucket is already empty." | ||
exit 0 | ||
fi |