Skip to content

Commit 840f9d9

Browse files
authored
Merge branch 'main' into dependabot/go_modules/github.com/getsentry/sentry-go-0.40.0
2 parents ce94b53 + efacd55 commit 840f9d9

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

internal/cli/apps.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,24 @@ func createAppCmd(cli *cli) *cobra.Command {
513513

514514
// Prompt for resource server identifier if app type is resource_server.
515515
if appIsResourceServer {
516-
if err := appResourceServerIdentifier.Ask(cmd, &inputs.ResourceServerIdentifier, nil); err != nil {
517-
return err
516+
if !appResourceServerIdentifier.IsSet(cmd) {
517+
var selectedAPIID string
518+
if err := appResourceServerIdentifier.Pick(cmd, &selectedAPIID, cli.apiPickerOptionsWithoutAuth0); err != nil {
519+
return err
520+
}
521+
522+
var selectedAPI *management.ResourceServer
523+
if err := ansi.Waiting(func() error {
524+
var err error
525+
selectedAPI, err = cli.api.ResourceServer.Read(cmd.Context(), selectedAPIID)
526+
return err
527+
}); err != nil {
528+
return fmt.Errorf("failed to read selected API: %w", err)
529+
}
530+
531+
inputs.ResourceServerIdentifier = selectedAPI.GetIdentifier()
532+
} else if strings.TrimSpace(inputs.ResourceServerIdentifier) == "" {
533+
return fmt.Errorf("resource-server-identifier cannot be empty for resource_server app type")
518534
}
519535
}
520536

internal/cli/apps_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,54 @@ func TestAppsListCmd(t *testing.T) {
9090
}
9191
}
9292

93+
func TestAppsCreateCmd(t *testing.T) {
94+
tests := []struct {
95+
name string
96+
args []string
97+
expectedError string
98+
}{
99+
{
100+
name: "Resource Server - resource-server-identifier is empty string",
101+
args: []string{
102+
"--name", "My Resource Server App",
103+
"--type", "resource_server",
104+
"--resource-server-identifier", "",
105+
},
106+
expectedError: "resource-server-identifier cannot be empty for resource_server app type",
107+
},
108+
{
109+
name: "Resource Server - resource-server-identifier is whitespace only",
110+
args: []string{
111+
"--name", "My Resource Server App",
112+
"--type", "resource_server",
113+
"--resource-server-identifier", " ",
114+
},
115+
expectedError: "resource-server-identifier cannot be empty for resource_server app type",
116+
},
117+
{
118+
name: "Resource Server - resource-server-identifier is tab/newline",
119+
args: []string{
120+
"--name", "My Resource Server App",
121+
"--type", "resource_server",
122+
"--resource-server-identifier", "\t\n",
123+
},
124+
expectedError: "resource-server-identifier cannot be empty for resource_server app type",
125+
},
126+
}
127+
128+
for _, test := range tests {
129+
t.Run(test.name, func(t *testing.T) {
130+
cli := &cli{}
131+
cli.noInput = true // Non-interactive mode.
132+
cmd := createAppCmd(cli)
133+
cmd.SetArgs(test.args)
134+
err := cmd.Execute()
135+
136+
assert.EqualError(t, err, test.expectedError)
137+
})
138+
}
139+
}
140+
93141
func TestFormatAppSettingsPath(t *testing.T) {
94142
assert.Empty(t, formatAppSettingsPath(""))
95143
assert.Equal(t, "applications/app-id-1/settings", formatAppSettingsPath("app-id-1"))

0 commit comments

Comments
 (0)