Skip to content

Commit

Permalink
Kokoro perf test fix - Integration tests (#1239)
Browse files Browse the repository at this point in the history
* testing

* testing

* testing

* adding comment for a reason

* creating function to copy dir with root permission

* common function

* fix

* testing

* revert changes

* revert changes

* adding remove package

* adding remove package
  • Loading branch information
Tulsishah authored Jul 22, 2023
1 parent 1c93102 commit a30308e
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 3 deletions.
2 changes: 2 additions & 0 deletions tools/integration_tests/list_large_dir/list_large_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@ func TestMain(m *testing.M) {

successCode := static_mounting.RunTests(flags, m)

setup.RemoveBinFileCopiedForTesting()

os.Exit(successCode)
}
2 changes: 2 additions & 0 deletions tools/integration_tests/operations/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,7 @@ func TestMain(m *testing.M) {
successCode = creds_tests.RunTestsForKeyFileAndGoogleApplicationCredentialsEnvVarSet(flags, "objectAdmin", m)
}

setup.RemoveBinFileCopiedForTesting()

os.Exit(successCode)
}
2 changes: 2 additions & 0 deletions tools/integration_tests/readonly/readonly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,7 @@ func TestMain(m *testing.M) {
// Delete objects from bucket after testing.
setup.RunScriptForTestData("testdata/delete_objects.sh", setup.TestBucket())

setup.RemoveBinFileCopiedForTesting()

os.Exit(successCode)
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,7 @@ func TestMain(m *testing.M) {
successCode = persistent_mounting.RunTests(flags, m)
}

setup.RemoveBinFileCopiedForTesting()

os.Exit(successCode)
}
20 changes: 17 additions & 3 deletions tools/integration_tests/util/operations/dir_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,30 @@ import (
const FilePermission_0600 = 0600
const FilePermission_0777 = 0777

func CopyDir(srcDirPath string, destDirPath string) (err error) {
cmd := exec.Command("cp", "--recursive", srcDirPath, destDirPath)

func executeCommandForCopyOperation(cmd *exec.Cmd) (err error) {
err = cmd.Run()
if err != nil {
err = fmt.Errorf("Copying dir operation is failed: %v", err)
}
return
}

func CopyDir(srcDirPath string, destDirPath string) (err error) {
cmd := exec.Command("cp", "--recursive", srcDirPath, destDirPath)

err = executeCommandForCopyOperation(cmd)

return
}

func CopyDirWithRootPermission(srcDirPath string, destDirPath string) (err error) {
cmd := exec.Command("sudo", "cp", "--recursive", srcDirPath, destDirPath)

err = executeCommandForCopyOperation(cmd)

return
}

func MoveDir(srcDirPath string, destDirPath string) (err error) {
cmd := exec.Command("mv", srcDirPath, destDirPath)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func RunTestsForImplicitDirAndExplicitDir(flags [][]string, m *testing.M) {
successCode = persistent_mounting.RunTests(flags, m)
}

setup.RemoveBinFileCopiedForTesting()

os.Exit(successCode)
}

Expand Down
19 changes: 19 additions & 0 deletions tools/integration_tests/util/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ func SetUpTestDir() error {
}
binFile = path.Join(TestDir(), "bin/gcsfuse")
sbinFile = path.Join(TestDir(), "sbin/mount.gcsfuse")

// mount.gcsfuse will find gcsfuse executable in mentioned locations.
// https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/tools/mount_gcsfuse/find.go#L59
// Copying the executable to /usr/local/bin
err := operations.CopyDirWithRootPermission(binFile, "/usr/local/bin")
if err != nil {
log.Printf("Error in copying bin file:%v", err)
}
} else {
// when testInstalledPackage flag is set, gcsfuse is preinstalled on the
// machine. Hence, here we are overwriting binFile to gcsfuse.
Expand All @@ -164,6 +172,17 @@ func SetUpTestDir() error {
return nil
}

// Removing bin file after testing.
func RemoveBinFileCopiedForTesting() {
if !TestInstalledPackage() {
cmd := exec.Command("sudo", "rm", "/usr/local/bin/gcsfuse")
err := cmd.Run()
if err != nil {
log.Printf("Error in removing file:%v", err)
}
}
}

func UnMount() error {
fusermount, err := exec.LookPath("fusermount")
if err != nil {
Expand Down

0 comments on commit a30308e

Please sign in to comment.