-
Notifications
You must be signed in to change notification settings - Fork 11
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
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. | user-for-org-create-test@example.com | | ||
+------+-----------+--------------------------------------+ | ||
`, "\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. | user-for-org-create-test@example.com | | ||
| hooli | Hooli | user-for-org-create-test@example.com | | ||
+-------+-----------+--------------------------------------+ | ||
`, "\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
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