github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/test/integration/install_int_test.go (about) 1 package integration 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/ActiveState/cli/internal/constants" 8 "github.com/ActiveState/cli/internal/testhelpers/e2e" 9 "github.com/ActiveState/cli/internal/testhelpers/suite" 10 "github.com/ActiveState/cli/internal/testhelpers/tagsuite" 11 ) 12 13 type InstallIntegrationTestSuite struct { 14 tagsuite.Suite 15 } 16 17 func (suite *InstallIntegrationTestSuite) TestInstall() { 18 suite.OnlyRunForTags(tagsuite.Install, tagsuite.Critical) 19 ts := e2e.New(suite.T(), false) 20 defer ts.Close() 21 22 ts.PrepareProject("ActiveState-CLI/small-python", "5a1e49e5-8ceb-4a09-b605-ed334474855b") 23 cp := ts.SpawnWithOpts(e2e.OptArgs("install", "trender"), e2e.OptAppendEnv(constants.DisableRuntime+"=false")) 24 cp.Expect("Package added", e2e.RuntimeSourcingTimeoutOpt) 25 cp.ExpectExitCode(0) 26 } 27 28 func (suite *InstallIntegrationTestSuite) TestInstall_InvalidCommit() { 29 suite.OnlyRunForTags(tagsuite.Install) 30 ts := e2e.New(suite.T(), false) 31 defer ts.Close() 32 33 ts.PrepareProject("ActiveState-CLI/small-python", "malformed-commit-id") 34 cp := ts.SpawnWithOpts(e2e.OptArgs("install", "trender")) 35 cp.Expect("invalid commit ID") 36 cp.ExpectExitCode(1) 37 ts.IgnoreLogErrors() 38 } 39 40 func (suite *InstallIntegrationTestSuite) TestInstall_NoMatches_NoAlternatives() { 41 suite.OnlyRunForTags(tagsuite.Install) 42 ts := e2e.New(suite.T(), false) 43 defer ts.Close() 44 45 ts.PrepareProject("ActiveState-CLI/small-python", "5a1e49e5-8ceb-4a09-b605-ed334474855b") 46 cp := ts.SpawnWithOpts(e2e.OptArgs("install", "I-dont-exist")) 47 cp.Expect("No results found for search term") 48 cp.Expect("find alternatives") // This verifies no alternatives were found 49 cp.ExpectExitCode(1) 50 ts.IgnoreLogErrors() 51 52 if strings.Count(strings.ReplaceAll(cp.Snapshot(), " x Failed", ""), " x ") != 1 { 53 suite.Fail("Expected exactly ONE error message, got: ", cp.Snapshot()) 54 } 55 } 56 57 func (suite *InstallIntegrationTestSuite) TestInstall_NoMatches_Alternatives() { 58 suite.OnlyRunForTags(tagsuite.Install) 59 ts := e2e.New(suite.T(), false) 60 defer ts.Close() 61 62 ts.PrepareProject("ActiveState-CLI/small-python", "5a1e49e5-8ceb-4a09-b605-ed334474855b") 63 cp := ts.SpawnWithOpts(e2e.OptArgs("install", "database")) 64 cp.Expect("No results found for search term") 65 cp.Expect("did you mean") // This verifies alternatives were found 66 cp.ExpectExitCode(1) 67 ts.IgnoreLogErrors() 68 69 if strings.Count(strings.ReplaceAll(cp.Snapshot(), " x Failed", ""), " x ") != 1 { 70 suite.Fail("Expected exactly ONE error message, got: ", cp.Snapshot()) 71 } 72 } 73 74 func (suite *InstallIntegrationTestSuite) TestInstall_BuildPlannerError() { 75 suite.OnlyRunForTags(tagsuite.Install) 76 ts := e2e.New(suite.T(), false) 77 defer ts.Close() 78 79 ts.PrepareProject("ActiveState-CLI/small-python", "d8f26b91-899c-4d50-8310-2c338786aa0f") 80 cp := ts.SpawnWithOpts( 81 e2e.OptArgs("install", "trender@999.0"), 82 e2e.OptAppendEnv(constants.DisableRuntime+"=false"), 83 ) 84 cp.Expect("Could not plan build, platform responded with", e2e.RuntimeSourcingTimeoutOpt) 85 cp.ExpectExitCode(1) 86 ts.IgnoreLogErrors() 87 88 if strings.Count(strings.ReplaceAll(cp.Snapshot(), " x Failed", ""), " x ") != 1 { 89 suite.Fail("Expected exactly ONE error message, got: ", cp.Snapshot()) 90 } 91 } 92 93 func (suite *InstallIntegrationTestSuite) TestInstall_Resolved() { 94 suite.OnlyRunForTags(tagsuite.Install) 95 ts := e2e.New(suite.T(), false) 96 defer ts.Close() 97 98 ts.PrepareProject("ActiveState-CLI/small-python", "5a1e49e5-8ceb-4a09-b605-ed334474855b") 99 cp := ts.SpawnWithOpts( 100 e2e.OptArgs("install", "requests"), 101 e2e.OptAppendEnv(constants.DisableRuntime+"=false"), 102 ) 103 cp.Expect("Package added", e2e.RuntimeSourcingTimeoutOpt) 104 cp.ExpectExitCode(0) 105 106 // Run `state packages` to verify a full package version was resolved. 107 cp = ts.Spawn("packages") 108 cp.Expect("requests") 109 cp.Expect("Auto → 2.") // note: the patch version is variable, so just expect that it exists 110 cp.ExpectExitCode(0) 111 } 112 113 func TestInstallIntegrationTestSuite(t *testing.T) { 114 suite.Run(t, new(InstallIntegrationTestSuite)) 115 }