Skip to content

Commit

Permalink
Delete Directory integration tests (#1172)
Browse files Browse the repository at this point in the history
* delete integration tests

* fixing comment
  • Loading branch information
Tulsishah committed Jun 12, 2023
1 parent 6fbcee0 commit e08c26b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tools/integration_tests/operations/delete_dir_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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 delete directory.
package operations_test

import (
"os"
"path"
"testing"

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

func TestDeleteEmptyExplicitDir(t *testing.T) {
dirPath := path.Join(setup.MntDir(), EmptyExplicitDirectoryForDeleteTest)
operations.CreateDirectoryWithNFiles(0, dirPath, "", t)

err := os.RemoveAll(dirPath)
if err != nil {
t.Errorf("Error in deleting empty explicit directory.")
}

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

func TestDeleteNonEmptyExplicitDir(t *testing.T) {
dirPath := path.Join(setup.MntDir(), NonEmptyExplicitDirectoryForDeleteTest)
operations.CreateDirectoryWithNFiles(NumberOfFilesInNonEmptyExplicitDirectoryForDeleteTest, dirPath, PrefixFilesInNonEmptyExplicitDirectoryForDeleteTest, t)

subDirPath := path.Join(dirPath, NonEmptyExplicitSubDirectoryForDeleteTest)
operations.CreateDirectoryWithNFiles(NumberOfFilesInNonEmptyExplicitSubDirectoryForDeleteTest, subDirPath, PrefixFilesInNonEmptyExplicitSubDirectoryForDeleteTest, t)

err := os.RemoveAll(dirPath)
if err != nil {
t.Errorf("Error in deleting empty explicit directory.")
}

dir, err := os.Stat(dirPath)
if err == nil && dir.Name() == NonEmptyExplicitDirectoryForDeleteTest && dir.IsDir() {
t.Errorf("Directory is not deleted.")
}
}
7 changes: 7 additions & 0 deletions tools/integration_tests/operations/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ const SecondSubDirectoryForListTest = "secondSubDirectoryForListTest"
const PrefixFileInSecondSubDirectoryForListTest = "fileInSecondSubDirectoryForListTest"
const FirstFileInSecondSubDirectoryForListTest = "fileInSecondSubDirectoryForListTest1"
const SecondFileInSecondSubDirectoryForListTest = "fileInSecondSubDirectoryForListTest2"
const EmptyExplicitDirectoryForDeleteTest = "emptyExplicitDirectoryForDeleteTest"
const NonEmptyExplicitDirectoryForDeleteTest = "nonEmptyExplicitDirectoryForDeleteTest"
const NonEmptyExplicitSubDirectoryForDeleteTest = "nonEmptyExplicitSubDirectoryForDeleteTest"
const NumberOfFilesInNonEmptyExplicitDirectoryForDeleteTest = 2
const PrefixFilesInNonEmptyExplicitDirectoryForDeleteTest = "filesInNonEmptyExplicitDirectoryForDeleteTest"
const NumberOfFilesInNonEmptyExplicitSubDirectoryForDeleteTest = 1
const PrefixFilesInNonEmptyExplicitSubDirectoryForDeleteTest = "filesInNonEmptyExplicitSubDirectoryForDeleteTest"

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

0 comments on commit e08c26b

Please sign in to comment.