Skip to content

Commit

Permalink
Merge branch version/0-42-0-RC1 to adopt changes from PR #2816
Browse files Browse the repository at this point in the history
  • Loading branch information
as-builds committed Oct 18, 2023
2 parents 53389be + b995636 commit 5d83759
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 6 deletions.
51 changes: 51 additions & 0 deletions internal/testhelpers/e2e/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
"github.com/ActiveState/cli/internal/osutils/stacktrace"
"github.com/ActiveState/cli/internal/rtutils/singlethread"
"github.com/ActiveState/cli/internal/strutils"
"github.com/ActiveState/cli/internal/subshell/bash"
"github.com/ActiveState/cli/internal/subshell/sscommon"
"github.com/ActiveState/cli/internal/testhelpers/tagsuite"
"github.com/ActiveState/cli/pkg/platform/api"
"github.com/ActiveState/cli/pkg/platform/api/mono"
Expand Down Expand Up @@ -185,12 +187,35 @@ func new(t *testing.T, retainDirs, updatePath bool, extraEnv ...string) *Session

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.InstallPathForBranch("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
Expand All @@ -204,6 +229,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 @@ -580,6 +613,24 @@ func (s *Session) Close() error {
}
}

// Add back the release state tool installation to the bash RC file.
// This was done on session creation to ensure that the release state tool
// does not appear on the PATH when a new subshell is started. This is a
// workaround to be addressed in: https://activestatef.atlassian.net/browse/DX-2285
if runtime.GOOS != "windows" {
installPath, err := installation.InstallPathForBranch("release")
if err != nil {
s.t.Errorf("Could not get install path: %v", errs.JoinMessage(err))
}
binDir := filepath.Join(installPath, "bin")

ss := bash.SubShell{}
err = ss.WriteUserEnv(cfg, map[string]string{"PATH": binDir}, sscommon.InstallID, false)
if err != nil {
s.t.Errorf("Could not clean user env: %v", errs.JoinMessage(err))
}
}

return nil
}

Expand Down
25 changes: 19 additions & 6 deletions test/integration/install_scripts_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,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, "-t", installDir}
argsPlain := []string{script}
if tt.Channel != "" {
argsPlain = append(argsPlain, "-b", tt.Channel)
}
Expand Down Expand Up @@ -113,14 +112,28 @@ func (suite *InstallScriptsIntegrationTestSuite) TestInstall() {

if tt.Activate != "" || tt.ActivateByCommand != "" {
cp.Expect("Creating a Virtual Environment")
cp.Expect("Quick Start", termtest.OptExpectTimeout(time.Second*60))
cp.Expect("Quick Start", e2e.RuntimeSourcingTimeoutOpt)
// ensure that shell is functional
cp.ExpectInput()

cp.SendLine("python3 -c \"import sys; print(sys.copyright)\"")
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.InstallPathForBranch(constants.BranchName)
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("Branch " + constants.BranchName)
Expand All @@ -129,12 +142,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

0 comments on commit 5d83759

Please sign in to comment.