Skip to content

Commit

Permalink
Fix SetupRCFile failing because no rc file exists in home dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Naatan committed Oct 20, 2023
1 parent 27ba2ec commit a3e77f3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 70 deletions.
18 changes: 1 addition & 17 deletions cmd/state-installer/test/integration/installer_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (suite *InstallerIntegrationTestSuite) TestInstallFromLocalSource() {
ts := e2e.New(suite.T(), false)
defer ts.Close()

suite.SetupRCFile(ts)
ts.SetupRCFile()
suite.T().Setenv(constants.HomeEnvVarName, ts.Dirs.HomeDir)

dir, err := ioutil.TempDir("", "system*")
Expand Down Expand Up @@ -223,22 +223,6 @@ func (suite *InstallerIntegrationTestSuite) TestInstallerOverwriteServiceApp() {
cp.ExpectExitCode(0)
}

func (suite *InstallerIntegrationTestSuite) SetupRCFile(ts *e2e.Session) {
if runtime.GOOS == "windows" {
return
}

cfg, err := config.New()
suite.Require().NoError(err)

subshell := subshell.New(cfg)
rcFile, err := subshell.RcFile()
suite.Require().NoError(err)

err = fileutils.CopyFile(rcFile, filepath.Join(ts.Dirs.HomeDir, filepath.Base(rcFile)))
suite.Require().NoError(err)
}

func (suite *InstallerIntegrationTestSuite) AssertConfig(ts *e2e.Session) {
if runtime.GOOS != "windows" {
// Test bashrc
Expand Down
28 changes: 28 additions & 0 deletions internal/testhelpers/e2e/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"testing"
"time"

"github.com/ActiveState/cli/internal/subshell"
"github.com/ActiveState/termtest"
"github.com/go-openapi/strfmt"
"github.com/google/uuid"
Expand Down Expand Up @@ -745,6 +746,33 @@ func (s *Session) DetectLogErrors() {
}
}

func (s *Session) SetupRCFile() {
if runtime.GOOS == "windows" {
return
}

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

s.SetupRCFileCustom(subshell.New(cfg))
}

func (s *Session) SetupRCFileCustom(subshell subshell.SubShell) {
if runtime.GOOS == "windows" {
return
}

rcFile, err := subshell.RcFile()
require.NoError(s.t, err)

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(rcFile)
}
require.NoError(s.t, err)
}

func RunningOnCI() bool {
return condition.OnCI()
}
20 changes: 2 additions & 18 deletions test/integration/deploy_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (suite *DeployIntegrationTestSuite) TestDeployPython() {
ts := e2e.New(suite.T(), false)
defer ts.Close()

suite.SetupRCFile(ts)
ts.SetupRCFile()
suite.T().Setenv("ACTIVESTATE_HOME", ts.Dirs.HomeDir)

targetID, err := uuid.NewUUID()
Expand Down Expand Up @@ -261,7 +261,7 @@ func (suite *DeployIntegrationTestSuite) TestDeployConfigure() {
ts := e2e.New(suite.T(), false)
defer ts.Close()

suite.SetupRCFile(ts)
ts.SetupRCFile()
suite.T().Setenv("ACTIVESTATE_HOME", ts.Dirs.HomeDir)

targetID, err := uuid.NewUUID()
Expand Down Expand Up @@ -309,22 +309,6 @@ func (suite *DeployIntegrationTestSuite) TestDeployConfigure() {
}
}

func (suite *DeployIntegrationTestSuite) SetupRCFile(ts *e2e.Session) {
if runtime.GOOS == "windows" {
return
}

cfg, err := config.New()
suite.Require().NoError(err)

subshell := subshell.New(cfg)
rcFile, err := subshell.RcFile()
suite.Require().NoError(err)

err = fileutils.CopyFile(rcFile, filepath.Join(ts.Dirs.HomeDir, filepath.Base(rcFile)))
suite.Require().NoError(err)
}

func (suite *DeployIntegrationTestSuite) AssertConfig(ts *e2e.Session, targetID string) {
if runtime.GOOS != "windows" {
// Test config file
Expand Down
20 changes: 2 additions & 18 deletions test/integration/shell_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,24 +258,8 @@ func (suite *ShellIntegrationTestSuite) SetupRCFile(ts *e2e.Session) {
return
}

cfg, err := config.New()
suite.Require().NoError(err)

subshell := subshell.New(cfg)
rcFile, err := subshell.RcFile()
suite.Require().NoError(err)

err = fileutils.CopyFile(rcFile, filepath.Join(ts.Dirs.HomeDir, filepath.Base(rcFile)))
suite.Require().NoError(err)

zsh := &zsh.SubShell{}
zshRcFile, err := zsh.RcFile()
suite.NoError(err)
err = fileutils.TouchFileUnlessExists(zshRcFile)
suite.NoError(err)

err = fileutils.CopyFile(rcFile, filepath.Join(ts.Dirs.HomeDir, filepath.Base(zshRcFile)))
suite.Require().NoError(err)
ts.SetupRCFile()
ts.SetupRCFileCustom(&zsh.SubShell{})
}

func (suite *ShellIntegrationTestSuite) TestRuby() {
Expand Down
18 changes: 1 addition & 17 deletions test/integration/use_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (suite *UseIntegrationTestSuite) TestReset() {
ts := e2e.New(suite.T(), false)
defer ts.Close()

suite.SetupRCFile(ts)
ts.SetupRCFile()
suite.T().Setenv("ACTIVESTATE_HOME", ts.Dirs.HomeDir)

cp := ts.SpawnWithOpts(e2e.OptArgs("checkout", "ActiveState-CLI/Python3"))
Expand Down Expand Up @@ -288,22 +288,6 @@ func (suite *UseIntegrationTestSuite) TestJSON() {
AssertValidJSON(suite.T(), cp)
}

func (suite *UseIntegrationTestSuite) SetupRCFile(ts *e2e.Session) {
if runtime.GOOS == "windows" {
return
}

cfg, err := config.New()
suite.Require().NoError(err)

subshell := subshell.New(cfg)
rcFile, err := subshell.RcFile()
suite.Require().NoError(err)

err = fileutils.CopyFile(rcFile, filepath.Join(ts.Dirs.HomeDir, filepath.Base(rcFile)))
suite.Require().NoError(err)
}

func TestUseIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(UseIntegrationTestSuite))
}

0 comments on commit a3e77f3

Please sign in to comment.