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

Kokoro perf test fix - Integration tests #1239

Merged
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")
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
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() {
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
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