@@ -33,11 +33,120 @@ func TestRootTreeOutput(t *testing.T) {
3333 }
3434
3535 got := out .String ()
36- if ! strings .Contains (got , "wherobots\n " ) || ! strings .Contains (got , " api\n " ) || ! strings .Contains (got , " users\n " ) || ! strings .Contains (got , " get\n " ) || ! strings .Contains (got , " list\n " ) {
36+ if ! strings .Contains (got , "wherobots\n " ) ||
37+ ! strings .Contains (got , " api\n " ) ||
38+ ! strings .Contains (got , " users\n " ) ||
39+ ! strings .Contains (got , " get " ) ||
40+ ! strings .Contains (got , " list " ) {
3741 t .Fatalf ("tree output missing expected nodes:\n %s" , got )
3842 }
3943}
4044
45+ func TestTreeShowsSummaryOnLeafNodes (t * testing.T ) {
46+ t .Parallel ()
47+
48+ cfg := config.Config {AppName : "wherobots" , HTTPTimeout : time .Second }
49+ runtimeSpec := & spec.RuntimeSpec {
50+ BaseURL : "https://api.example.com" ,
51+ Operations : []* spec.Operation {
52+ {Method : "GET" , Path : "/catalogs" , Summary : "List all catalogs" },
53+ {Method : "POST" , Path : "/catalogs" , Summary : "Create a catalog" },
54+ },
55+ }
56+
57+ root := BuildRootCommand (cfg , runtimeSpec )
58+ var out bytes.Buffer
59+ root .SetOut (& out )
60+ root .SetErr (& out )
61+ root .SetArgs ([]string {"--tree" })
62+
63+ if err := root .Execute (); err != nil {
64+ t .Fatalf ("Execute() error = %v" , err )
65+ }
66+
67+ tree := out .String ()
68+ if ! strings .Contains (tree , "List all catalogs" ) {
69+ t .Errorf ("tree should show summary 'List all catalogs':\n %s" , tree )
70+ }
71+ if ! strings .Contains (tree , "Create a catalog" ) {
72+ t .Errorf ("tree should show summary 'Create a catalog':\n %s" , tree )
73+ }
74+ // Group node (catalogs) should not have a trailing summary
75+ if strings .Contains (tree , "catalogs " ) {
76+ t .Errorf ("group node 'catalogs' should not have a summary:\n %s" , tree )
77+ }
78+ }
79+
80+ func TestDescriptionAppearsInHelp (t * testing.T ) {
81+ t .Parallel ()
82+
83+ cfg := config.Config {AppName : "wherobots" , HTTPTimeout : time .Second }
84+ runtimeSpec := & spec.RuntimeSpec {
85+ BaseURL : "https://api.example.com" ,
86+ Operations : []* spec.Operation {
87+ {
88+ Method : "GET" ,
89+ Path : "/catalogs" ,
90+ Summary : "List all catalogs" ,
91+ Description : "Returns all catalogs accessible to the current user, including managed and foreign catalogs." ,
92+ },
93+ },
94+ }
95+
96+ root := BuildRootCommand (cfg , runtimeSpec )
97+ var out bytes.Buffer
98+ root .SetOut (& out )
99+ root .SetErr (& out )
100+ root .SetArgs ([]string {"api" , "catalogs" , "list" , "--help" })
101+
102+ if err := root .Execute (); err != nil {
103+ t .Fatalf ("Execute() error = %v" , err )
104+ }
105+
106+ help := out .String ()
107+ if ! strings .Contains (help , "Returns all catalogs accessible to the current user" ) {
108+ t .Errorf ("help should contain the OpenAPI description:\n %s" , help )
109+ }
110+ }
111+
112+ func TestExcludedOperationsAbsentFromTree (t * testing.T ) {
113+ t .Parallel ()
114+
115+ cfg := config.Config {AppName : "wherobots" , HTTPTimeout : time .Second }
116+ runtimeSpec := & spec.RuntimeSpec {
117+ BaseURL : "https://api.example.com" ,
118+ Operations : []* spec.Operation {
119+ {Method : "GET" , Path : "/catalogs" , Summary : "List catalogs" },
120+ {Method : "POST" , Path : "/management/org" , Summary : "Superuser action" , Excluded : true },
121+ {Method : "POST" , Path : "/files/upload-url" , Summary : "Legacy upload" , Excluded : true },
122+ },
123+ }
124+
125+ root := BuildRootCommand (cfg , runtimeSpec )
126+ var out bytes.Buffer
127+ root .SetOut (& out )
128+ root .SetErr (& out )
129+ root .SetArgs ([]string {"--tree" })
130+
131+ if err := root .Execute (); err != nil {
132+ t .Fatalf ("Execute() error = %v" , err )
133+ }
134+
135+ tree := out .String ()
136+
137+ // Visible endpoint should be present
138+ if ! strings .Contains (tree , "catalogs" ) {
139+ t .Errorf ("tree should contain 'catalogs':\n %s" , tree )
140+ }
141+ // Excluded endpoints must not appear
142+ if strings .Contains (tree , "management" ) {
143+ t .Errorf ("tree must not contain excluded 'management':\n %s" , tree )
144+ }
145+ if strings .Contains (tree , "files" ) {
146+ t .Errorf ("tree must not contain excluded 'files':\n %s" , tree )
147+ }
148+ }
149+
41150func TestDryRunOutputsCurl (t * testing.T ) {
42151 t .Parallel ()
43152
0 commit comments