diff --git a/internal/testhelpers/e2e/session.go b/internal/testhelpers/e2e/session.go index 9655aae58f..17d993cfea 100644 --- a/internal/testhelpers/e2e/session.go +++ b/internal/testhelpers/e2e/session.go @@ -28,9 +28,6 @@ import ( "github.com/ActiveState/cli/internal/subshell/bash" "github.com/ActiveState/cli/internal/subshell/sscommon" "github.com/ActiveState/cli/internal/testhelpers/tagsuite" - "github.com/ActiveState/cli/pkg/platform/api" - "github.com/ActiveState/cli/pkg/platform/api/mono" - "github.com/ActiveState/cli/pkg/platform/api/mono/mono_client/users" "github.com/ActiveState/cli/pkg/platform/api/mono/mono_models" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -39,7 +36,6 @@ import ( "github.com/ActiveState/cli/pkg/projectfile" "github.com/ActiveState/termtest" "github.com/go-openapi/strfmt" - "github.com/google/uuid" "github.com/phayes/permbits" "github.com/stretchr/testify/require" ) @@ -448,48 +444,8 @@ func (s *Session) LogoutUser() { p.ExpectExitCode(0) } -func (s *Session) CreateNewUser() *mono_models.UserEditable { - uid, err := uuid.NewRandom() - require.NoError(s.T, err) - - username := fmt.Sprintf("user-%s", uid.String()[0:8]) - password := uid.String()[8:] - email := fmt.Sprintf("%s@test.tld", username) - user := &mono_models.UserEditable{ - Username: username, - Password: password, - Name: username, - Email: email, - } - - params := users.NewAddUserParams() - params.SetUser(user) - - // The default mono API client host is "testing.tld" inside unit tests. - // Since we actually want to create production users, we need to manually instantiate a mono API - // client with the right host. - serviceURL := api.GetServiceURL(api.ServiceMono) - host := os.Getenv(constants.APIHostEnvVarName) - if host == "" { - host = constants.DefaultAPIHost - } - serviceURL.Host = strings.Replace(serviceURL.Host, string(api.ServiceMono)+api.TestingPlatform, host, 1) - _, err = mono.Init(serviceURL, nil).Users.AddUser(params) - require.NoError(s.T, err, "Error creating new user") - - p := s.Spawn(tagsuite.Auth, "--username", username, "--password", password) - p.Expect("logged in") - p.ExpectExitCode(0) - - s.users = append(s.users, username) - - return user -} - // NotifyProjectCreated indicates that the given project was created on the Platform and needs to // be deleted when the session is closed. -// This only needs to be called for projects created by PersistentUsername, not projects created by -// users created with CreateNewUser(). Created users' projects are auto-deleted. func (s *Session) NotifyProjectCreated(org, name string) { s.createdProjects = append(s.createdProjects, project.NewNamespace(org, name, "")) } diff --git a/test/integration/fork_int_test.go b/test/integration/fork_int_test.go index f26df5e682..31cdf1bc75 100644 --- a/test/integration/fork_int_test.go +++ b/test/integration/fork_int_test.go @@ -2,12 +2,10 @@ package integration import ( "testing" - "time" - - "github.com/ActiveState/cli/internal/testhelpers/suite" - "github.com/ActiveState/termtest" + "github.com/ActiveState/cli/internal/strutils" "github.com/ActiveState/cli/internal/testhelpers/e2e" + "github.com/ActiveState/cli/internal/testhelpers/suite" "github.com/ActiveState/cli/internal/testhelpers/tagsuite" ) @@ -26,17 +24,13 @@ func (suite *ForkIntegrationTestSuite) TestFork() { ts := e2e.New(suite.T(), false) defer suite.cleanup(ts) - user := ts.CreateNewUser() + ts.LoginAsPersistentUser() + pname := strutils.UUID() - cp := ts.Spawn("fork", "ActiveState-CLI/Python3", "--name", "Test-Python3", "--org", user.Username) + cp := ts.Spawn("fork", "ActiveState-CLI/Python3", "--name", pname.String(), "--org", e2e.PersistentUsername) cp.Expect("fork has been successfully created") cp.ExpectExitCode(0) - - // Check if we error out on conflicts properly - cp = ts.Spawn("fork", "ActiveState-CLI/Python3", "--name", "Test-Python3", "--org", user.Username) - cp.Expect(`You already have a project with the name`) - cp.ExpectExitCode(1) - ts.IgnoreLogErrors() + ts.NotifyProjectCreated(e2e.PersistentUsername, pname.String()) } func (suite *ForkIntegrationTestSuite) TestFork_FailNameExists() { @@ -46,7 +40,7 @@ func (suite *ForkIntegrationTestSuite) TestFork_FailNameExists() { ts.LoginAsPersistentUser() cp := ts.Spawn("fork", "ActiveState-CLI/Python3", "--org", e2e.PersistentUsername) - cp.Expect("You already have a project with the name 'Python3'", termtest.OptExpectTimeout(30*time.Second)) + cp.Expect("You already have a project with the name 'Python3'") cp.ExpectNotExitCode(0) ts.IgnoreLogErrors() } diff --git a/test/integration/import_int_test.go b/test/integration/import_int_test.go index 47c9c9cd7b..8b4b5eba5f 100644 --- a/test/integration/import_int_test.go +++ b/test/integration/import_int_test.go @@ -11,6 +11,7 @@ import ( "github.com/ActiveState/termtest" "github.com/ActiveState/cli/internal/constants" + "github.com/ActiveState/cli/internal/strutils" "github.com/ActiveState/cli/internal/testhelpers/e2e" "github.com/ActiveState/cli/internal/testhelpers/osutil" "github.com/ActiveState/cli/internal/testhelpers/suite" @@ -85,12 +86,14 @@ func (suite *ImportIntegrationTestSuite) TestImport() { ts := e2e.New(suite.T(), false) defer ts.Close() - user := ts.CreateNewUser() - namespace := fmt.Sprintf("%s/%s", user.Username, "Python3") + ts.LoginAsPersistentUser() + pname := strutils.UUID() + namespace := fmt.Sprintf("%s/%s", e2e.PersistentUsername, pname.String()) cp := ts.Spawn("init", "--language", "python", namespace, ts.Dirs.Work) cp.Expect("successfully initialized", e2e.RuntimeSourcingTimeoutOpt) cp.ExpectExitCode(0) + ts.NotifyProjectCreated(e2e.PersistentUsername, pname.String()) reqsFilePath := filepath.Join(cp.WorkDirectory(), reqsFileName) diff --git a/test/integration/push_int_test.go b/test/integration/push_int_test.go index 6a6e03514f..4f3276cd9c 100644 --- a/test/integration/push_int_test.go +++ b/test/integration/push_int_test.go @@ -116,7 +116,7 @@ func (suite *PushIntegrationTestSuite) TestPush_NoPermission_NewProject() { suite.OnlyRunForTags(tagsuite.Push) ts := e2e.New(suite.T(), false) defer ts.Close() - user := ts.CreateNewUser() + ts.LoginAsPersistentUser() pname := strutils.UUID() cp := ts.Spawn("config", "set", constants.AsyncRuntimeConfig, "true") @@ -155,12 +155,11 @@ func (suite *PushIntegrationTestSuite) TestPush_NoPermission_NewProject() { cp.SendLine(pname.String()) cp.Expect("Project created") cp.ExpectExitCode(0) - // Note: no need for ts.NotifyProjectCreated because newly created users and their projects are - // auto-cleaned by e2e. + ts.NotifyProjectCreated(e2e.PersistentUsername, pname.String()) pjfile, err = projectfile.Parse(pjfilepath) suite.Require().NoError(err) - suite.Require().Contains(pjfile.Project, user.Username) + suite.Require().Contains(pjfile.Project, e2e.PersistentUsername) suite.Require().Contains(pjfile.Project, pname.String()) }