Skip to content

Commit

Permalink
Merge branch version/0-42-0-RC1 to adopt changes from PR #2823
Browse files Browse the repository at this point in the history
  • Loading branch information
as-builds committed Oct 17, 2023
2 parents 9b39505 + 96be607 commit f34e72a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
13 changes: 13 additions & 0 deletions cmd/state-installer/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ func main() {
logging.Debug("Original Args: %v", os.Args)
logging.Debug("Processed Args: %v", processedArgs)

// Store sessionToken to config
for _, envVar := range []string{constants.OverrideSessionTokenEnvVarName, constants.SessionTokenEnvVarName} {
sessionToken, ok := os.LookupEnv(envVar)
if !ok {
continue
}
err := cfg.Set(anaConst.CfgSessionToken, sessionToken)
if err != nil {
multilog.Error("Unable to set session token: " + errs.JoinMessage(err))
}
break
}

an = sync.New(anaConst.SrcStateInstaller, cfg, nil, out)
an.Event(anaConst.CatInstallerFunnel, "start")

Expand Down
18 changes: 3 additions & 15 deletions cmd/state-installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

svcApp "github.com/ActiveState/cli/cmd/state-svc/app"
svcAutostart "github.com/ActiveState/cli/cmd/state-svc/autostart"
anaConst "github.com/ActiveState/cli/internal/analytics/constants"
"github.com/ActiveState/cli/internal/config"
"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/errs"
Expand All @@ -30,10 +29,9 @@ import (
)

type Installer struct {
out output.Outputer
cfg *config.Instance
payloadPath string
sessionToken string
out output.Outputer
cfg *config.Instance
payloadPath string
*Params
}

Expand All @@ -49,13 +47,6 @@ func NewInstaller(cfg *config.Instance, out output.Outputer, payloadPath string,
}

func (i *Installer) Install() (rerr error) {
// Store sessionToken to config
if i.sessionToken != "" && i.cfg.GetString(anaConst.CfgSessionToken) == "" {
if err := i.cfg.Set(anaConst.CfgSessionToken, i.sessionToken); err != nil {
return errs.Wrap(err, "Failed to set session token")
}
}

// Store update tag
if i.updateTag != "" {
if err := i.cfg.Set(updater.CfgUpdateTag, i.updateTag); err != nil {
Expand Down Expand Up @@ -145,9 +136,6 @@ func (i *Installer) InstallPath() string {

// sanitizeInput cleans up the input and inserts fallback values
func (i *Installer) sanitizeInput() error {
if sessionToken, ok := os.LookupEnv(constants.SessionTokenEnvVarName); ok {
i.sessionToken = sessionToken
}
if tag, ok := os.LookupEnv(constants.UpdateTagEnvVarName); ok {
i.updateTag = tag
}
Expand Down
3 changes: 3 additions & 0 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ const ProfileEnvVarName = "ACTIVESTATE_PROFILE"
// SessionTokenEnvVarName records the session token
const SessionTokenEnvVarName = "ACTIVESTATE_SESSION_TOKEN"

// OverrideSessionTokenEnvVarName overrides SessionTokenEnvVarName for integration tests.
const OverrideSessionTokenEnvVarName = "ACTIVESTATE_OVERRIDE_SESSION_TOKEN"

// UpdateTagEnvVarName
const UpdateTagEnvVarName = "ACTIVESTATE_UPDATE_TAG"

Expand Down
19 changes: 19 additions & 0 deletions test/integration/install_scripts_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/thoas/go-funk"

anaConst "github.com/ActiveState/cli/internal/analytics/constants"
"github.com/ActiveState/cli/internal/condition"
"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/environment"
Expand Down Expand Up @@ -97,12 +98,14 @@ func (suite *InstallScriptsIntegrationTestSuite) TestInstall() {
"bash", e2e.OptArgs(argsWithActive...),
e2e.OptAppendEnv("ACTIVESTATE_CLI_DISABLE_RUNTIME=false"),
e2e.OptAppendEnv(fmt.Sprintf("%s=%s", constants.AppInstallDirOverrideEnvVarName, appInstallDir)),
e2e.OptAppendEnv(fmt.Sprintf("%s=FOO", constants.OverrideSessionTokenEnvVarName)),
)
} else {
cp = ts.SpawnCmdWithOpts("powershell.exe", e2e.OptArgs(argsWithActive...),
e2e.OptAppendEnv("SHELL="),
e2e.OptAppendEnv("ACTIVESTATE_CLI_DISABLE_RUNTIME=false"),
e2e.OptAppendEnv(fmt.Sprintf("%s=%s", constants.AppInstallDirOverrideEnvVarName, appInstallDir)),
e2e.OptAppendEnv(fmt.Sprintf("%s=FOO", constants.OverrideSessionTokenEnvVarName)),
)
}

Expand Down Expand Up @@ -132,6 +135,7 @@ func (suite *InstallScriptsIntegrationTestSuite) TestInstall() {

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

// Verify that can install overtop
Expand Down Expand Up @@ -260,6 +264,21 @@ func (suite *InstallScriptsIntegrationTestSuite) assertCorrectVersion(ts *e2e.Se
}
}

func (suite *InstallScriptsIntegrationTestSuite) assertAnalytics(ts *e2e.Session) {
// Verify analytics reported a non-empty sessionToken.
sessionTokenFound := false
events := parseAnalyticsEvents(suite, ts)
suite.Require().NotEmpty(events)
for _, event := range events {
if event.Category == anaConst.CatInstallerFunnel && event.Dimensions != nil {
suite.Assert().NotEmpty(*event.Dimensions.SessionToken)
sessionTokenFound = true
break
}
}
suite.Assert().True(sessionTokenFound, "sessionToken was not found in analytics")
}

func TestInstallScriptsIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(InstallScriptsIntegrationTestSuite))
}

0 comments on commit f34e72a

Please sign in to comment.