Skip to content

Commit

Permalink
updated flag to assume preinstalled package
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeenkaur committed May 31, 2023
1 parent 66d9904 commit bffd862
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 70 deletions.
2 changes: 1 addition & 1 deletion tools/integration_tests/mounting/gcsfuse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func init() { RegisterTestSuite(&GcsfuseTest{}) }
func (t *GcsfuseTest) SetUp(_ *TestInfo) {
var err error
t.gcsfusePath = path.Join(gBuildDir, "bin/gcsfuse")
if *setup.TestPackagePath != "" {
if *setup.TestInstalledPackage {
t.gcsfusePath = "gcsfuse"
}
// Set up the temporary directory.
Expand Down
8 changes: 1 addition & 7 deletions tools/integration_tests/mounting/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,12 @@ func TestMain(m *testing.M) {
}

// Build into that directory.
if *setup.TestPackagePath == "" {
if !*setup.TestInstalledPackage {
err = util.BuildGcsfuse(gBuildDir)
if err != nil {
log.Fatalf("buildGcsfuse: %p", err)
return
}
} else {
err = setup.SetUpTestPackage(gBuildDir)
if err != nil {
log.Fatalf("SetUpTestPackage():%p", err)
return
}
}

// Run tests.
Expand Down
6 changes: 3 additions & 3 deletions tools/integration_tests/mounting/mount_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ func (t *MountHelperTest) SetUp(_ *TestInfo) {
switch runtime.GOOS {
case "darwin":
t.helperPath = path.Join(gBuildDir, "sbin/mount_gcsfuse")
if *setup.TestPackagePath != "" {
if *setup.TestInstalledPackage {
t.helperPath = "/sbin/mount_gcsfuse"
}

case "linux":
t.helperPath = path.Join(gBuildDir, "sbin/mount.gcsfuse")
if *setup.TestPackagePath != "" {
if *setup.TestInstalledPackage {
t.helperPath = "/sbin/mount.gcsfuse"
}

Expand Down Expand Up @@ -258,7 +258,7 @@ func (t *MountHelperTest) FuseSubtype() {

// Mount using the tool that would be invoked by ~mount -t fuse.gcsfuse`.
t.helperPath = path.Join(gBuildDir, "sbin/mount.fuse.gcsfuse")
if *setup.TestPackagePath != "" {
if *setup.TestInstalledPackage {
t.helperPath = "/sbin/mount.fuse.gcsfuse"
}
args := []string{canned.FakeBucketName, t.dir}
Expand Down
5 changes: 4 additions & 1 deletion tools/integration_tests/util/mounting/mounting.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ func MountGcsfuse(flags []string) error {
flags...,
)

if *setup.TestPackagePath != "" {
// If TestInstalledPackage flag is set, it is assumed that gcsfuse is
// preinstalled on the machine. Hence, here we are overwriting the mount
// command to use gcsfuse instead os using tempDir/bin/gcsfuse.
if *setup.TestInstalledPackage {
mountCmd = exec.Command(
"gcsfuse",
flags...,
Expand Down
61 changes: 3 additions & 58 deletions tools/integration_tests/util/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
var testBucket = flag.String("testbucket", "", "The GCS bucket used for the test.")
var mountedDirectory = flag.String("mountedDirectory", "", "The GCSFuse mounted directory used for the test.")
var integrationTest = flag.Bool("integrationTest", false, "Run tests only when the flag value is true.")
var TestPackagePath = flag.String("testPackagePath", "", "[Optional] Run test on the package pointed by the path value provided on this flag. By default, integration tests builds a new package to run the tests.")
var TestInstalledPackage = flag.Bool("testInstalledPackage", false, "[Optional] Run tests on the package pre-installed on the host machine. By default, integration tests build a new package to run the tests.")

const BufferSize = 100
const FilePermission_0600 = 0600
Expand Down Expand Up @@ -122,75 +122,20 @@ func CreateTempFile() string {
return fileName
}

func setUpDebPackage() error {
cmd := exec.Command("sudo", "apt", "install", *TestPackagePath)
err := cmd.Run()
if err != nil {
return fmt.Errorf("failed to install debian pkg, err: %w", err)
}
return nil
}

func setUpRpmPackage() error {
cmd := exec.Command("sudo", "rpm", "-i", *TestPackagePath)
err := cmd.Run()
if err != nil {
return fmt.Errorf("failed to install rpm pkg, err: %w", err)
}
return nil
}

func SetUpTestPackage(destDir string) error {
_, err := os.Stat(*TestPackagePath)
if err != nil {
return fmt.Errorf("invalid TestPackagePath %s : err: %w", *TestPackagePath, err)
}

rpmPkgFound := false
debPkgFound := false
testPkg := *TestPackagePath
ext := testPkg[len(testPkg)-3:]
if ext == "rpm" {
rpmPkgFound = true
} else if ext == "deb" {
debPkgFound = true
}
if !rpmPkgFound && !debPkgFound {
return fmt.Errorf("%s path doesn't point to rpm or deb package: err: %w", *TestPackagePath, err)
}

cmd := exec.Command("cp", *TestPackagePath, destDir)
err = cmd.Run()
if err != nil {
return fmt.Errorf("failed to copy package from %s: err: %w", *TestPackagePath, err)
}

if debPkgFound {
return setUpDebPackage()
} else {
return setUpRpmPackage()
}
}

func SetUpTestDir() error {
var err error
testDir, err = os.MkdirTemp("", "gcsfuse_readwrite_test_")
if err != nil {
return fmt.Errorf("TempDir: %w\n", err)
}

if *TestPackagePath == "" {
if !*TestInstalledPackage {
err = util.BuildGcsfuse(testDir)
if err != nil {
return fmt.Errorf("BuildGcsfuse(%q): %w\n", TestDir(), err)
}
} else {
err = SetUpTestPackage(TestDir())
if err != nil {
return fmt.Errorf("SetUpTestPackage():%w\n", err)
}
binFile = path.Join(TestDir(), "bin/gcsfuse")
}
binFile = path.Join(TestDir(), "bin/gcsfuse")
logFile = path.Join(TestDir(), "gcsfuse.log")
mntDir = path.Join(TestDir(), "mnt")

Expand Down

0 comments on commit bffd862

Please sign in to comment.