github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/test/integration/fork_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  
    10  	"github.com/ActiveState/cli/internal/testhelpers/e2e"
    11  	"github.com/ActiveState/cli/internal/testhelpers/tagsuite"
    12  )
    13  
    14  type ForkIntegrationTestSuite struct {
    15  	tagsuite.Suite
    16  }
    17  
    18  func (suite *ForkIntegrationTestSuite) cleanup(ts *e2e.Session) {
    19  	cp := ts.Spawn(tagsuite.Auth, "logout")
    20  	cp.ExpectExitCode(0)
    21  	ts.Close()
    22  }
    23  
    24  func (suite *ForkIntegrationTestSuite) TestFork() {
    25  	suite.OnlyRunForTags(tagsuite.Fork)
    26  	ts := e2e.New(suite.T(), false)
    27  	defer suite.cleanup(ts)
    28  
    29  	user := ts.CreateNewUser()
    30  
    31  	cp := ts.Spawn("fork", "ActiveState-CLI/Python3", "--name", "Test-Python3", "--org", user.Username)
    32  	cp.Expect("fork has been successfully created")
    33  	cp.ExpectExitCode(0)
    34  
    35  	// Check if we error out on conflicts properly
    36  	cp = ts.Spawn("fork", "ActiveState-CLI/Python3", "--name", "Test-Python3", "--org", user.Username)
    37  	cp.Expect(`You already have a project with the name`)
    38  	cp.ExpectExitCode(1)
    39  	ts.IgnoreLogErrors()
    40  }
    41  
    42  func (suite *ForkIntegrationTestSuite) TestFork_FailNameExists() {
    43  	suite.OnlyRunForTags(tagsuite.Fork)
    44  	ts := e2e.New(suite.T(), false)
    45  	defer suite.cleanup(ts)
    46  	ts.LoginAsPersistentUser()
    47  
    48  	cp := ts.SpawnWithOpts(e2e.OptArgs("fork", "ActiveState-CLI/Python3", "--org", e2e.PersistentUsername))
    49  	cp.Expect("You already have a project with the name 'Python3'", termtest.OptExpectTimeout(30*time.Second))
    50  	cp.ExpectNotExitCode(0)
    51  	ts.IgnoreLogErrors()
    52  }
    53  
    54  func TestForkIntegrationTestSuite(t *testing.T) {
    55  	suite.Run(t, new(ForkIntegrationTestSuite))
    56  }