TestCommandCatalogPath pins that the auth-hint path reconstruction inverts the service command tree for any depth — flat dotted resources AND genuinely nested resources — so it round-trips through apicatalog.Resolve instead of assuming a fixed root->service->resource->method shape.
(t *testing.T)
| 15 | // nested resources — so it round-trips through apicatalog.Resolve instead of |
| 16 | // assuming a fixed root->service->resource->method shape. |
| 17 | func TestCommandCatalogPath(t *testing.T) { |
| 18 | chain := func(names ...string) *cobra.Command { |
| 19 | var parent, leaf *cobra.Command |
| 20 | for _, n := range names { |
| 21 | c := &cobra.Command{Use: n} |
| 22 | if parent != nil { |
| 23 | parent.AddCommand(c) |
| 24 | } |
| 25 | parent = c |
| 26 | leaf = c |
| 27 | } |
| 28 | return leaf |
| 29 | } |
| 30 | |
| 31 | tests := []struct { |
| 32 | name string |
| 33 | leaf *cobra.Command |
| 34 | want []string |
| 35 | }{ |
| 36 | {"flat dotted resource", chain("lark-cli", "im", "chat.members", "create"), []string{"im", "chat.members", "create"}}, |
| 37 | {"nested resources", chain("lark-cli", "im", "spaces", "items", "get"), []string{"im", "spaces", "items", "get"}}, |
| 38 | {"service level", chain("lark-cli", "im"), []string{"im"}}, |
| 39 | } |
| 40 | for _, tt := range tests { |
| 41 | t.Run(tt.name, func(t *testing.T) { |
| 42 | if got := commandCatalogPath(tt.leaf); !reflect.DeepEqual(got, tt.want) { |
| 43 | t.Errorf("commandCatalogPath = %v, want %v", got, tt.want) |
| 44 | } |
| 45 | }) |
| 46 | } |
| 47 | |
| 48 | // The root command (no parent) has no catalog path. |
| 49 | if got := commandCatalogPath(&cobra.Command{Use: "lark-cli"}); len(got) != 0 { |
| 50 | t.Errorf("root path = %v, want empty", got) |
| 51 | } |
| 52 | } |
nothing calls this directly
no test coverage detected