Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions internal/testhelpers/e2e/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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("%[email protected]", 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, ""))
}
Expand Down
20 changes: 7 additions & 13 deletions test/integration/fork_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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() {
Expand All @@ -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()
}
Expand Down
7 changes: 5 additions & 2 deletions test/integration/import_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions test/integration/push_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,15 @@ func (suite *PushIntegrationTestSuite) TestInitAndPush() {

// Test pushing without permission, and choosing to create a new project
func (suite *PushIntegrationTestSuite) TestPush_NoPermission_NewProject() {
suite.T().Skip("Cannot create new unprivileged users") // DX-3190
if runtime.GOOS == "windows" {
suite.T().Skip("Skipped on Windows for now because SendKeyDown() doesnt work (regardless of bash/cmd)")
}

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")
Expand Down Expand Up @@ -155,12 +156,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())
}

Expand Down
Loading