-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Running all the integration test with --only-dir mounting (#1100)
* adding --only-dir mounting in integration tests * updating function name and removing unnecessary files * Upating comments * linux tests * local changes * renaming directory * fixing merge conflict * fixing merge conflict * small fix * adding test case where directory exist in only dir mounting * adding test case where directory exist in only dir mounting * new line * adding licence * fixed comments * fixing comments * formating * fixing lint tests * fixing comments * fixing comments * fixing lint tests * fixing lint tests * small fix * small fix * updating functions name * small fix * adding comment * adding comment * fixing comments * resolving comments * fixed comments
- Loading branch information
Showing
13 changed files
with
353 additions
and
85 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
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
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
14 changes: 14 additions & 0 deletions
14
tools/integration_tests/readonly/testdata/create_objects.sh
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
14 changes: 14 additions & 0 deletions
14
tools/integration_tests/readonly/testdata/delete_objects.sh
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
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,50 @@ | ||
// 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. | ||
|
||
package mounting | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup" | ||
) | ||
|
||
func MountGcsfuse(flags []string) error { | ||
mountCmd := exec.Command( | ||
setup.BinFile(), | ||
flags..., | ||
) | ||
|
||
// Adding mount command in LogFile | ||
file, err := os.OpenFile(setup.LogFile(), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) | ||
if err != nil { | ||
fmt.Println("Could not open logfile") | ||
} | ||
defer file.Close() | ||
|
||
_, err = file.WriteString(mountCmd.String() + "\n") | ||
if err != nil { | ||
fmt.Println("Could not write cmd to logFile") | ||
} | ||
|
||
_, err = mountCmd.CombinedOutput() | ||
if err != nil { | ||
log.Println(mountCmd.String()) | ||
return fmt.Errorf("cannot mount gcsfuse: %w\n", err) | ||
} | ||
return nil | ||
} |
91 changes: 91 additions & 0 deletions
91
tools/integration_tests/util/mounting/only_dir_mounting/only_dir_mounting.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,91 @@ | ||
// 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. | ||
|
||
package only_dir_mounting | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"path" | ||
"testing" | ||
|
||
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting" | ||
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup" | ||
) | ||
|
||
const DirectoryInTestBucket = "Test" | ||
|
||
func mountGcsfuseWithOnlyDir(flags []string, dir string) (err error) { | ||
defaultArg := []string{"--only-dir", | ||
dir, | ||
"--debug_gcs", | ||
"--debug_fs", | ||
"--debug_fuse", | ||
"--log-file=" + setup.LogFile(), | ||
"--log-format=text", | ||
setup.TestBucket(), | ||
setup.MntDir()} | ||
|
||
for i := 0; i < len(defaultArg); i++ { | ||
flags = append(flags, defaultArg[i]) | ||
} | ||
|
||
err = mounting.MountGcsfuse(flags) | ||
|
||
return err | ||
} | ||
|
||
func mountGcsFuseForFlagsAndExecuteTests(flags [][]string, dir string, m *testing.M) (successCode int) { | ||
for i := 0; i < len(flags); i++ { | ||
if err := mountGcsfuseWithOnlyDir(flags[i], dir); err != nil { | ||
setup.LogAndExit(fmt.Sprintf("mountGcsfuse: %v\n", err)) | ||
} | ||
successCode = setup.ExecuteTestForFlagsSet(flags[i], m) | ||
} | ||
return | ||
} | ||
|
||
func executeTestsForOnlyDirMounting(flags [][]string, m *testing.M) (successCode int) { | ||
setup.SetUpTestDirForTestBucketFlag() | ||
|
||
mountDirInBucket := path.Join(setup.TestBucket(), DirectoryInTestBucket) | ||
// Clean the bucket. | ||
|
||
setup.RunScriptForTestData("../util/mounting/only_dir_mounting/testdata/delete_objects.sh", setup.TestBucket()) | ||
|
||
// "Test" directory not exist in bucket. | ||
mountGcsFuseForFlagsAndExecuteTests(flags, DirectoryInTestBucket, m) | ||
|
||
// "Test" directory exist in bucket. | ||
// Clean the bucket. | ||
setup.RunScriptForTestData("../util/mounting/only_dir_mounting/testdata/delete_objects.sh", setup.TestBucket()) | ||
|
||
// Create Test directory in bucket. | ||
setup.RunScriptForTestData("../util/mounting/only_dir_mounting/testdata/create_objects.sh", mountDirInBucket) | ||
|
||
successCode = mountGcsFuseForFlagsAndExecuteTests(flags, DirectoryInTestBucket, m) | ||
|
||
// Clean the bucket after testing. | ||
setup.RunScriptForTestData("../util/mounting/only_dir_mounting/testdata/delete_objects.sh", setup.TestBucket()) | ||
|
||
return | ||
} | ||
|
||
func RunTests(flags [][]string, m *testing.M) (successCode int) { | ||
successCode = executeTestsForOnlyDirMounting(flags, m) | ||
|
||
log.Printf("Test log: %s\n", setup.LogFile()) | ||
|
||
return successCode | ||
} |
16 changes: 16 additions & 0 deletions
16
tools/integration_tests/util/mounting/only_dir_mounting/testdata/create_objects.sh
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,16 @@ | ||
# 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. | ||
|
||
touch a.txt | ||
gsutil mv a.txt gs://$1/ |
22 changes: 22 additions & 0 deletions
22
tools/integration_tests/util/mounting/only_dir_mounting/testdata/delete_objects.sh
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,22 @@ | ||
# 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. | ||
|
||
# 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 |
Oops, something went wrong.