Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: create delete list integration tests #1073

Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

71 changes: 71 additions & 0 deletions tools/integration_tests/readonly/create_object_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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 checkIfFileCreationFailed(filePath string, t *testing.T) {
file, err := os.OpenFile(filePath, os.O_CREATE, setup.FilePermission_0600)

if err == nil {
t.Errorf("File is created in read-only file system.")
}

checkErrorForReadOnlyFileSystem(err, t)

defer file.Close()
}

func TestCreateFile(t *testing.T) {
filePath := path.Join(setup.MntDir(), "testFile.txt")

checkIfFileCreationFailed(filePath, t)
}

func TestCreateFileInDirectory(t *testing.T) {
filePath := path.Join(setup.MntDir(), DirectoryNameInTestBucket, "testFile.txt")

checkIfFileCreationFailed(filePath, t)
}

func checkIfDirCreationFailed(dirPath string, t *testing.T) {
err := os.Mkdir(dirPath, fs.ModeDir)

if err == nil {
t.Errorf("Directory is created in read-only file system.")
}

checkErrorForReadOnlyFileSystem(err, t)
}

func TestCreateDir(t *testing.T) {
dirPath := path.Join(setup.MntDir(), "test")

checkIfDirCreationFailed(dirPath, t)
}

func TestCreateSubDirectoryInDirectory(t *testing.T) {
dirPath := path.Join(setup.MntDir(), DirectoryNameInTestBucket, "test")

checkIfDirCreationFailed(dirPath, t)
}
62 changes: 62 additions & 0 deletions tools/integration_tests/readonly/delete_object_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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 (
"os"
"path"
"testing"

"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/setup"
)

func checkIfObjDeletionFailed(objPath string, t *testing.T) {
err := os.RemoveAll(objPath)

if err == nil {
t.Errorf("Objects are deleted in read-only file system.")
}

checkErrorForReadOnlyFileSystem(err, t)
}

func TestDeleteDir(t *testing.T) {
objPath := path.Join(setup.MntDir(), DirectoryNameInTestBucket)

checkIfObjDeletionFailed(objPath, t)
}

func TestDeleteFile(t *testing.T) {
objPath := path.Join(setup.MntDir(), FileNameInTestBucket)

checkIfObjDeletionFailed(objPath, t)
}

func TestDeleteSubDirectory(t *testing.T) {
objPath := path.Join(setup.MntDir(), DirectoryNameInTestBucket, SubDirectoryNameInTestBucket)

checkIfObjDeletionFailed(objPath, t)
}

func TestDeleteFileInDirectory(t *testing.T) {
objPath := path.Join(setup.MntDir(), DirectoryNameInTestBucket, FileNameInDirectoryTestBucket)

checkIfObjDeletionFailed(objPath, t)
}

func TestDeleteAllObjectsInBucket(t *testing.T) {
checkIfObjDeletionFailed(setup.MntDir(), t)
}
26 changes: 18 additions & 8 deletions tools/integration_tests/readonly/list_objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,25 @@ func TestListObjectsInBucket(t *testing.T) {
log.Fatal(err)
}

// Comparing number of objects in the testBucket - 2
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 {
// Comparing first object name and type
// Name - testBucket/Test, Type - Dir
if obj[0].Name() != DirectoryNameInTestBucket || obj[0].IsDir() != true {
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
t.Errorf("Listed object is incorrect.")
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
}

if obj[1].Name() != FileNameInTestBucket && obj[1].IsDir() != false {
// Comparing second object name and type
// Name - testBucket/Test1.txt, Type - File
if obj[1].Name() != FileNameInTestBucket || obj[1].IsDir() != false {
t.Errorf("Listed object is incorrect.")
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
}
}

func TestListObjectsInBucketSubDirectory(t *testing.T) {
func TestListObjectsInBucketDirectory(t *testing.T) {
// ** SubDirectory structure **
// testBucket/Test
// testBucket/Test/a.txt -- File
Expand All @@ -60,15 +65,20 @@ func TestListObjectsInBucketSubDirectory(t *testing.T) {
log.Fatal(err)
}

if len(obj) != NumberOfObjectsInTestBucketSubDirectory {
// Comparing number of objects in the directory of testBucket - 2.
if len(obj) != NumberOfObjectsInDirectoryTestBucket {
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.")
// Comparing first object name and type.
// Name - testBucket/Test/a.txt, Type - File
if obj[0].Name() != FileNameInDirectoryTestBucket || obj[0].IsDir() != false {
t.Errorf("Listed object from bucket directory is incorrect.")
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
}

if obj[1].Name() != SubDirectoryNameInTestBucket && obj[1].IsDir() != true {
t.Errorf("Listed object is incorrect.")
// Comparing second object name and type.
// Name - testBucket/b, Type - Dir
if obj[1].Name() != SubDirectoryNameInTestBucket || obj[1].IsDir() != true {
t.Errorf("Listed object from bucket directory is incorrect.")
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
}
}
18 changes: 13 additions & 5 deletions tools/integration_tests/readonly/readonly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ package readonly_test
import (
"os"
"os/exec"
"strings"
"testing"

"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/setup"
)

const DirectoryNameInTestBucket = "Test" // testBucket/Test
const FileNameInTestBucket = "Test1.txt" // testBucket/Test1.txt
const SubDirectoryNameInTestBucket = "b" // testBucket/Test/b
const FileInSubDirectoryNameInTestBucket = "a.txt" // testBucket/Test/a.txt
const DirectoryNameInTestBucket = "Test" // testBucket/Test
const FileNameInTestBucket = "Test1.txt" // testBucket/Test1.txt
const SubDirectoryNameInTestBucket = "b" // testBucket/Test/b
const FileNameInDirectoryTestBucket = "a.txt" // testBucket/Test/a.txt
const FileNameInSubDirectoryTestBucket = "b.txt" // testBucket/Test/b/b.txt
const NumberOfObjectsInTestBucket = 2
const NumberOfObjectsInTestBucketSubDirectory = 2
const NumberOfObjectsInDirectoryTestBucket = 2

// Run shell script
func runScriptForTestData(script string, testBucket string) {
Expand All @@ -39,6 +41,12 @@ func runScriptForTestData(script string, testBucket string) {
}
}

func checkErrorForReadOnlyFileSystem(err error, t *testing.T) {
if !strings.Contains(err.Error(), "read-only file system") && !strings.Contains(err.Error(), "permission denied") {
t.Errorf("Incorrect error for readonly filesystem.")
}
}

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

Expand Down