Skip to content

Commit

Permalink
Persistent mounting integration tests (#1218)
Browse files Browse the repository at this point in the history
* adding test for persistent mounting

* adding test for persistent mounting

* adding test for persistent mounting

* adding test for persistent mounting

* Testing

* Testing

* Testing

* Testing

* Testing

* Testing

* Testing

* Testing

* Testing

* testing

* formating argument

* adding -o flag

* adding mounting test in every package

* small fix

* removing --o in

* removing --o in

* adding commands to run tests for mountedDirectory flag

* small fix

* fixing commands

* adding comment

* small fix

* small fix

* adding comment

* adding comments and small fixed

* fixing lint

* fixing merge conflict

* smallfi x

* testing

* testing

* small fix

* removing unnecessary commands

* removing extra line

* removing extra line
  • Loading branch information
Tulsishah committed Jul 20, 2023
1 parent 438869a commit 640bed7
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 8 deletions.
5 changes: 5 additions & 0 deletions tools/integration_tests/operations/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/creds_tests"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/only_dir_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/persistent_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/static_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup"
)
Expand Down Expand Up @@ -108,6 +109,10 @@ func TestMain(m *testing.M) {
successCode = only_dir_mounting.RunTests(flags, m)
}

if successCode == 0 {
successCode = persistent_mounting.RunTests(flags, m)
}

if successCode == 0 {
// Test for admin permission on test bucket.
successCode = creds_tests.RunTestsForKeyFileAndGoogleApplicationCredentialsEnvVarSet(flags, "objectAdmin", m)
Expand Down
6 changes: 6 additions & 0 deletions tools/integration_tests/readonly/readonly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"

"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/creds_tests"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/persistent_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/static_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup"
)
Expand Down Expand Up @@ -79,6 +80,11 @@ func TestMain(m *testing.M) {
setup.SetUpTestDirForTestBucketFlag()
successCode := static_mounting.RunTests(flags, m)

if successCode == 0 {
// Test for viewer permission on test bucket.
successCode = persistent_mounting.RunTests(flags, m)
}

if successCode == 0 {
// Test for viewer permission on test bucket.
successCode = creds_tests.RunTestsForKeyFileAndGoogleApplicationCredentialsEnvVarSet(flags, "objectViewer", m)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"testing"

"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/only_dir_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/persistent_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/static_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup"
)
Expand Down Expand Up @@ -59,5 +60,9 @@ func TestMain(m *testing.M) {
successCode = only_dir_mounting.RunTests(flags, m)
}

if successCode == 0 {
successCode = persistent_mounting.RunTests(flags, m)
}

os.Exit(successCode)
}
121 changes: 121 additions & 0 deletions tools/integration_tests/run_tests_mounted_directory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,107 +27,228 @@ gcsfuse --enable-storage-client-library=true --implicit-dirs=true $TEST_BUCKET_N
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o enable_storage_client_library=true,implicit_dirs=true
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

gcsfuse --enable-storage-client-library=false $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o enable_storage_client_library=false
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

gcsfuse --implicit-dirs=true $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o implicit_dirs=true
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

gcsfuse --implicit-dirs=false $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o implicit_dirs=false
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

# Run integration tests for operations with --only-dir mounting.
gcsfuse --only-dir testDir --enable-storage-client-library=true --implicit-dirs=true $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o only_dir=testDir,enable_storage_client_library=true,implicit_dirs=true
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

gcsfuse --only-dir testDir --enable-storage-client-library=false $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o only_dir=testDir,enable_storage_client_library=false
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

gcsfuse --only-dir testDir --implicit-dirs=true $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o only_dir=testDir,implicit_dirs=true
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

gcsfuse --only-dir testDir --implicit-dirs=false $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o only_dir=testDir,implicit_dirs=false
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

# Run integration tests for readonly directory with static mounting
gcsfuse --o=ro --implicit-dirs=true $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/readonly/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o ro,implicit_dirs=true
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/readonly/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
sudo umount $MOUNT_DIR

gcsfuse --file-mode=544 --dir-mode=544 --implicit-dirs=true $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/readonly/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o file_mode=544,dir_mode=544,implicit_dirs=true
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/readonly/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
sudo umount $MOUNT_DIR

# Run integration tests for readonly with --only-dir mounting.
gcsfuse --only-dir testDir --o=ro --implicit-dirs=true $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/readonly/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME/testDir
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o ro,only_dir=testDir,implicit_dirs=true
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/readonly/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME/testDir
sudo umount $MOUNT_DIR

gcsfuse --only-dir testDir --file-mode=544 --dir-mode=544 --implicit-dirs=true $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/readonly/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME/testDir
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o only_dir=testDir,file_mode=544,dir_mode=544,implicit_dirs=true
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/readonly/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME/testDir
sudo umount $MOUNT_DIR

# Run integration tests for rename_dir_limit directory with static mounting
gcsfuse --rename-dir-limit=3 --implicit-dirs $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/rename_dir_limit/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o rename_dir_limit=3,implicit_dirs
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/rename_dir_limit/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

gcsfuse --rename-dir-limit=3 $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/rename_dir_limit/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o rename_dir_limit=3
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/rename_dir_limit/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

