github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/test/integration/branch_int_test.go (about) 1 package integration 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/ActiveState/cli/internal/testhelpers/suite" 8 "github.com/ActiveState/termtest" 9 "github.com/google/uuid" 10 11 "github.com/ActiveState/cli/internal/testhelpers/e2e" 12 "github.com/ActiveState/cli/internal/testhelpers/tagsuite" 13 ) 14 15 type BranchIntegrationTestSuite struct { 16 tagsuite.Suite 17 } 18 19 func (suite *BranchIntegrationTestSuite) TestBranch_List() { 20 suite.OnlyRunForTags(tagsuite.Branches) 21 ts := e2e.New(suite.T(), false) 22 defer ts.Close() 23 24 ts.PrepareProject("ActiveState-CLI/Branches", "35af7414-b44b-4fd7-aa93-2ecad337ed2b") 25 26 cp := ts.SpawnWithOpts(e2e.OptArgs("branch"), e2e.OptTermTest(termtest.OptVerboseLogger())) 27 // Sometimes there's a space before the line break, unsure exactly why, but hence the regex 28 cp.ExpectRe(`main \(Current\)\s?\n ├─ firstbranch\s?\n │ └─ firstbranchchild\s?\n │ └─ childoffirstbranchchild\s?\n ├─ secondbranch\s?\n └─ thirdbranch`, termtest.OptExpectTimeout(5*time.Second)) 29 cp.Expect("To switch to another branch,") 30 cp.ExpectExitCode(0) 31 32 ts.PrepareProject("ActiveState-CLI/small-python", e2e.CommitIDNotChecked) 33 cp = ts.Spawn("branch") 34 cp.Expect("main") 35 suite.Assert().NotContains(cp.Snapshot(), "To switch to another branch,") // only shows when multiple branches are listed 36 cp.ExpectExitCode(0) 37 } 38 39 func (suite *BranchIntegrationTestSuite) TestBranch_Add() { 40 suite.OnlyRunForTags(tagsuite.Branches) 41 suite.T().Skip("Skip test as state branch add functionality is currently disabled") 42 ts := e2e.New(suite.T(), false) 43 defer ts.Close() 44 45 ts.PrepareProject("ActiveState-CLI/Branch", e2e.CommitIDNotChecked) 46 47 ts.LoginAsPersistentUser() 48 49 cp := ts.Spawn("pull") 50 cp.Expect("Your project in the activestate.yaml has been updated") 51 cp.ExpectExitCode(0) 52 53 branchName, err := uuid.NewRandom() 54 suite.Require().NoError(err) 55 56 cp = ts.Spawn("branch", "add", branchName.String()) 57 cp.ExpectExitCode(0) 58 59 cp = ts.Spawn("branch") 60 cp.Expect(branchName.String()) 61 cp.ExpectExitCode(0) 62 } 63 64 func (suite *BranchIntegrationTestSuite) TestJSON() { 65 suite.OnlyRunForTags(tagsuite.Branches, tagsuite.JSON) 66 ts := e2e.New(suite.T(), false) 67 defer ts.Close() 68 69 cp := ts.Spawn("checkout", "ActiveState-CLI/Branches", ".") 70 cp.Expect("Skipping runtime setup") 71 cp.Expect("Checked out") 72 cp.ExpectExitCode(0) 73 74 cp = ts.Spawn("branch", "-o", "json") 75 cp.Expect(`"branchID":`) 76 cp.ExpectExitCode(0) 77 AssertValidJSON(suite.T(), cp) 78 } 79 80 func TestBranchIntegrationTestSuite(t *testing.T) { 81 suite.Run(t, new(BranchIntegrationTestSuite)) 82 }