Skip to content

Commit

Permalink
Revert "Merge pull request #2941 from ActiveState/DX-2285"
Browse files Browse the repository at this point in the history
This reverts commit 91f0fd8, reversing
changes made to 372e2a8.
  • Loading branch information
MDrakos committed Jan 9, 2024
1 parent 8d0c9e7 commit 2994d0c
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 185 deletions.
3 changes: 0 additions & 3 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,3 @@ const PlatformApiPrintRequestsEnvVarName = "ACTIVESTATE_CLI_PLATFORM_API_PRINT_R

// ActiveStateCIEnvVarName is the environment variable set when running in an ActiveState CI environment.
const ActiveStateCIEnvVarName = "ACTIVESTATE_CI"

// OverrideSandbox is the environment variable to set when overriding the sandbox for integration tests.
const OverrideSandbox = "ACTIVESTATE_TEST_OVERRIDE_SANDBOX"
4 changes: 3 additions & 1 deletion internal/osutils/exeutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ func ExecSimpleFromDir(dir, bin string, args []string, env []string) (string, st

// Execute will run the given command and with optional settings for the exec.Cmd struct
func Execute(command string, arg []string, optSetter func(cmd *exec.Cmd) error) (int, *exec.Cmd, error) {
logging.Debug("Executing command: %s, %v", command, arg)

cmd := exec.Command(command, arg...)
logging.Debug("Executing command: %s, with args: %s", cmd, arg)

if optSetter != nil {
if err := optSetter(cmd); err != nil {
return -1, nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/osutils/osutils_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func BashifyPathEnv(pathList string) (string, error) {
cmd.Env = []string{"PATH=" + pathList}
bashified, err := cmd.Output()
if err != nil {
return "", errs.Wrap(err, "Unable to bashify PATH: %s, output: %s", pathList, string(bashified))
return "", errs.Wrap(err, "Unable to bashify PATH: %s", pathList)
}
return string(bashified), nil
}
Expand Down
4 changes: 0 additions & 4 deletions internal/testhelpers/e2e/dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ type Dirs struct {
SockRoot string
// HomeDir is used as the test user's home directory
HomeDir string
// TempDir is the directory where temporary files are stored
TempDir string
}

// NewDirs creates all temporary directories
Expand All @@ -44,7 +42,6 @@ func NewDirs(base string) (*Dirs, error) {
defaultBin := filepath.Join(base, "cache", "bin")
sockRoot := filepath.Join(base, "sock")
homeDir := filepath.Join(base, "home")
tempDir := filepath.Join(base, "temp")

subdirs := []string{config, cache, bin, work, defaultBin}
for _, subdir := range subdirs {
Expand All @@ -62,7 +59,6 @@ func NewDirs(base string) (*Dirs, error) {
DefaultBin: defaultBin,
SockRoot: sockRoot,
HomeDir: homeDir,
TempDir: tempDir,
}

return &dirs, nil
Expand Down
93 changes: 0 additions & 93 deletions internal/testhelpers/e2e/env.go

This file was deleted.

17 changes: 0 additions & 17 deletions internal/testhelpers/e2e/env_unix.go

This file was deleted.

46 changes: 0 additions & 46 deletions internal/testhelpers/e2e/env_windows.go

This file was deleted.

65 changes: 61 additions & 4 deletions internal/testhelpers/e2e/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,57 @@ func New(t *testing.T, retainDirs bool, extraEnv ...string) *Session {
func new(t *testing.T, retainDirs, updatePath bool, extraEnv ...string) *Session {
dirs, err := NewDirs("")
require.NoError(t, err)
env := sandboxedTestEnvironment(t, dirs, updatePath)
var env []string
env = append(env, os.Environ()...)
env = append(env, []string{
constants.ConfigEnvVarName + "=" + dirs.Config,
constants.CacheEnvVarName + "=" + dirs.Cache,
constants.DisableRuntime + "=true",
constants.ProjectEnvVarName + "=",
constants.E2ETestEnvVarName + "=true",
constants.DisableUpdates + "=true",
constants.DisableProjectMigrationPrompt + "=true",
constants.OptinUnstableEnvVarName + "=true",
constants.ServiceSockDir + "=" + dirs.SockRoot,
constants.HomeEnvVarName + "=" + dirs.HomeDir,
"NO_COLOR=true",
}...)

if updatePath {
// add bin path
// Remove release state tool installation from PATH in tests
// This is a workaround as our test sessions are not compeltely
// sandboxed. This should be addressed in: https://activestatef.atlassian.net/browse/DX-2285
oldPath, _ := os.LookupEnv("PATH")
installPath, err := installation.InstallPathForChannel("release")
require.NoError(t, err)

binPath := filepath.Join(installPath, "bin")
oldPath = strings.Replace(oldPath, binPath+string(os.PathListSeparator), "", -1)
newPath := fmt.Sprintf(
"PATH=%s%s%s",
dirs.Bin, string(os.PathListSeparator), oldPath,
)
env = append(env, newPath)
t.Setenv("PATH", newPath)

cfg, err := config.New()
require.NoError(t, err)

// In order to ensure that the release state tool does not appear on the PATH
// when a new subshell is started we remove the installation entries from the
// rc file. This is added back later in the session's Close method.
// Again, this is a workaround to be addressed in: https://activestatef.atlassian.net/browse/DX-2285
if runtime.GOOS != "windows" {
s := bash.SubShell{}
err = s.CleanUserEnv(cfg, sscommon.InstallID, false)
require.NoError(t, err)
}
t.Setenv(constants.HomeEnvVarName, dirs.HomeDir)
}

// add session environment variables
env = append(env, extraEnv...)

session := &Session{Dirs: dirs, Env: env, retainDirs: retainDirs, T: t}

Expand All @@ -182,6 +232,14 @@ func new(t *testing.T, retainDirs, updatePath bool, extraEnv ...string) *Session
session.SvcExe = session.copyExeToBinDir(svcExe)
session.ExecutorExe = session.copyExeToBinDir(execExe)

// Set up environment for test runs. This is separate
// from the environment for the session itself.
// Setting environment variables here allows helper
// functions access to them.
// This is a workaround as our test sessions are not compeltely
// sandboxed. This should be addressed in: https://activestatef.atlassian.net/browse/DX-2285
t.Setenv(constants.HomeEnvVarName, dirs.HomeDir)

err = fileutils.Touch(filepath.Join(dirs.Base, installation.InstallDirMarker))
require.NoError(session.T, err)

Expand Down Expand Up @@ -295,6 +353,7 @@ func (s *Session) SpawnCmdWithOpts(exe string, optSetters ...SpawnOptSetter) *Sp
cmd := exec.Command(shell, args...)

cmd.Env = spawnOpts.Env

if spawnOpts.Dir != "" {
cmd.Dir = spawnOpts.Dir
}
Expand Down Expand Up @@ -712,8 +771,6 @@ func (s *Session) SetupRCFile() {
if runtime.GOOS == "windows" {
return
}
s.T.Setenv("HOME", s.Dirs.HomeDir)
defer s.T.Setenv("HOME", os.Getenv("HOME"))

cfg, err := config.New()
require.NoError(s.T, err)
Expand All @@ -732,7 +789,7 @@ func (s *Session) SetupRCFileCustom(subshell subshell.SubShell) {
if fileutils.TargetExists(filepath.Join(s.Dirs.HomeDir, filepath.Base(rcFile))) {
err = fileutils.CopyFile(rcFile, filepath.Join(s.Dirs.HomeDir, filepath.Base(rcFile)))
} else {
err = fileutils.Touch(filepath.Join(s.Dirs.HomeDir, filepath.Base(rcFile)))
err = fileutils.Touch(rcFile)
}
require.NoError(s.T, err)
}
Expand Down
6 changes: 3 additions & 3 deletions test/integration/activate_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ func (suite *ActivateIntegrationTestSuite) TestActivateUsingCommitID() {

cp := ts.SpawnWithOpts(
e2e.OptArgs("activate", "ActiveState-CLI/Python3#6d9280e7-75eb-401a-9e71-0d99759fbad3", "--path", ts.Dirs.Work),
e2e.OptAppendEnv(constants.DisableRuntime+"=false"),
)
cp.Expect("Activated", e2e.RuntimeSourcingTimeoutOpt)
cp.ExpectInput()
cp.Expect("Skipping runtime setup")
cp.Expect("Activated")
cp.ExpectInput(termtest.OptExpectTimeout(10 * time.Second))

cp.SendLine("exit")
cp.ExpectExitCode(0)
Expand Down
22 changes: 17 additions & 5 deletions test/integration/install_scripts_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ func (suite *InstallScriptsIntegrationTestSuite) TestInstall() {
suite.Require().NoError(fileutils.WriteFile(script, b))

// Construct installer command to execute.
installDir := filepath.Join(ts.Dirs.Work, "install")
argsPlain := []string{script}
argsPlain = append(argsPlain, "-t", installDir)
if tt.Channel != "" {
argsPlain = append(argsPlain, "-b", tt.Channel)
}
Expand Down Expand Up @@ -118,6 +116,20 @@ func (suite *InstallScriptsIntegrationTestSuite) TestInstall() {
cp.Expect("ActiveState")
}

// We get the default install path and use that to directly invoke
// the state tool. This is to avoid inadvertently using the state
// tool that is already on the PATH.
installPath, err := installation.InstallPathForChannel(constants.ChannelName)
suite.NoError(err)

binPath := filepath.Join(installPath, "bin")

if runtime.GOOS != "windows" {
cp.SendLine("echo $PATH")
} else {
cp.SendLine("echo %PATH%")
}
cp.Expect(installPath)
cp.SendLine("state --version")
cp.Expect("Version " + constants.Version)
cp.Expect("Channel " + constants.ChannelName)
Expand All @@ -126,12 +138,12 @@ func (suite *InstallScriptsIntegrationTestSuite) TestInstall() {

cp.ExpectExitCode(0)

stateExec, err := installation.StateExecFromDir(installDir)
stateExec, err := installation.StateExecFromDir(ts.Dirs.HomeDir)
suite.NoError(err)
suite.FileExists(stateExec)

suite.assertBinDirContents(filepath.Join(installDir, "bin"))
suite.assertCorrectVersion(ts, installDir, tt.Version, tt.Channel)
suite.assertBinDirContents(binPath)
suite.assertCorrectVersion(ts, binPath, tt.Version, tt.Channel)
suite.assertAnalytics(ts)
suite.DirExists(ts.Dirs.Config)

Expand Down
7 changes: 0 additions & 7 deletions test/integration/shells_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package integration

import (
"fmt"
"path/filepath"
"runtime"
"testing"

"github.com/stretchr/testify/suite"

"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/fileutils"
"github.com/ActiveState/cli/internal/testhelpers/e2e"
"github.com/ActiveState/cli/internal/testhelpers/tagsuite"
)
Expand Down Expand Up @@ -46,11 +44,6 @@ func (suite *ShellsIntegrationTestSuite) TestShells() {
suite.T().Run(fmt.Sprintf("using_%s", shell), func(t *testing.T) {
ts.SetT(t)

if shell == e2e.Zsh {
err := fileutils.Touch(filepath.Join(ts.Dirs.HomeDir, ".zshrc"))
suite.Require().NoError(err)
}

// Run the checkout in a particular shell.
cp = ts.SpawnShellWithOpts(shell)
cp.SendLine(e2e.QuoteCommand(shell, ts.ExecutablePath(), "checkout", "ActiveState-CLI/small-python", string(shell)))
Expand Down
Loading

0 comments on commit 2994d0c

Please sign in to comment.