Skip to content

Commit 5540f33

Browse files
Fix approval_requests commands not available
1 parent 016d476 commit 5540f33

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

pkg/cmd/resource/approval_requests.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,21 @@ var approvalRequestsSpecs = []OperationSpec{
5353
// AddApprovalRequestsSubCmds patches approval_requests commands into the
5454
// auto-generated `core` namespace command tree.
5555
func AddApprovalRequestsSubCmds(rootCmd *cobra.Command, cfg *config.Config) error {
56+
var v2Cmd *cobra.Command
5657
var coreCmd *cobra.Command
5758

5859
for _, cmd := range rootCmd.Commands() {
60+
if cmd.Use == "v2" {
61+
v2Cmd = cmd
62+
break
63+
}
64+
}
65+
66+
if v2Cmd == nil {
67+
return nil
68+
}
69+
70+
for _, cmd := range v2Cmd.Commands() {
5971
if cmd.Use == "core" {
6072
coreCmd = cmd
6173
break
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package resource
2+
3+
import (
4+
"testing"
5+
6+
"github.com/spf13/cobra"
7+
"github.com/stretchr/testify/require"
8+
9+
"github.com/stripe/stripe-cli/pkg/config"
10+
)
11+
12+
func TestAddApprovalRequestsSubCmds(t *testing.T) {
13+
root := &cobra.Command{Use: "stripe"}
14+
v2Cmd := &cobra.Command{Use: "v2"}
15+
coreCmd := &cobra.Command{Use: "core", Annotations: make(map[string]string)}
16+
v2Cmd.AddCommand(coreCmd)
17+
root.AddCommand(v2Cmd)
18+
19+
err := AddApprovalRequestsSubCmds(root, &config.Config{})
20+
require.NoError(t, err)
21+
22+
var found *cobra.Command
23+
for _, cmd := range coreCmd.Commands() {
24+
if cmd.Use == "approval_requests" {
25+
found = cmd
26+
break
27+
}
28+
}
29+
require.NotNil(t, found, "expected approval_requests command under v2 core")
30+
}

0 commit comments

Comments
 (0)