diff --git a/test/e2e/testsuite/testsuite.go b/test/e2e/testsuite/testsuite.go index fc61c1621f..2f26177347 100644 --- a/test/e2e/testsuite/testsuite.go +++ b/test/e2e/testsuite/testsuite.go @@ -22,7 +22,6 @@ import ( ) var ( - CRCHome string CRCExecutable string userProvidedBundle bool bundleName string @@ -61,7 +60,7 @@ func InitializeTestSuite(tctx *godog.TestSuiteContext) { } usr, _ := user.Current() - CRCHome = filepath.Join(usr.HomeDir, ".crc") + util.CRCHome = filepath.Join(usr.HomeDir, ".crc") // init CRCExecutable if no location provided by user if CRCExecutable == "" { @@ -108,7 +107,7 @@ func InitializeTestSuite(tctx *godog.TestSuiteContext) { if cleanupHome { // remove $HOME/.crc - err = util.RemoveCRCHome(CRCHome) + err = util.RemoveCRCHome() if err != nil { fmt.Println(err) os.Exit(1) @@ -452,7 +451,7 @@ func InitializeScenario(s *godog.ScenarioContext) { // CRC related steps s.Step(`^removing CRC home directory succeeds$`, - RemoveCRCHome) + util.RemoveCRCHome) s.Step(`^starting CRC with default bundle (succeeds|fails)$`, StartCRCWithDefaultBundleSucceedsOrFails) s.Step(`^starting CRC with custom bundle (succeeds|fails)$`, @@ -538,10 +537,6 @@ func WaitForClusterInState(state string) error { return crcCmd.WaitForClusterInState(state) } -func RemoveCRCHome() error { - return util.RemoveCRCHome(CRCHome) -} - func CheckHTTPResponseWithRetry(retryCount int, retryWait string, address string, expectedStatusCode int) error { var err error @@ -610,7 +605,7 @@ func CheckCRCStatus(state string) error { func DeleteFileFromCRCHome(fileName string) error { - theFile := filepath.Join(CRCHome, fileName) + theFile := filepath.Join(util.CRCHome, fileName) if _, err := os.Stat(theFile); os.IsNotExist(err) { return nil @@ -624,7 +619,7 @@ func DeleteFileFromCRCHome(fileName string) error { func FileExistsInCRCHome(fileName string) error { - theFile := filepath.Join(CRCHome, fileName) + theFile := filepath.Join(util.CRCHome, fileName) _, err := os.Stat(theFile) if os.IsNotExist(err) { @@ -668,7 +663,7 @@ func ConfigFileInCRCHomeContainsKeyMatchingValue(format string, configFile strin if expectedValue == "current bundle" { expectedValue = fmt.Sprintf(".*%s", bundleName) } - configPath := filepath.Join(CRCHome, configFile) + configPath := filepath.Join(util.CRCHome, configFile) config, err := util.GetFileContent(configPath) if err != nil { @@ -694,7 +689,7 @@ func ConfigFileInCRCHomeContainsKeyMatchingValue(format string, configFile strin func ConfigFileInCRCHomeContainsKey(format string, configFile string, condition string, keyPath string) error { - configPath := filepath.Join(CRCHome, configFile) + configPath := filepath.Join(util.CRCHome, configFile) config, err := util.GetFileContent(configPath) if err != nil { @@ -854,7 +849,7 @@ func EnsureUserIsLoggedIntoClusterSucceedsOrFails(expected string) error { func SetConfigPropertyToValueSucceedsOrFails(property string, value string, expected string) error { if value == "current bundle" { if !userProvidedBundle { - value = filepath.Join(CRCHome, "cache", bundleName) + value = filepath.Join(util.CRCHome, "cache", bundleName) } else { value = bundleLocation } diff --git a/test/extended/util/util.go b/test/extended/util/util.go index 6cf218ab47..2db92e70c5 100644 --- a/test/extended/util/util.go +++ b/test/extended/util/util.go @@ -4,7 +4,6 @@ import ( "fmt" "io" "os" - "os/user" "path/filepath" "runtime" "strings" @@ -15,6 +14,10 @@ import ( "github.com/crc-org/crc/pkg/download" ) +var ( + CRCHome string +) + func CopyFilesToTestDir() error { cwd, err := os.Getwd() if err != nil { @@ -127,23 +130,23 @@ func DownloadBundle(bundleLocation string, bundleDestination string, bundleName return filename, nil } -func RemoveCRCHome(crcHome string) error { - keepFile := filepath.Join(crcHome, ".keep") +func RemoveCRCHome() error { + keepFile := filepath.Join(CRCHome, ".keep") _, err := os.Stat(keepFile) if err != nil { // cannot get keepFile's status - err = os.RemoveAll(crcHome) + err = os.RemoveAll(CRCHome) if err != nil { - fmt.Printf("Problem deleting CRC home folder %s.\n", crcHome) + fmt.Printf("Problem deleting CRC home folder %s.\n", CRCHome) return err } - fmt.Printf("Deleted CRC home folder %s.\n", crcHome) + fmt.Printf("Deleted CRC home folder %s.\n", CRCHome) return nil } // keepFile exists - return fmt.Errorf("folder %s not removed as per request: %s present", crcHome, keepFile) + return fmt.Errorf("folder %s not removed as per request: %s present", CRCHome, keepFile) } // MatchWithRetry will execute match function with expression as arg @@ -180,11 +183,7 @@ func MatchRepetitionsWithRetry(expression string, match func(string) error, matc // GetBundlePath returns a path to the cached bundle, depending on the preset func GetBundlePath(preset preset.Preset) string { - - usr, _ := user.Current() - crcHome := filepath.Join(usr.HomeDir, ".crc") - bundle := constants.GetDefaultBundle(preset) - return filepath.Join(crcHome, "cache", bundle) + return filepath.Join(CRCHome, "cache", bundle) }