github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/test/integration/remote_installer_int_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 "path/filepath" 6 "testing" 7 8 anaConst "github.com/ActiveState/cli/internal/analytics/constants" 9 "github.com/ActiveState/cli/internal/constants" 10 "github.com/ActiveState/cli/internal/environment" 11 "github.com/ActiveState/cli/internal/fileutils" 12 "github.com/ActiveState/cli/internal/osutils" 13 "github.com/ActiveState/cli/internal/testhelpers/e2e" 14 "github.com/ActiveState/cli/internal/testhelpers/suite" 15 "github.com/ActiveState/cli/internal/testhelpers/tagsuite" 16 ) 17 18 type RemoteInstallIntegrationTestSuite struct { 19 tagsuite.Suite 20 remoteInstallerExe string 21 } 22 23 func (suite *RemoteInstallIntegrationTestSuite) TestInstall() { 24 suite.OnlyRunForTags(tagsuite.RemoteInstaller, tagsuite.Critical) 25 ts := e2e.New(suite.T(), true) 26 defer ts.Close() 27 28 tests := []struct { 29 Name string 30 Version string 31 Channel string 32 }{ 33 // Disabled until the target installers support the installpath override env var: DX-1350 34 // {"install-release-latest", "", constants.ReleaseChannel}, 35 // {"install-prbranch", "", ""}, 36 // {"install-prbranch-with-version", constants.Version, constants.ChannelName}, 37 {"install-prbranch-and-channel", "", constants.ChannelName}, 38 } 39 40 for _, tt := range tests { 41 suite.Run(fmt.Sprintf("%s (%s@%s)", tt.Name, tt.Version, tt.Channel), func() { 42 ts := e2e.New(suite.T(), false) 43 defer ts.Close() 44 45 suite.setupTest(ts) 46 47 installPath := filepath.Join(ts.Dirs.Work, "install") 48 stateExePath := filepath.Join(installPath, "bin", constants.StateCmd+osutils.ExeExtension) 49 50 args := []string{"-n"} 51 if tt.Version != "" { 52 args = append(args, "--version", tt.Version) 53 } 54 if tt.Channel != "" { 55 args = append(args, "--channel", tt.Channel) 56 } 57 58 appInstallDir := filepath.Join(ts.Dirs.Work, "app") 59 suite.NoError(fileutils.Mkdir(appInstallDir)) 60 61 cp := ts.SpawnCmdWithOpts( 62 suite.remoteInstallerExe, 63 e2e.OptArgs(args...), 64 e2e.OptAppendEnv(constants.InstallPathOverrideEnvVarName+"="+installPath), 65 e2e.OptAppendEnv(fmt.Sprintf("%s=%s", constants.AppInstallDirOverrideEnvVarName, appInstallDir)), 66 ) 67 68 cp.Expect("Terms of Service") 69 cp.SendLine("Y") 70 cp.Expect("Installing") 71 cp.Expect("Installation Complete") 72 cp.Expect("Press ENTER to exit") 73 cp.SendEnter() 74 cp.ExpectExitCode(0) 75 76 suite.Require().FileExists(stateExePath) 77 78 cp = ts.SpawnCmdWithOpts( 79 stateExePath, 80 e2e.OptArgs("--version"), 81 e2e.OptAppendEnv(constants.InstallPathOverrideEnvVarName+"="+installPath), 82 ) 83 if tt.Version != "" { 84 cp.Expect("Version " + tt.Version) 85 } 86 if tt.Channel != "" { 87 cp.Expect("Channel " + tt.Channel) 88 } 89 cp.Expect("Built") 90 cp.ExpectExitCode(0) 91 92 // Verify analytics reported the correct sessionToken. 93 sessionTokenFound := false 94 events := parseAnalyticsEvents(suite, ts) 95 suite.Require().NotEmpty(events) 96 for _, event := range events { 97 if event.Category == anaConst.CatUpdates && event.Dimensions != nil { 98 suite.Assert().Contains(*event.Dimensions.SessionToken, constants.RemoteInstallerVersion) 99 sessionTokenFound = true 100 break 101 } 102 } 103 suite.Assert().True(sessionTokenFound, "sessionToken was not found in analytics") 104 }) 105 } 106 } 107 108 func (s *RemoteInstallIntegrationTestSuite) setupTest(ts *e2e.Session) { 109 root := environment.GetRootPathUnsafe() 110 buildDir := fileutils.Join(root, "build") 111 installerExe := filepath.Join(buildDir, constants.StateRemoteInstallerCmd+osutils.ExeExtension) 112 if !fileutils.FileExists(installerExe) { 113 s.T().Fatal("E2E tests require a state-remote-installer binary. Run `state run build-installer`.") 114 } 115 s.remoteInstallerExe = ts.CopyExeToDir(installerExe, filepath.Join(ts.Dirs.Base, "installer")) 116 } 117 118 func TestRemoteInstallIntegrationTestSuite(t *testing.T) { 119 suite.Run(t, new(RemoteInstallIntegrationTestSuite)) 120 }