Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty array stdout with --json flag #747

Merged
merged 14 commits into from
Apr 20, 2023
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
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPp
github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/auth0/go-auth0 v0.16.0 h1:ei3Ks5EXau96UQfz3Dak13+SyRw1cOMBGgEP+BCocXs=
github.com/auth0/go-auth0 v0.16.0/go.mod h1:k2iXR4WU9si22nKZO70NNf/rGf3vT4EzCzonPwhN13A=
github.com/auth0/go-auth0 v0.17.0 h1:nlDkW6Qc3xpeuv5iVUBRMeg4RDZ7d7oeBBPQbZ708us=
github.com/auth0/go-auth0 v0.17.0/go.mod h1:KiuxR7q2pTm9a1snjFi7y3KmPS+Bt1kgiJ8oSBvVkXo=
github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0 h1:0NmehRCgyk5rljDQLKUO+cRJCnduDyn11+zGZIc9Z48=
Expand Down
3 changes: 1 addition & 2 deletions internal/display/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ func (r *Renderer) ActionList(actions []*management.Action) {
r.Heading(resource)

if len(actions) == 0 {
r.EmptyState(resource)
r.Infof("Use 'auth0 actions create' to add one")
r.EmptyState(resource, "Use 'auth0 actions create' to add one")
return
}

Expand Down
5 changes: 2 additions & 3 deletions internal/display/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ func (r *Renderer) APIList(apis []*management.ResourceServer) {
r.Heading(fmt.Sprintf("%s (%d)", resource, len(apis)))

if len(apis) == 0 {
r.EmptyState(resource)
r.Infof("Use 'auth0 apis create' to add one")
r.EmptyState(resource, "Use 'auth0 apis create' to add one")
return
}

Expand Down Expand Up @@ -161,7 +160,7 @@ func (r *Renderer) ScopesList(api string, scopes []management.ResourceServerScop
r.Heading(fmt.Sprintf("%s of %s", resource, ansi.Bold(api)))

if len(scopes) == 0 {
r.EmptyState(resource)
r.EmptyState(resource, "")
return
}

Expand Down
3 changes: 1 addition & 2 deletions internal/display/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ func (r *Renderer) ApplicationList(clients []*management.Client, revealSecrets b
r.Heading(fmt.Sprintf("%s (%v)", resource, len(clients)))

if len(clients) == 0 {
r.EmptyState(resource)
r.Infof("Use 'auth0 apps create' to add one")
r.EmptyState(resource, "Use 'auth0 apps create' to add one")
return
}

Expand Down
3 changes: 1 addition & 2 deletions internal/display/custom_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ func (r *Renderer) CustomDomainList(customDomains []*management.CustomDomain) {
r.Heading(resource)

if len(customDomains) == 0 {
r.EmptyState(resource)
r.Infof("Use 'auth0 domains create' to add one")
r.EmptyState(resource, "Use 'auth0 domains create' to add one")
return
}

Expand Down
8 changes: 6 additions & 2 deletions internal/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ func (r *Renderer) Heading(text ...string) {
fmt.Fprintf(r.MessageWriter, "\n%s %s\n", ansi.Faint("==="), heading)
}

func (r *Renderer) EmptyState(resource string) {
fmt.Fprintf(r.MessageWriter, "No %s available.\n\n", resource)
func (r *Renderer) EmptyState(resource string, hint string) {
if r.Format == OutputFormatJSON {
willvedd marked this conversation as resolved.
Show resolved Hide resolved
r.JSONResult([]interface{}{})
return
}
r.Warnf("No %s available. %s\n", resource, hint)
}

func (r *Renderer) JSONResult(data interface{}) {
Expand Down
3 changes: 1 addition & 2 deletions internal/display/log_streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ func (r *Renderer) LogStreamList(logs []*management.LogStream) {
r.Heading(resource)

if len(logs) == 0 {
r.EmptyState(resource)
r.Infof("Use 'auth0 logs streams create' to add one")
r.EmptyState(resource, "Use 'auth0 logs streams create' to add one")
return
}

Expand Down
9 changes: 6 additions & 3 deletions internal/display/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,15 @@ func (r *Renderer) LogList(logs []*management.Log, silent, hasFilter bool) {

if len(logs) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

if len(logs) == 0 {
	if !hasFilter {
		r.EmptyState(resource, "To generate logs, run a test command like 'auth0 test login' or 'auth0 test token'")
		return
	}
	
	r.EmptyState("logs matching filter criteria", "")
	return
}

Like this it will print "No logs matching filter criteria available." and we have less complex code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO that reads very poorly. I'm glad we were able to reduce a couple one-off instances, but I think this one still makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both sentences are grammatically correct and convey the same meaning 🤷🏻‍♂️ Not a blocker tho.

if hasFilter {
r.Output("No logs available matching filter criteria.\n\n")
if r.Format == OutputFormatJSON {
r.JSONResult([]interface{}{})
return
}
r.Warnf("No logs available matching filter criteria.\n")
} else {
r.EmptyState(resource)
r.EmptyState(resource, "To generate logs, run a test command like 'auth0 test login' or 'auth0 test token'")
}

r.Infof("To generate logs, run a test command like 'auth0 test login' or 'auth0 test token'")
return
}

Expand Down
7 changes: 6 additions & 1 deletion internal/display/members.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ func (v *membersView) Object() interface{} {
}

func (r *Renderer) MembersList(members []management.OrganizationMember) {
resource := "members"
resource := "organization members"

r.Heading(resource)

if len(members) == 0 {
r.EmptyState(resource, "")
return
}

var res []View
for _, m := range members {
res = append(res, makeMembersView(&m))
Expand Down
3 changes: 1 addition & 2 deletions internal/display/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ func (r *Renderer) OrganizationList(organizations []*management.Organization) {
r.Heading(resource)

if len(organizations) == 0 {
r.EmptyState(resource)
r.Infof("Use 'auth0 orgs create' to add one")
r.EmptyState(resource, "Use 'auth0 orgs create' to add one")
return
}

Expand Down
3 changes: 1 addition & 2 deletions internal/display/role_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ func (r *Renderer) RolePermissionList(perms []*management.Permission) {
r.Heading(resource)

if len(perms) == 0 {
r.EmptyState(resource)
r.Infof("Use 'auth0 roles permissions add' to add one")
r.EmptyState(resource, "Use 'auth0 roles permissions add' to add one")
return
}

Expand Down
8 changes: 3 additions & 5 deletions internal/display/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ func (r *Renderer) RoleList(roles []*management.Role) {
r.Heading(fmt.Sprintf("%s (%d)", resource, len(roles)))

if len(roles) == 0 {
r.EmptyState(resource)
r.Infof("Use 'auth0 roles create' to add one")
r.EmptyState(resource, "Use 'auth0 roles create' to add one")
return
}

Expand All @@ -59,12 +58,11 @@ func (r *Renderer) RoleList(roles []*management.Role) {
}

func (r *Renderer) UserRoleList(roles []*management.Role) {
resource := "roles assigned to user"
resource := "user roles"
r.Heading(fmt.Sprintf("%s (%d)", resource, len(roles)))

if len(roles) == 0 {
r.Output("No roles assigned to user.\n\n")
r.Infof("Use 'auth0 users roles assign' to assign roles to a user.")
r.EmptyState(resource, "Use 'auth0 users roles assign' to assign roles to a user")
return
}

Expand Down
3 changes: 1 addition & 2 deletions internal/display/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ func (r *Renderer) RulesList(rules []*management.Rule) {
r.Heading(resource)

if len(rules) == 0 {
r.EmptyState(resource)
r.Infof("Use 'auth0 rules create' to add one")
r.EmptyState(resource, "Use 'auth0 rules create' to add one")
return
}

Expand Down
3 changes: 1 addition & 2 deletions internal/display/tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ func (r *Renderer) TenantList(data []string) {
r.Heading()

if len(data) == 0 {
r.EmptyState("tenants")
r.Infof("Use 'auth0 login' to add one")
r.EmptyState("tenants", "Use 'auth0 login' to add one")
return
}

Expand Down
2 changes: 1 addition & 1 deletion internal/display/user_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (r *Renderer) UserBlocksList(userBlocks []*management.UserBlock) {
r.Heading(resource)

if len(userBlocks) == 0 {
r.EmptyState(resource)
r.EmptyState(resource, "")
return
}

Expand Down
3 changes: 1 addition & 2 deletions internal/display/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ func (r *Renderer) UserSearch(users []*management.User) {
r.Heading(resource)

if len(users) == 0 {
r.EmptyState(resource)
r.Infof("Use 'auth0 users create' to add one")
r.EmptyState(resource, "Use 'auth0 users create' to add one")
return
}

Expand Down
24 changes: 15 additions & 9 deletions test/integration/actions-test-cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ tests:
contains:
- Use 'auth0 actions create' to add one

002 - it successfully creates an action:
002 - it successfully lists all actions with no data (json):
command: auth0 actions list --json
exit-code: 0
stdout:
exactly: "[]"

003 - it successfully creates an action:
command: auth0 actions create -n "integration-test-action1" -t "post-login" -c "function() {}" -d "lodash=4.0.0" -s "SECRET=value"
exit-code: 0
stdout:
Expand All @@ -24,7 +30,7 @@ tests:
- "CREATED 0 seconds ago"
- "CODE function() {}"

003 - it successfully lists all actions with data:
004 - it successfully lists all actions with data:
command: auth0 actions list
exit-code: 0
stdout:
Expand All @@ -35,7 +41,7 @@ tests:
- STATUS
- DEPLOYED

004 - it successfully creates an action and outputs in json:
005 - it successfully creates an action and outputs in json:
command: auth0 actions create -n "integration-test-action2" -t "post-login" -c "function() {}" -d "lodash=4.0.0" -s "SECRET=value" --json
exit-code: 0
stdout:
Expand All @@ -50,7 +56,7 @@ tests:
secrets.0.value: "value"
status: "pending"

005 - given a test action, it successfully gets the action's details:
006 - given a test action, it successfully gets the action's details:
command: auth0 actions show $(./test/integration/scripts/get-action-id.sh)
exit-code: 0
stdout:
Expand All @@ -64,7 +70,7 @@ tests:
- "CREATED"
- "CODE function() {}"

006 - given a test action, it successfully gets the action's details and outputs in json:
007 - given a test action, it successfully gets the action's details and outputs in json:
command: auth0 actions show $(./test/integration/scripts/get-action-id.sh) --json
exit-code: 0
stdout:
Expand All @@ -77,7 +83,7 @@ tests:
dependencies.0.version: "4.0.0"
secrets.0.name: "SECRET"

007 - given a test action, it successfully updates the action's details:
008 - given a test action, it successfully updates the action's details:
command: auth0 actions update $(./test/integration/scripts/get-action-id.sh) -n "integration-test-action-updated" -c "function() {console.log()}" -d "uuid=9.0.0" -s "SECRET2=newValue"
exit-code: 0
stdout:
Expand All @@ -91,7 +97,7 @@ tests:
- "CREATED"
- "CODE function() {console.log()}"

008 - given a test action, it successfully updates the action's details and outputs in json:
009 - given a test action, it successfully updates the action's details and outputs in json:
command: auth0 actions update $(./test/integration/scripts/get-action-id.sh) -n "integration-test-action-updated-again" -c "function() {console.log()}" -d "uuid=9.0.0" -s "SECRET3=newValue" --json
exit-code: 0
stdout:
Expand All @@ -105,13 +111,13 @@ tests:
secrets.0.name: "SECRET3"
secrets.0.value: "newValue"

009 - given a test action, it successfully opens the settings page:
010 - given a test action, it successfully opens the settings page:
command: auth0 actions open $(./test/integration/scripts/get-action-id.sh) --no-input
exit-code: 0
stderr:
contains:
- "Open the following URL in a browser"

010 - given a test action, it successfully deletes the action:
011 - given a test action, it successfully deletes the action:
command: auth0 actions delete $(./test/integration/scripts/get-action-id.sh) --force
exit-code: 0
45 changes: 36 additions & 9 deletions test/integration/custom-domains-test-cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@ config:
retries: 1

tests:
001 - list domains:
001 - list domains with no results:
command: auth0 domains list
exit-code: 0
002 - create domain with minimal flags:
stderr:
contains:
- No custom domains available.
- Use 'auth0 domains create' to add one

002 - list domains with no results (json):
command: auth0 domains list --json
exit-code: 0
stdout:
exactly: "[]"

003 - create domain with minimal flags:
command: auth0 domains create --domain "custom-domain.com" --no-input
exit-code: 0
stdout:
Expand All @@ -15,13 +26,15 @@ tests:
- "DOMAIN custom-domain.com"
- "STATUS pending_verification"
- "PROVISIONING TYPE auth0_managed_certs"
003 - unsuccessfully create domain with same name:

004 - unsuccessfully create domain with same name:
command: auth0 domains create --domain "custom-domain.com" --no-input
exit-code: 1
stderr:
contains:
- "An unexpected error occurred while attempting to create the custom domain 'custom-domain.com': 409 Conflict: The specified custom domain already exists"
004 - show domain:

005 - show domain:
command: auth0 domains show $(./test/integration/scripts/get-custom-domain-id.sh) --no-input
exit-code: 0
stdout:
Expand All @@ -30,7 +43,8 @@ tests:
- "DOMAIN custom-domain.com"
- "STATUS pending_verification"
- "PROVISIONING TYPE auth0_managed_certs"
005 - update domain minimal flags:

006 - update domain minimal flags:
command: auth0 domains update $(./test/integration/scripts/get-custom-domain-id.sh) --no-input
exit-code: 0
stdout:
Expand All @@ -39,7 +53,8 @@ tests:
- "DOMAIN custom-domain.com"
- "STATUS pending_verification"
- "PROVISIONING TYPE auth0_managed_certs"
006 - update domain maximal flags:

007 - update domain maximal flags:
command: auth0 domains update $(./test/integration/scripts/get-custom-domain-id.sh) --policy recommended --no-input
exit-code: 0
stdout:
Expand All @@ -49,7 +64,8 @@ tests:
- "STATUS pending_verification"
- "PROVISIONING TYPE auth0_managed_certs"
- "TLS POLICY recommended"
007 - verify domain:

008 - verify domain:
command: auth0 domains update $(./test/integration/scripts/get-custom-domain-id.sh) --policy recommended --no-input
exit-code: 0
stdout:
Expand All @@ -58,10 +74,12 @@ tests:
- "DOMAIN custom-domain.com"
- "PROVISIONING TYPE auth0_managed_certs"
- "TLS POLICY recommended"
008 - delete domain:

009 - delete domain:
command: auth0 domains delete $(./test/integration/scripts/get-custom-domain-id.sh) --no-input
exit-code: 0
009 - create domain with maximal flags:

010 - create domain with maximal flags:
command: auth0 domains create --domain "custom-domain.com" --verification txt --type self --policy recommended --no-input
exit-code: 0
stdout:
Expand All @@ -73,3 +91,12 @@ tests:
- "VERIFICATION METHOD txt"
- "TLS POLICY recommended"
- "CUSTOM CLIENT IP HEADER"

011 - list custom domains with results:
command: auth0 domains list
exit-code: 0
stdout:
contains:
- "ID DOMAIN STATUS"
- "cd_"
- "custom-domain.com"
2 changes: 1 addition & 1 deletion test/integration/fixtures/update-rule.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "rul_LBnc1o7UxvuiEmkt",
"id": "rul_xWavq6OFKbMma9DH",
"name": "integration-test-rule-betterName",
"script": "function(user, context, cb) {\n cb(null, user, context);\n}\n",
"order": 3,
Expand Down
Loading