github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/test/integration/languages_int_test.go (about) 1 package integration 2 3 import ( 4 "regexp" 5 "testing" 6 "time" 7 8 "github.com/ActiveState/cli/internal/constants" 9 "github.com/ActiveState/cli/internal/testhelpers/suite" 10 "github.com/ActiveState/termtest" 11 goversion "github.com/hashicorp/go-version" 12 13 "github.com/ActiveState/cli/internal/testhelpers/e2e" 14 "github.com/ActiveState/cli/internal/testhelpers/tagsuite" 15 ) 16 17 type LanguagesIntegrationTestSuite struct { 18 tagsuite.Suite 19 } 20 21 func (suite *LanguagesIntegrationTestSuite) TestLanguages_list() { 22 suite.OnlyRunForTags(tagsuite.Languages) 23 ts := e2e.New(suite.T(), false) 24 defer ts.Close() 25 26 ts.PrepareProject("ActiveState-CLI/Languages", "1eb82b25-a564-42ee-a7d4-d51d2ea73cd5") 27 28 cp := ts.Spawn("languages") 29 cp.Expect("Name") 30 cp.Expect("python") 31 cp.Expect("3.9.15") 32 cp.ExpectExitCode(0) 33 } 34 35 func (suite *LanguagesIntegrationTestSuite) TestLanguages_listNoCommitID() { 36 suite.OnlyRunForTags(tagsuite.Languages) 37 ts := e2e.New(suite.T(), false) 38 defer ts.Close() 39 40 ts.PrepareProject("ActiveState-CLI/Languages", e2e.CommitIDNotChecked) 41 42 cp := ts.Spawn("languages") 43 cp.ExpectNotExitCode(0) 44 ts.IgnoreLogErrors() 45 } 46 47 func (suite *LanguagesIntegrationTestSuite) TestLanguages_install() { 48 suite.OnlyRunForTags(tagsuite.Languages) 49 ts := e2e.New(suite.T(), false) 50 defer ts.Close() 51 52 ts.PrepareProject("ActiveState-CLI/Languages", "1eb82b25-a564-42ee-a7d4-d51d2ea73cd5") 53 54 ts.LoginAsPersistentUser() 55 56 cp := ts.Spawn("languages") 57 cp.Expect("Name") 58 cp.Expect("python") 59 cp.ExpectExitCode(0) 60 61 cp = ts.Spawn("languages", "install", "python@3.9.16") 62 cp.Expect("Language updated: python@3.9.16") 63 // This can take a little while 64 cp.ExpectExitCode(0, termtest.OptExpectTimeout(60*time.Second)) 65 66 cp = ts.Spawn("languages") 67 cp.Expect("Name") 68 cp.Expect("python") 69 versionRe := regexp.MustCompile(`(\d+)\.(\d+).(\d+)`) 70 cp.ExpectRe(versionRe.String()) 71 cp.ExpectExitCode(0) 72 73 // assert that version number changed 74 output := cp.Output() 75 vs := versionRe.FindString(output) 76 v, err := goversion.NewVersion(vs) 77 suite.Require().NoError(err, "parsing version %s", vs) 78 minVersion := goversion.Must(goversion.NewVersion("3.8.1")) 79 suite.True(!v.LessThan(minVersion), "%v >= 3.8.1", v) 80 } 81 82 func (suite *LanguagesIntegrationTestSuite) TestJSON() { 83 suite.OnlyRunForTags(tagsuite.Languages, tagsuite.JSON) 84 ts := e2e.New(suite.T(), false) 85 defer ts.Close() 86 87 cp := ts.Spawn("checkout", "ActiveState-CLI/Python3", ".") 88 cp.Expect("Skipping runtime setup") 89 cp.Expect("Checked out") 90 cp.ExpectExitCode(0) 91 92 cp = ts.Spawn("languages", "-o", "json") 93 cp.Expect(`[{"name":"python","version":`) 94 cp.ExpectExitCode(0) 95 AssertValidJSON(suite.T(), cp) 96 97 cp = ts.Spawn("languages", "search", "--output", "json") 98 cp.Expect(`[{"name":"perl","version":`) 99 cp.ExpectExitCode(0) 100 // AssertValidJSON(suite.T(), cp) // currently too big to fit in the terminal window for validation 101 } 102 103 func (suite *LanguagesIntegrationTestSuite) TestSearch() { 104 suite.OnlyRunForTags(tagsuite.Languages) 105 ts := e2e.New(suite.T(), false) 106 defer ts.Close() 107 108 cp := ts.Spawn("languages", "search") 109 cp.Expect("perl") 110 cp.Expect("5.32") 111 cp.Expect("python") 112 cp.Expect("3.11") 113 cp.Expect("ruby") 114 cp.Expect("3.2") 115 cp.ExpectExitCode(0) 116 } 117 118 func (suite *LanguagesIntegrationTestSuite) TestWildcards() { 119 suite.OnlyRunForTags(tagsuite.Languages) 120 ts := e2e.New(suite.T(), false) 121 defer ts.Close() 122 123 cp := ts.Spawn("checkout", "ActiveState-CLI/small-python", ".") 124 cp.Expect("Skipping runtime setup") 125 cp.Expect("Checked out") 126 cp.ExpectExitCode(0) 127 128 // Test explicit wildcard. 129 cp = ts.Spawn("languages", "install", "python@3.9.x") 130 cp.Expect("Language updated: python@3.9.x") 131 cp.ExpectExitCode(0) 132 cp = ts.Spawn("history") 133 cp.Expect("→ >=3.9,<3.10") 134 cp.ExpectExitCode(0) 135 136 cp = ts.Spawn("reset", "-n") 137 cp.Expect("Successfully reset") 138 cp.ExpectExitCode(0) 139 140 // Test implicit wildcard. 141 cp = ts.Spawn("languages", "install", "python@3.9") 142 cp.Expect("Language updated: python@3.9") 143 cp.ExpectExitCode(0) 144 cp = ts.Spawn("history") 145 cp.Expect("→ >=3.9,<3.10") 146 cp.ExpectExitCode(0) 147 148 // Test non-matching version. 149 // Enable the runtime to actually solve the build and invalidate the version. 150 cp = ts.SpawnWithOpts( 151 e2e.OptArgs("languages", "install", "python@100"), 152 e2e.OptAppendEnv(constants.DisableRuntime+"=false"), 153 ) 154 cp.Expect("Failed") 155 cp.ExpectNotExitCode(0) 156 } 157 158 func TestLanguagesIntegrationTestSuite(t *testing.T) { 159 suite.Run(t, new(LanguagesIntegrationTestSuite)) 160 }