Skip to content

Commit

Permalink
Use mockapi ID generator functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcdawkins committed Dec 29, 2024
1 parent 695fcef commit 2fc3f37
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 37 deletions.
2 changes: 1 addition & 1 deletion go-tests/activity_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestActivityList(t *testing.T) {
apiServer := httptest.NewServer(apiHandler)
defer apiServer.Close()

projectID := "oth9aidoo4zio"
projectID := mockapi.ProjectID()

apiHandler.SetProjects([]*mockapi.Project{{
ID: projectID,
Expand Down
2 changes: 1 addition & 1 deletion go-tests/app_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestAppConfig(t *testing.T) {

apiHandler := mockapi.NewHandler(t)

projectID := "aht1iegh3nei9"
projectID := mockapi.ProjectID()

apiHandler.SetProjects([]*mockapi.Project{{
ID: projectID,
Expand Down
2 changes: 1 addition & 1 deletion go-tests/app_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestAppList(t *testing.T) {
apiServer := httptest.NewServer(apiHandler)
defer apiServer.Close()

projectID := "nu8ohgeizah1a"
projectID := mockapi.ProjectID()

apiHandler.SetProjects([]*mockapi.Project{{
ID: projectID,
Expand Down
4 changes: 2 additions & 2 deletions go-tests/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestBackupList(t *testing.T) {
apiServer := httptest.NewServer(apiHandler)
defer apiServer.Close()

projectID := "rai7quieroohu"
projectID := mockapi.ProjectID()

apiHandler.SetProjects([]*mockapi.Project{
{
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestBackupCreate(t *testing.T) {
apiServer := httptest.NewServer(apiHandler)
defer apiServer.Close()

projectID := "vei8wah5Ohl2e"
projectID := mockapi.ProjectID()

apiHandler.SetProjects([]*mockapi.Project{
{
Expand Down
2 changes: 1 addition & 1 deletion go-tests/environment_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestEnvironmentInfo(t *testing.T) {

apiHandler := mockapi.NewHandler(t)

projectID := "vishiv0aighae"
projectID := mockapi.ProjectID()

apiHandler.SetProjects([]*mockapi.Project{
{
Expand Down
24 changes: 13 additions & 11 deletions go-tests/environment_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ func TestEnvironmentList(t *testing.T) {
apiServer := httptest.NewServer(apiHandler)
defer apiServer.Close()

projectID := mockapi.ProjectID()

apiHandler.SetProjects([]*mockapi.Project{
{
ID: mockProjectID,
ID: projectID,
Links: mockapi.MakeHALLinks(
"self=/projects/"+mockProjectID,
"environments=/projects/"+mockProjectID+"/environments",
"self=/projects/"+projectID,
"environments=/projects/"+projectID+"/environments",
),
},
})
apiHandler.SetEnvironments([]*mockapi.Environment{
makeEnv(mockProjectID, "main", "production", "active", nil),
makeEnv(mockProjectID, "staging", "staging", "active", "main"),
makeEnv(mockProjectID, "dev", "development", "active", "staging"),
makeEnv(mockProjectID, "fix", "development", "inactive", "dev"),
makeEnv(projectID, "main", "production", "active", nil),
makeEnv(projectID, "staging", "staging", "active", "main"),
makeEnv(projectID, "dev", "development", "active", "staging"),
makeEnv(projectID, "fix", "development", "inactive", "dev"),
})

f := newCommandFactory(t, apiServer.URL, authServer.URL)
Expand All @@ -47,24 +49,24 @@ func TestEnvironmentList(t *testing.T) {
| dev | Dev | Active | development |
| fix | Fix | Inactive | development |
+-----------+---------+----------+-------------+
`, f.Run("environment:list", "-v", "-p", mockProjectID))
`, f.Run("environment:list", "-v", "-p", projectID))

assertTrimmed(t, `
ID Title Status Type
main Main Active production
staging Staging Active staging
dev Dev Active development
fix Fix Inactive development
`, f.Run("environment:list", "-v", "-p", mockProjectID, "--format", "plain"))
`, f.Run("environment:list", "-v", "-p", projectID, "--format", "plain"))

assertTrimmed(t, `
ID Title Status Type
main Main Active production
staging Staging Active staging
dev Dev Active development
`, f.Run("environment:list", "-v", "-p", mockProjectID, "--format", "plain", "--no-inactive"))
`, f.Run("environment:list", "-v", "-p", projectID, "--format", "plain", "--no-inactive"))

assert.Equal(t, "fix\n", f.Run("environment:list", "-v", "-p", mockProjectID, "--pipe", "--status=inactive"))
assert.Equal(t, "fix\n", f.Run("environment:list", "-v", "-p", projectID, "--pipe", "--status=inactive"))
}

func makeEnv(projectID, name, envType, status string, parent any) *mockapi.Environment {
Expand Down
2 changes: 1 addition & 1 deletion go-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/platformsh/legacy-cli/tests
go 1.22.9

require (
github.com/platformsh/cli v0.0.0-20241229114059-6abd256f63d0
github.com/platformsh/cli v0.0.0-20241229194532-b86546247906
github.com/stretchr/testify v1.9.0
)

Expand Down
4 changes: 2 additions & 2 deletions go-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ github.com/oklog/ulid/v2 v2.1.0 h1:+9lhoxAP56we25tyYETBBY1YLA2SaoLvUFgrP2miPJU=
github.com/oklog/ulid/v2 v2.1.0/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=
github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/platformsh/cli v0.0.0-20241229114059-6abd256f63d0 h1:Im0GlY2U42e464pX3V0baCcRGoWihpv1SrHFEPp5U7I=
github.com/platformsh/cli v0.0.0-20241229114059-6abd256f63d0/go.mod h1:jMxyJGLMlkjDq7l9cVWFhsX/8xxFqEOH95rWbDFyO08=
github.com/platformsh/cli v0.0.0-20241229194532-b86546247906 h1:BvQf2yvT7USm80fAJ0C5FXfTfjjK2onrnoVMPz5CT9k=
github.com/platformsh/cli v0.0.0-20241229194532-b86546247906/go.mod h1:jMxyJGLMlkjDq7l9cVWFhsX/8xxFqEOH95rWbDFyO08=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
Expand Down
2 changes: 1 addition & 1 deletion go-tests/mount_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestMountList(t *testing.T) {
apiServer := httptest.NewServer(apiHandler)
defer apiServer.Close()

projectID := "oa3chu0foot4s"
projectID := mockapi.ProjectID()

apiHandler.SetProjects([]*mockapi.Project{{
ID: projectID,
Expand Down
4 changes: 2 additions & 2 deletions go-tests/project_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestProjectInfo(t *testing.T) {
makeOrg("org-id-1", "org-1", "Org 1", myUserID),
})

projectID := "eer4jee4ri3mo"
projectID := mockapi.ProjectID()
created, err := time.Parse(time.RFC3339, "2014-04-01T10:00:00+01:00")
require.NoError(t, err)

Expand All @@ -56,7 +56,7 @@ func TestProjectInfo(t *testing.T) {
f := newCommandFactory(t, apiServer.URL, authServer.URL)

expectedLines := `Property Value
id eer4jee4ri3mo
id ` + projectID + `
title Project 1
region region-1
organization org-id-1
Expand Down
2 changes: 1 addition & 1 deletion go-tests/route_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestRouteList(t *testing.T) {

apiHandler := mockapi.NewHandler(t)

projectID := "iewohthoo1ein"
projectID := mockapi.ProjectID()

apiHandler.SetProjects([]*mockapi.Project{{
ID: projectID,
Expand Down
2 changes: 1 addition & 1 deletion go-tests/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestSSH(t *testing.T) {
}
})

projectID := "aiyaikii1uere"
projectID := mockapi.ProjectID()

apiHandler := mockapi.NewHandler(t)
apiHandler.SetMyUser(&mockapi.User{ID: myUserID})
Expand Down
4 changes: 0 additions & 4 deletions go-tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import (

var _validatedCommand string

// The legacy CLI identifier expects project IDs to be alphanumeric.
// See: https://github.com/platformsh/legacy-cli/blob/main/src/Service/Identifier.php#L75
const mockProjectID = "abcdefg123456"

func getCommandName(t *testing.T) string {
if testing.Short() {
t.Skip("skipping integration test due to -short flag")
Expand Down
13 changes: 7 additions & 6 deletions go-tests/user_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func TestUserList(t *testing.T) {
authServer := mockapi.NewAuthServer(t)
defer authServer.Close()

projectID := mockapi.ProjectID()
myUserID := "my-user-id"
vendor := "test-vendor"

Expand All @@ -23,7 +24,7 @@ func TestUserList(t *testing.T) {
makeOrg("org-id-1", "org-1", "Org 1", myUserID),
})
apiHandler.SetProjects([]*mockapi.Project{
makeProject(mockProjectID, "org-id-1", vendor, "Project 1", "region-1"),
makeProject(projectID, "org-id-1", vendor, "Project 1", "region-1"),
})
apiHandler.SetUserGrants([]*mockapi.UserGrant{
{
Expand All @@ -34,21 +35,21 @@ func TestUserList(t *testing.T) {
Permissions: []string{"admin"},
},
{
ResourceID: mockProjectID,
ResourceID: projectID,
ResourceType: "project",
OrganizationID: "org-id-1",
UserID: myUserID,
Permissions: []string{"admin"},
},
{
ResourceID: mockProjectID,
ResourceID: projectID,
ResourceType: "project",
OrganizationID: "org-id-1",
UserID: "user-id-2",
Permissions: []string{"viewer", "development:viewer"},
},
{
ResourceID: mockProjectID,
ResourceID: projectID,
ResourceType: "project",
OrganizationID: "org-id-1",
UserID: "user-id-3",
Expand All @@ -66,12 +67,12 @@ func TestUserList(t *testing.T) {
| [email protected] | User user-id-2 | viewer | user-id-2 |
| [email protected] | User user-id-3 | viewer | user-id-3 |
+------------------------+-----------------+--------------+------------+
`, f.Run("users", "-p", mockProjectID))
`, f.Run("users", "-p", projectID))

assertTrimmed(t, `
Email address Name Project role ID Permissions
[email protected] User my-user-id admin my-user-id admin
[email protected] User user-id-2 viewer user-id-2 viewer, development:viewer
[email protected] User user-id-3 viewer user-id-3 viewer, production:viewer, development:admin, staging:contributor
`, f.Run("users", "-p", mockProjectID, "--format", "plain", "--columns", "+perm%"))
`, f.Run("users", "-p", projectID, "--format", "plain", "--columns", "+perm%"))
}
2 changes: 1 addition & 1 deletion go-tests/variable_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestVariableList(t *testing.T) {
apiServer := httptest.NewServer(apiHandler)
defer apiServer.Close()

projectID := "su0heinehei7i"
projectID := mockapi.ProjectID()

apiHandler.SetProjects([]*mockapi.Project{{
ID: projectID,
Expand Down
2 changes: 1 addition & 1 deletion go-tests/variable_write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestVariableCreate(t *testing.T) {
apiServer := httptest.NewServer(apiHandler)
defer apiServer.Close()

projectID := "ohnguk9zeiw3b"
projectID := mockapi.ProjectID()

apiHandler.SetProjects([]*mockapi.Project{{
ID: projectID,
Expand Down

0 comments on commit 2fc3f37

Please sign in to comment.