github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/test/integration/refresh_int_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 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 RefreshIntegrationTestSuite struct { 14 tagsuite.Suite 15 } 16 17 func (suite *RefreshIntegrationTestSuite) TestRefresh() { 18 suite.OnlyRunForTags(tagsuite.Refresh) 19 ts := e2e.New(suite.T(), false) 20 defer ts.Close() 21 22 suite.PrepareActiveStateYAML(ts, "ActiveState-CLI/Branches", "main", "35af7414-b44b-4fd7-aa93-2ecad337ed2b") 23 24 cp := ts.SpawnWithOpts( 25 e2e.OptArgs("refresh"), 26 e2e.OptAppendEnv(constants.DisableRuntime+"=false"), 27 ) 28 cp.Expect("Setting Up Runtime") 29 cp.Expect("Runtime updated", e2e.RuntimeSourcingTimeoutOpt) 30 cp.ExpectExitCode(0) 31 32 cp = ts.SpawnWithOpts( 33 e2e.OptArgs("exec", "--", "python3", "-c", "import requests"), 34 e2e.OptAppendEnv(constants.DisableRuntime+"=false"), 35 ) 36 cp.Expect("ModuleNotFoundError") 37 cp.ExpectExitCode(1) 38 ts.IgnoreLogErrors() 39 40 suite.PrepareActiveStateYAML(ts, "ActiveState-CLI/Branches", "secondbranch", "46c83477-d580-43e2-a0c6-f5d3677517f1") 41 cp = ts.SpawnWithOpts( 42 e2e.OptArgs("refresh"), 43 e2e.OptAppendEnv(constants.DisableRuntime+"=false"), 44 ) 45 cp.Expect("Setting Up Runtime") 46 cp.Expect("Runtime updated", e2e.RuntimeSourcingTimeoutOpt) 47 cp.ExpectExitCode(0) 48 49 cp = ts.SpawnWithOpts( 50 e2e.OptArgs("exec", "--", "python3", "-c", "import requests"), 51 e2e.OptAppendEnv(constants.DisableRuntime+"=false"), 52 ) 53 cp.ExpectExitCode(0, e2e.RuntimeSourcingTimeoutOpt) 54 55 cp = ts.Spawn("refresh") 56 suite.Assert().NotContains(cp.Output(), "Setting Up Runtime", "Unchanged runtime should not refresh") 57 cp.Expect("Runtime updated") 58 cp.ExpectExitCode(0) 59 } 60 61 func (suite *RefreshIntegrationTestSuite) TestJSON() { 62 suite.OnlyRunForTags(tagsuite.Refresh, tagsuite.JSON) 63 ts := e2e.New(suite.T(), false) 64 defer ts.Close() 65 66 suite.PrepareActiveStateYAML(ts, "ActiveState-CLI/Branches", "main", "35af7414-b44b-4fd7-aa93-2ecad337ed2b") 67 68 cp := ts.Spawn("refresh", "-o", "json") 69 cp.Expect(`"namespace":`) 70 cp.Expect(`"path":`) 71 cp.Expect(`"executables":`) 72 cp.ExpectExitCode(0) 73 // AssertValidJSON(suite.T(), cp) // cannot assert here due to "Skipping runtime setup" notice 74 } 75 76 func (suite *RefreshIntegrationTestSuite) PrepareActiveStateYAML(ts *e2e.Session, namespace, branch, commitID string) { 77 asyData := fmt.Sprintf(`project: "https://platform.activestate.com/%s?branch=%s"`, namespace, branch) 78 ts.PrepareActiveStateYAML(asyData) 79 ts.PrepareCommitIdFile(commitID) 80 } 81 82 func TestRefreshIntegrationTestSuite(t *testing.T) { 83 suite.Run(t, new(RefreshIntegrationTestSuite)) 84 }