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

Delete implicit dir integration test #1203

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
935ad73
adding delete tests
Tulsishah Jun 19, 2023
d1f93ed
adding delete tests
Tulsishah Jun 19, 2023
a4ec666
small fix
Tulsishah Jun 19, 2023
6ee2cdb
small fix
Tulsishah Jun 19, 2023
0911627
testing
Tulsishah Jun 19, 2023
3686b6c
testing
Tulsishah Jun 19, 2023
8a2210a
testing
Tulsishah Jun 19, 2023
d832274
testing
Tulsishah Jun 19, 2023
cec45b8
testing
Tulsishah Jun 19, 2023
fa9842d
testing
Tulsishah Jun 19, 2023
287b28a
testing
Tulsishah Jun 19, 2023
fad47a4
testing
Tulsishah Jun 19, 2023
cbe8a12
testing
Tulsishah Jun 19, 2023
ddac411
testing
Tulsishah Jun 19, 2023
d686fa3
small fix
Tulsishah Jun 19, 2023
b659de8
small fix
Tulsishah Jun 19, 2023
4d6d364
fixed tests
Tulsishah Jun 20, 2023
1fc7433
remove unnecessary tests
Tulsishah Jun 20, 2023
0b0a0f5
testing
Tulsishah Jun 20, 2023
6116945
testing
Tulsishah Jun 20, 2023
f36f606
testing
Tulsishah Jun 20, 2023
cd21bf9
testing
Tulsishah Jun 20, 2023
9704e59
testing
Tulsishah Jun 21, 2023
734f29e
testing
Tulsishah Jun 21, 2023
b97d7cc
resolving conflict
Tulsishah Jun 27, 2023
d60370c
small fix
Tulsishah Jun 27, 2023
05fc4f2
resolving conflict
Tulsishah Jun 27, 2023
a6751ec
removing unnecessary changes
Tulsishah Jun 27, 2023
58fc3fd
removing unnecessary changes
Tulsishah Jun 27, 2023
7c5c59b
removing unnecessary changes
Tulsishah Jun 27, 2023
19ad1ed
small fix
Tulsishah Jun 27, 2023
499b454
renaming test
Tulsishah Jun 28, 2023
277d571
Merge branch 'GoogleCloudPlatform:master' into delete_implicit_dir_in…
Tulsishah Jun 28, 2023
967ce67
renaming
Tulsishah Jun 28, 2023
588a6f2
renaming
Tulsishah Jun 28, 2023
6cb407d
using function
Tulsishah Jun 28, 2023
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
4 changes: 2 additions & 2 deletions tools/integration_tests/explicit_dir/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func TestListOnlyExplicitObjectsFromBucket(t *testing.T) {
// testBucket/explicitDirectory/fileInExplicitDir1 -- File
// testBucket/explicitDirectory/fileInExplicitDir2 -- File

implicit_and_explicit_dir_setup.CreateImplicitDirectory()
implicit_and_explicit_dir_setup.CreateExplicitDirectory(t)
implicit_and_explicit_dir_setup.CreateImplicitDirectoryStructure()
implicit_and_explicit_dir_setup.CreateExplicitDirectoryStructure(t)

err := filepath.WalkDir(setup.MntDir(), func(path string, dir fs.DirEntry, err error) error {
if err != nil {
Expand Down
140 changes: 140 additions & 0 deletions tools/integration_tests/implicit_dir/delete_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// 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.

// Provide test for deleting implicit directory.
package implicit_dir_test

import (
"path"
"testing"

"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/operations"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup/implicit_and_explicit_dir_setup"
)

// Directory Structure
// testBucket/implicitDirectory -- Dir
// testBucket/implicitDirectory/fileInImplicitDir1 -- File
// testBucket/implicitDirectory/implicitSubDirectory -- Dir
// testBucket/implicitDirectory/implicitSubDirectory/fileInImplicitDir2 -- File
func TestDeleteNonEmptyImplicitDir(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

implicit_and_explicit_dir_setup.CreateImplicitDirectoryStructure()

dirPath := path.Join(setup.MntDir(), implicit_and_explicit_dir_setup.ImplicitDirectory)

implicit_and_explicit_dir_setup.RemoveAndCheckIfDirIsDeleted(dirPath, implicit_and_explicit_dir_setup.ImplicitDirectory, t)
}

// Directory Structure
// testBucket/implicitDirectory -- Dir
// testBucket/implicitDirectory/fileInImplicitDir1 -- File
// testBucket/implicitDirectory/implicitSubDirectory -- Dir
// testBucket/implicitDirectory/implicitSubDirectory/fileInImplicitDir2 -- File
func TestDeleteNonEmptyImplicitSubDir(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

implicit_and_explicit_dir_setup.CreateImplicitDirectoryStructure()

subDirPath := path.Join(setup.MntDir(), implicit_and_explicit_dir_setup.ImplicitDirectory, implicit_and_explicit_dir_setup.ImplicitSubDirectory)
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved

implicit_and_explicit_dir_setup.RemoveAndCheckIfDirIsDeleted(subDirPath, implicit_and_explicit_dir_setup.ImplicitSubDirectory, t)
}

// Directory Structure
// testBucket/implicitDirectory -- Dir
// testBucket/implicitDirectory/explicitDirInImplicitDir -- Dir
// testBucket/implicitDirectory/explicitDirInImplicitDir/fileInExplicitDirInImplicitDir -- File
// testBucket/implicitDirectory/fileInImplicitDir1 -- File
// testBucket/implicitDirectory/implicitSubDirectory -- Dir
// testBucket/implicitDirectory/implicitSubDirectory/fileInImplicitDir2 -- File
func TestDeleteImplicitDirWithExplicitSubDir(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

implicit_and_explicit_dir_setup.CreateImplicitDirectoryStructure()

explicitDirPath := path.Join(setup.MntDir(), implicit_and_explicit_dir_setup.ImplicitDirectory, ExplicitDirInImplicitDir)

operations.CreateDirectoryWithNFiles(NumberOfFilesInExplicitDirInImplicitDir, explicitDirPath, PrefixFileInExplicitDirInImplicitDir, t)

dirPath := path.Join(setup.MntDir(), implicit_and_explicit_dir_setup.ImplicitDirectory)

implicit_and_explicit_dir_setup.RemoveAndCheckIfDirIsDeleted(dirPath, implicit_and_explicit_dir_setup.ImplicitDirectory, t)
}

// Directory Structure
// testBucket/implicitDirectory -- Dir
// testBucket/implicitDirectory/fileInImplicitDir1 -- File
// testBucket/implicitDirectory/implicitSubDirectory -- Dir
// testBucket/implicitDirectory/implicitSubDirectory/fileInImplicitDir2 -- File
// testBucket/implicitDirectory/implicitSubDirectory/explicitDirInImplicitDir -- Dir
// testBucket/implicitDirectory/implicitSubDirectory/explicitDirInImplicitDir/fileInExplicitDirInImplicitDir -- File
func TestDeleteImplicitDirWithImplicitSubDirContainingExplicitDir(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

implicit_and_explicit_dir_setup.CreateImplicitDirectoryStructure()
explicitDirPath := path.Join(setup.MntDir(), implicit_and_explicit_dir_setup.ImplicitDirectory, implicit_and_explicit_dir_setup.ImplicitSubDirectory, ExplicitDirInImplicitSubDir)

operations.CreateDirectoryWithNFiles(NumberOfFilesInExplicitDirInImplicitSubDir, explicitDirPath, PrefixFileInExplicitDirInImplicitSubDir, t)

dirPath := path.Join(setup.MntDir(), implicit_and_explicit_dir_setup.ImplicitDirectory)

implicit_and_explicit_dir_setup.RemoveAndCheckIfDirIsDeleted(dirPath, implicit_and_explicit_dir_setup.ImplicitDirectory, t)
}

// Directory Structure
// testBucket/explicitDirectory -- Dir
// testBucket/explictFile -- File
// testBucket/explicitDirectory/fileInExplicitDir1 -- File
// testBucket/explicitDirectory/fileInExplicitDir2 -- File
// testBucket/explicitDirectory/implicitDirectory -- Dir
// testBucket/explicitDirectory/implicitDirectory/fileInImplicitDir1 -- File
// testBucket/explicitDirectory/implicitDirectory/implicitSubDirectory -- Dir
// testBucket/explicitDirectory/implicitDirectory/implicitSubDirectory/fileInImplicitDir2 -- File
func TestDeleteImplicitDirInExplicitDir(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

implicit_and_explicit_dir_setup.CreateImplicitDirectoryInExplicitDirectoryStructure(t)

dirPath := path.Join(setup.MntDir(), implicit_and_explicit_dir_setup.ExplicitDirectory, implicit_and_explicit_dir_setup.ImplicitDirectory)

implicit_and_explicit_dir_setup.RemoveAndCheckIfDirIsDeleted(dirPath, implicit_and_explicit_dir_setup.ImplicitDirectory, t)
}

// Directory Structure
// testBucket/explicitDirectory -- Dir
// testBucket/explictFile -- File
// testBucket/explicitDirectory/fileInExplicitDir1 -- File
// testBucket/explicitDirectory/fileInExplicitDir2 -- File
// testBucket/explicitDirectory/implicitDirectory -- Dir
// testBucket/explicitDirectory/implicitDirectory/fileInImplicitDir1 -- File
// testBucket/explicitDirectory/implicitDirectory/implicitSubDirectory -- Dir
// testBucket/explicitDirectory/implicitDirectory/implicitSubDirectory/fileInImplicitDir2 -- File
func TestDeleteExplicitDirContainingImplicitSubDir(t *testing.T) {
// Clean the mountedDirectory before running test.
setup.CleanMntDir()

implicit_and_explicit_dir_setup.CreateImplicitDirectoryInExplicitDirectoryStructure(t)

dirPath := path.Join(setup.MntDir(), implicit_and_explicit_dir_setup.ExplicitDirectory)

implicit_and_explicit_dir_setup.RemoveAndCheckIfDirIsDeleted(dirPath, implicit_and_explicit_dir_setup.ExplicitDirectory, t)
}
7 changes: 7 additions & 0 deletions tools/integration_tests/implicit_dir/implicit_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ import (
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup/implicit_and_explicit_dir_setup"
)

const ExplicitDirInImplicitDir = "explicitDirInImplicitDir"
const ExplicitDirInImplicitSubDir = "explicitDirInImplicitSubDir"
const PrefixFileInExplicitDirInImplicitDir = "fileInExplicitDirInImplicitDir"
const PrefixFileInExplicitDirInImplicitSubDir = "fileInExplicitDirInImplicitSubDir"
const NumberOfFilesInExplicitDirInImplicitSubDir = 1
const NumberOfFilesInExplicitDirInImplicitDir = 1

func TestMain(m *testing.M) {
flags := [][]string{{"--implicit-dirs"}, {"--enable-storage-client-library=false", "--implicit-dirs"}}

Expand Down
4 changes: 2 additions & 2 deletions tools/integration_tests/implicit_dir/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func TestListImplicitObjectsFromBucket(t *testing.T) {
// testBucket/explicitDirectory/fileInExplicitDir1 -- File
// testBucket/explicitDirectory/fileInExplicitDir2 -- File

implicit_and_explicit_dir_setup.CreateImplicitDirectory()
implicit_and_explicit_dir_setup.CreateExplicitDirectory(t)
implicit_and_explicit_dir_setup.CreateImplicitDirectoryStructure()
implicit_and_explicit_dir_setup.CreateExplicitDirectoryStructure(t)

err := filepath.WalkDir(setup.MntDir(), func(path string, dir fs.DirEntry, err error) error {
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,16 @@ func RunTestsForImplicitDirAndExplicitDir(flags [][]string, m *testing.M) {
os.Exit(successCode)
}

func CreateImplicitDirectory() {
func RemoveAndCheckIfDirIsDeleted(dirPath string, dirName string, t *testing.T) {
operations.RemoveDir(dirPath)

dir, err := os.Stat(dirPath)
if err == nil && dir.Name() == dirName && dir.IsDir() {
t.Errorf("Directory is not deleted.")
}
}

func CreateImplicitDirectoryStructure() {
// Implicit Directory Structure
// testBucket/implicitDirectory -- Dir
// testBucket/implicitDirectory/fileInImplicitDir1 -- File
Expand All @@ -75,7 +84,7 @@ func CreateImplicitDirectory() {
setup.RunScriptForTestData("../util/setup/implicit_and_explicit_dir_setup/testdata/create_objects.sh", setup.TestBucket())
}

func CreateExplicitDirectory(t *testing.T) {
func CreateExplicitDirectoryStructure(t *testing.T) {
// Explicit Directory structure
// testBucket/explicitDirectory -- Dir
// testBucket/explictFile -- File
Expand All @@ -93,3 +102,18 @@ func CreateExplicitDirectory(t *testing.T) {
// Closing file at the end.
defer operations.CloseFile(file)
}

func CreateImplicitDirectoryInExplicitDirectoryStructure(t *testing.T) {
// testBucket/explicitDirectory -- Dir
// testBucket/explictFile -- File
// testBucket/explicitDirectory/fileInExplicitDir1 -- File
// testBucket/explicitDirectory/fileInExplicitDir2 -- File
// testBucket/explicitDirectory/implicitDirectory -- Dir
// testBucket/explicitDirectory/implicitDirectory/fileInImplicitDir1 -- File
// testBucket/explicitDirectory/implicitDirectory/implicitSubDirectory -- Dir
// testBucket/explicitDirectory/implicitDirectory/implicitSubDirectory/fileInImplicitDir2 -- File

CreateExplicitDirectoryStructure(t)
dirPathInBucket := path.Join(setup.TestBucket(), ExplicitDirectory)
setup.RunScriptForTestData("../util/setup/implicit_and_explicit_dir_setup/testdata/create_objects.sh", dirPathInBucket)
}