# Run integration tests for rename_dir_limit with --only-dir mounting.
gcsfuse --only-dir testDir --rename-dir-limit=3 --implicit-dirs $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/rename_dir_limit/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o only_dir=testDir,rename_dir_limit=3,implicit_dirs
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/rename_dir_limit/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

gcsfuse --only-dir testDir --rename-dir-limit=3 $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/rename_dir_limit/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o only_dir=testDir,rename_dir_limit=3,implicit_dirs
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/rename_dir_limit/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR
sudo umount $MOUNT_DIR

# Run integration tests for implicit_dir directory with static mounting
gcsfuse --implicit-dirs $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/implicit_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o implicit_dirs
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/implicit_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
sudo umount $MOUNT_DIR

gcsfuse --enable-storage-client-library=false --implicit-dirs $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/implicit_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o enable_storage_client_library=false,implicit_dirs
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/implicit_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
sudo umount $MOUNT_DIR


# Run integration tests for implicit_dir with --only-dir mounting.
gcsfuse --only-dir testDir --implicit-dirs $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/implicit_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME/testDir
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o only_dir=testDir,implicit_dirs
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/implicit_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME/testDir
sudo umount $MOUNT_DIR

gcsfuse --only-dir testDir --enable-storage-client-library=false --implicit-dirs $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/implicit_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME/testDir
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o only_dir=testDir,enable_storage_client_library=false,implicit_dirs
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/implicit_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME/testDir
sudo umount $MOUNT_DIR

# Run integration tests for explicit_dir directory with static mounting
gcsfuse --enable-storage-client-library=true $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/explicit_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o enable_storage_client_library=true
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/explicit_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
sudo umount $MOUNT_DIR

gcsfuse --enable-storage-client-library=false $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/explicit_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o enable_storage_client_library=false
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/explicit_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
sudo umount $MOUNT_DIR

# Run integration tests for explicit_dir with --only-dir mounting.
gcsfuse --only-dir testDir --enable-storage-client-library=true $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/explicit_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME/testDir
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o only_dir=testDir,enable_storage_client_library=true
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/explicit_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME/testDir
sudo umount $MOUNT_DIR

gcsfuse --only-dir testDir --enable-storage-client-library=false $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/explicit_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME/testDir
sudo umount $MOUNT_DIR

# Run test with persistent mounting
mount.gcsfuse $TEST_BUCKET_NAME $MOUNT_DIR -o only_dir=testDir,enable_storage_client_library=false
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/explicit_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME/testDir
sudo umount $MOUNT_DIR

# Run integration tests for list_large_dir directory with static mounting
gcsfuse --implicit-dirs $TEST_BUCKET_NAME $MOUNT_DIR
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/list_large_dir/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME
Expand Down
4 changes: 2 additions & 2 deletions tools/integration_tests/util/mounting/mounting.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup"
)

func MountGcsfuse(flags []string) error {
func MountGcsfuse(binaryFile string, flags []string) error {
mountCmd := exec.Command(
setup.BinFile(),
binaryFile,
flags...,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func mountGcsfuseWithOnlyDir(flags []string, dir string) (err error) {
flags = append(flags, defaultArg[i])
}

err = mounting.MountGcsfuse(flags)
err = mounting.MountGcsfuse(setup.BinFile(), flags)

return err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//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 persistent_mounting

import (
"fmt"
"log"
"strings"
"testing"

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

// make e.g --enable-storage-client-library in enable_storage_client_library
func makePersistentMountingArgs(flags []string) (args []string, err error) {
var s string
for i := range flags {
// We are already passing flags with -o flag.
s = strings.Replace(flags[i], "--o=", "", -1)
// e.g. Convert --enable-storage-client-library to __enable_storage_client_library
s = strings.Replace(s, "-", "_", -1)
// e.g. Convert __enable_storage_client_library to enable_storage_client_library
s = strings.Replace(s, "__", "", -1)
args = append(args, s)
}
return
}

func mountGcsfuseWithStaticMounting(flags []string) (err error) {
defaultArg := []string{setup.TestBucket(),
setup.MntDir(),
"-o",
"debug_gcs",
"-o",
"debug_fs",
"-o",
"debug_fuse",
"-o",
"log_file=" + setup.LogFile(),
"-o",
"log_format=text",
}

persistentMountingArgs, err := makePersistentMountingArgs(flags)
if err != nil {
setup.LogAndExit("Error in converting flags for persistent mounting.")
}

for i := 0; i < len(persistentMountingArgs); i++ {
// e.g. -o flag1, -o flag2, ...
defaultArg = append(defaultArg, "-o", persistentMountingArgs[i])
}

err = mounting.MountGcsfuse(setup.SbinFile(), defaultArg)

return err
}

func executeTestsForStatingMounting(flags [][]string, m *testing.M) (successCode int) {
var err error

for i := 0; i < len(flags); i++ {
if err = mountGcsfuseWithStaticMounting(flags[i]); err != nil {
setup.LogAndExit(fmt.Sprintf("mountGcsfuse: %v\n", err))
}
setup.ExecuteTestForFlagsSet(flags[i], m)
}
return
}

func RunTests(flags [][]string, m *testing.M) (successCode int) {
successCode = executeTestsForStatingMounting(flags, m)

log.Printf("Test log: %s\n", setup.LogFile())

return successCode
}

0 comments on commit 640bed7

Please sign in to comment.