From acb504feb68062b29edb49c0d57ced64de7ca9ee Mon Sep 17 00:00:00 2001 From: mitchell Date: Fri, 13 Oct 2023 15:11:07 -0400 Subject: [PATCH] Remote installer should send a sessionToken to analytics. --- cmd/state-remote-installer/main.go | 6 ++++++ test/integration/remote_installer_int_test.go | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/cmd/state-remote-installer/main.go b/cmd/state-remote-installer/main.go index bf2f913a43..de30e8c678 100644 --- a/cmd/state-remote-installer/main.go +++ b/cmd/state-remote-installer/main.go @@ -95,6 +95,12 @@ func main() { return } + // Store sessionToken to config + err = cfg.Set(anaConst.CfgSessionToken, "remote_"+constants.RemoteInstallerVersion) + if err != nil { + logging.Error("Unable to set session token: " + errs.JoinMessage(err)) + } + an = sync.New(anaConst.SrcStateRemoteInstaller, cfg, nil, out) // Set up prompter diff --git a/test/integration/remote_installer_int_test.go b/test/integration/remote_installer_int_test.go index b12fbcf2a3..00ba3d163b 100644 --- a/test/integration/remote_installer_int_test.go +++ b/test/integration/remote_installer_int_test.go @@ -5,6 +5,7 @@ import ( "path/filepath" "testing" + anaConst "github.com/ActiveState/cli/internal/analytics/constants" "github.com/ActiveState/cli/internal/constants" "github.com/ActiveState/cli/internal/environment" "github.com/ActiveState/cli/internal/exeutils" @@ -88,6 +89,19 @@ func (suite *RemoteInstallIntegrationTestSuite) TestInstall() { } cp.Expect("Built") cp.ExpectExitCode(0) + + // Verify analytics reported the correct sessionToken. + sessionTokenFound := false + events := parseAnalyticsEvents(suite, ts) + suite.Require().NotEmpty(events) + for _, event := range events { + if event.Category == anaConst.CatUpdates && event.Dimensions != nil { + suite.Assert().Contains(*event.Dimensions.SessionToken, constants.RemoteInstallerVersion) + sessionTokenFound = true + break + } + } + suite.Assert().True(sessionTokenFound, "sessionToken was not found in analytics") }) } }