-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test the org:create and org:info commands
- Loading branch information
1 parent
9aad277
commit 31c7381
Showing
10 changed files
with
199 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ func TestAuthInfo(t *testing.T) { | |
| email | [email protected] | | ||
| phone_number_verified | true | | ||
+-----------------------+---------------------+ | ||
`, "\n"), run("auth:info", "-v")) | ||
`, "\n"), run("auth:info", "-v", "--refresh")) | ||
|
||
assert.Equal(t, "my-user-id\n", run("auth:info", "-P", "id")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package tests | ||
|
||
import ( | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/platformsh/cli/internal/mockapi" | ||
) | ||
|
||
func TestOrgCreate(t *testing.T) { | ||
authServer := mockapi.NewAuthServer(t) | ||
defer authServer.Close() | ||
|
||
myUserID := "user-for-org-create-test" | ||
|
||
apiHandler := mockapi.NewHandler(t) | ||
apiHandler.SetMyUser(&mockapi.User{ID: myUserID}) | ||
apiHandler.SetOrgs([]*mockapi.Org{ | ||
makeOrg("org-id-1", "acme", "ACME Inc.", myUserID), | ||
}) | ||
|
||
apiServer := httptest.NewServer(apiHandler) | ||
defer apiServer.Close() | ||
|
||
run := runnerWithAuth(t, apiServer.URL, authServer.URL) | ||
|
||
// TODO disable the cache? | ||
run("cc") | ||
|
||
assert.Equal(t, strings.TrimLeft(` | ||
+------+-----------+--------------------------------------+ | ||
| Name | Label | Owner email | | ||
+------+-----------+--------------------------------------+ | ||
| acme | ACME Inc. | [email protected] | | ||
+------+-----------+--------------------------------------+ | ||
`, "\n"), run("orgs")) | ||
|
||
runCombinedOutput := runnerCombinedOutput(t, apiServer.URL, authServer.URL) | ||
|
||
co, err := runCombinedOutput("org:create", "--name", "hooli", "--yes") | ||
assert.Error(t, err) | ||
assert.Contains(t, co, "--country is required") | ||
|
||
co, err = runCombinedOutput("org:create", "--name", "hooli", "--yes", "--country", "XY") | ||
assert.Error(t, err) | ||
assert.Contains(t, co, "Invalid country: XY") | ||
|
||
co, err = runCombinedOutput("org:create", "--name", "hooli", "--yes", "--country", "US") | ||
assert.NoError(t, err) | ||
assert.Contains(t, co, "Hooli") | ||
|
||
assert.Equal(t, strings.TrimLeft(` | ||
+-------+-----------+--------------------------------------+ | ||
| Name | Label | Owner email | | ||
+-------+-----------+--------------------------------------+ | ||
| acme | ACME Inc. | [email protected] | | ||
| hooli | Hooli | [email protected] | | ||
+-------+-----------+--------------------------------------+ | ||
`, "\n"), run("orgs")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package tests | ||
|
||
import ( | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/platformsh/cli/internal/mockapi" | ||
) | ||
|
||
func TestOrgInfo(t *testing.T) { | ||
authServer := mockapi.NewAuthServer(t) | ||
defer authServer.Close() | ||
|
||
myUserID := "user-for-org-info-test" | ||
|
||
apiHandler := mockapi.NewHandler(t) | ||
apiHandler.SetMyUser(&mockapi.User{ID: myUserID}) | ||
apiServer := httptest.NewServer(apiHandler) | ||
defer apiServer.Close() | ||
|
||
apiHandler.SetOrgs([]*mockapi.Org{ | ||
makeOrg("org-id-1", "org-1", "Org 1", myUserID), | ||
}) | ||
|
||
run := runnerWithAuth(t, apiServer.URL, authServer.URL) | ||
|
||
assert.Contains(t, run("org:info", "-o", "org-1", "--format", "csv", "--refresh"), `Property,Value | ||
id,org-id-1 | ||
name,org-1 | ||
label,Org 1 | ||
owner_id,user-for-org-info-test | ||
capabilities,`) | ||
|
||
assert.Equal(t, "Org 1\n", run("org:info", "-o", "org-1", "label")) | ||
|
||
runCombinedOutput := runnerCombinedOutput(t, apiServer.URL, authServer.URL) | ||
co, err := runCombinedOutput("org:info", "-o", "org-1", "label", "New Label") | ||
assert.NoError(t, err) | ||
assert.Contains(t, co, "Property label set to: New Label\n") | ||
|
||
assert.Equal(t, "New Label\n", run("org:info", "-o", "org-1", "label")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,31 +35,32 @@ func TestOrgList(t *testing.T) { | |
| Name | Label | Owner email | | ||
+--------------+--------------------------------+-----------------------+ | ||
| acme | ACME Inc. | [email protected] | | ||
| four-seasons | Four Seasons Total Landscaping | [email protected] | | ||
| duff | Duff Beer | [email protected] | | ||
| four-seasons | Four Seasons Total Landscaping | [email protected] | | ||
+--------------+--------------------------------+-----------------------+ | ||
`, "\n"), run("orgs")) | ||
|
||
assert.Equal(t, strings.TrimLeft(` | ||
Name Label Owner email | ||
acme ACME Inc. [email protected] | ||
four-seasons Four Seasons Total Landscaping [email protected] | ||
duff Duff Beer [email protected] | ||
four-seasons Four Seasons Total Landscaping [email protected] | ||
`, "\n"), run("orgs", "--format", "plain")) | ||
|
||
assert.Equal(t, strings.TrimLeft(` | ||
org-id-1,acme | ||
org-id-2,four-seasons | ||
org-id-3,duff | ||
org-id-2,four-seasons | ||
`, "\n"), run("orgs", "--format", "csv", "--columns", "id,name", "--no-header")) | ||
} | ||
|
||
func makeOrg(id, name, label, owner string) *mockapi.Org { | ||
return &mockapi.Org{ | ||
ID: id, | ||
Name: name, | ||
Label: label, | ||
Owner: owner, | ||
Links: mockapi.MakeHALLinks("self=/organizations/" + url.PathEscape(id)), | ||
ID: id, | ||
Name: name, | ||
Label: label, | ||
Owner: owner, | ||
Capabilities: []string{}, | ||
Links: mockapi.MakeHALLinks("self=/organizations/" + url.PathEscape(id)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters