github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/test/integration/runtime_int_test.go (about) 1 package integration 2 3 import ( 4 "path/filepath" 5 "runtime" 6 "testing" 7 "time" 8 9 "github.com/ActiveState/cli/internal/constants" 10 "github.com/ActiveState/cli/internal/osutils" 11 "github.com/ActiveState/cli/internal/testhelpers/e2e" 12 "github.com/ActiveState/cli/internal/testhelpers/suite" 13 "github.com/ActiveState/cli/internal/testhelpers/tagsuite" 14 "github.com/ActiveState/cli/pkg/platform/runtime/setup" 15 "github.com/ActiveState/cli/pkg/platform/runtime/target" 16 ) 17 18 // Disabled due to DX-1514 19 /*func TestOfflineInstaller(t *testing.T) { 20 // Each artifact of the form UUID.tar.gz has the following structure: 21 // - runtime.json (empty) 22 // - tmp (directory) 23 // - [number] (file) 24 // The numbered file is the key to the following maps. 25 testArtifacts := map[string]strfmt.UUID{ 26 "1": "74D554B3-6B0F-434B-AFE2-9F2F0B5F32BA", 27 "2": "87ADD1B0-169D-4C01-8179-191BB9910799", 28 "3": "5D8D933F-09FA-45A3-81FF-E6F33E91C9ED", 29 "4": "992B8488-C61D-433C-ADF2-D76EBD8DAE59", 30 "5": "2C36A315-59ED-471B-8629-2663ECC95476", 31 "6": "57E8EAF4-F7EE-4BEF-B437-D9F0A967BA52", 32 "7": "E299F10C-7B5D-4B25-B821-90E30193A916", 33 "8": "F95C0ECE-9F69-4998-B83F-CE530BACD468", 34 "9": "CAC9708D-FAA6-4295-B640-B8AA41A8AABC", 35 "10": "009D20C9-0E38-44E8-A095-7B6FEF01D7DA", 36 } 37 const artifactsPerArtifact = 2 // files/artifacts per artifact.tar.gz 38 39 dir, err := os.MkdirTemp("", "") 40 suite.Require().NoError(err) 41 defer os.RemoveAll(dir) 42 43 artifactsDir := filepath.Join(osutil.GetTestDataDir(), "offline-runtime") 44 offlineTarget := target.NewOfflineTarget(nil, dir, artifactsDir) 45 46 analytics := blackhole.New() 47 mockProgress := &testhelper.MockProgressOutput{} 48 logfile, err := buildlogfile.New(outputhelper.NewCatcher()) 49 suite.Require().NoError(err) 50 eventHandler := events.NewRuntimeEventHandler(mockProgress, nil, logfile) 51 52 if value, set := os.LookupEnv(constants.DisableRuntime); set { 53 os.Setenv(constants.DisableRuntime, "false") 54 defer os.Setenv(constants.DisableRuntime, value) 55 } 56 57 rt, err := runtime.New(offlineTarget, analytics, nil, nil) 58 suite.Require().Error(err) 59 err = rt.Update(eventHandler) 60 suite.Require().NoError(err) 61 62 suite.Assert().False(mockProgress.BuildStartedCalled) 63 suite.Assert().False(mockProgress.BuildCompletedCalled) 64 suite.Assert().Equal(int64(0), mockProgress.BuildTotal) 65 suite.Assert().Equal(0, mockProgress.BuildCurrent) 66 suite.Assert().Equal(true, mockProgress.InstallationStartedCalled) 67 suite.Assert().Equal(true, mockProgress.InstallationCompletedCalled) 68 suite.Assert().Equal(int64(len(testArtifacts)), mockProgress.InstallationTotal) 69 suite.Assert().Equal(len(testArtifacts)*artifactsPerArtifact, mockProgress.ArtifactStartedCalled) 70 suite.Assert().Equal(2*len(testArtifacts)*artifactsPerArtifact, mockProgress.ArtifactIncrementCalled) // start and stop each have one count 71 suite.Assert().Equal(len(testArtifacts)*artifactsPerArtifact, mockProgress.ArtifactCompletedCalled) 72 suite.Assert().Equal(0, mockProgress.ArtifactFailureCalled) 73 74 for filename := range testArtifacts { 75 filename := filepath.Join(dir, "tmp", filename) // each file is in a "tmp" dir in the archive 76 suite.Assert().True(fileutils.FileExists(filename), "file '%s' was not extracted from its artifact", filename) 77 } 78 }*/ 79 80 type RuntimeIntegrationTestSuite struct { 81 tagsuite.Suite 82 } 83 84 func (suite *RuntimeIntegrationTestSuite) TestInterruptSetup() { 85 suite.OnlyRunForTags(tagsuite.Interrupt) 86 ts := e2e.New(suite.T(), false) 87 defer ts.Close() 88 89 cp := ts.SpawnWithOpts( 90 e2e.OptArgs("checkout", "ActiveState-CLI/test-interrupt-small-python#863c45e2-3626-49b6-893c-c15e85a17241", "."), 91 e2e.OptAppendEnv(constants.DisableRuntime+"=false"), 92 ) 93 cp.Expect("Checked out project", e2e.RuntimeSourcingTimeoutOpt) 94 95 targetDir := target.ProjectDirToTargetDir(ts.Dirs.Work, ts.Dirs.Cache) 96 pythonExe := filepath.Join(setup.ExecDir(targetDir), "python3"+osutils.ExeExtension) 97 cp = ts.SpawnCmd(pythonExe, "-c", `print(__import__('sys').version)`) 98 cp.Expect("3.8.8") 99 cp.ExpectExitCode(0) 100 101 cp = ts.SpawnWithOpts( 102 e2e.OptArgs("pull"), 103 e2e.OptAppendEnv(constants.DisableRuntime+"=false", 104 constants.RuntimeSetupWaitEnvVarName+"=true"), 105 ) 106 time.Sleep(30 * time.Second) 107 cp.SendCtrlC() // cancel pull/update 108 109 cp = ts.SpawnCmd(pythonExe, "-c", `print(__import__('sys').version)`) 110 cp.Expect("3.8.8") // current runtime still works 111 cp.ExpectExitCode(0) 112 ts.IgnoreLogErrors() // Should see an error related to the interrupted setup 113 } 114 115 func (suite *RuntimeIntegrationTestSuite) TestInUse() { 116 if runtime.GOOS == "darwin" { 117 return // gopsutil errors on later versions of macOS (DX-2723) 118 } 119 suite.OnlyRunForTags(tagsuite.Critical) 120 ts := e2e.New(suite.T(), false) 121 defer ts.Close() 122 123 cp := ts.Spawn("checkout", "ActiveState-CLI/Perl-5.36", ".") 124 cp.Expect("Skipping runtime setup") 125 cp.ExpectExitCode(0) 126 127 cp = ts.SpawnWithOpts( 128 e2e.OptArgs("shell"), 129 e2e.OptAppendEnv(constants.DisableRuntime+"=false"), 130 ) 131 cp.Expect("Activated", e2e.RuntimeSourcingTimeoutOpt) 132 cp.SendLine("perl") 133 time.Sleep(1 * time.Second) // allow time for perl to start up 134 135 cp2 := ts.SpawnWithOpts( 136 e2e.OptArgs("install", "DateTime"), 137 e2e.OptAppendEnv(constants.DisableRuntime+"=false"), 138 ) 139 cp2.Expect("currently in use", e2e.RuntimeSourcingTimeoutOpt) 140 cp2.Expect("perl") 141 cp2.ExpectNotExitCode(0) 142 ts.IgnoreLogErrors() 143 144 cp.SendCtrlC() 145 cp.SendLine("exit") 146 cp.ExpectExit() // code can vary depending on shell; just assert process finished 147 } 148 149 func TestRuntimeIntegrationTestSuite(t *testing.T) { 150 suite.Run(t, new(RuntimeIntegrationTestSuite)) 151 }