@@ -84,106 +84,82 @@ func TestResource_FunctionState(t *testing.T) {
8484 }
8585}
8686
87- func TestResource_Languages (t * testing.T ) {
88- expectedOutput := `go
87+ func TestResource_Listings (t * testing.T ) {
88+ cases := []struct {
89+ name string
90+ uri string
91+ subcommand string
92+ expectedOutput string
93+ }{
94+ {
95+ name : "languages" ,
96+ uri : "func://languages" ,
97+ subcommand : "languages" ,
98+ expectedOutput : `go
8999node
90100python
91101etc
92- `
93-
94- executor := mock .NewExecutor ()
95- executor .ExecuteFn = func (ctx context.Context , subcommand string , args ... string ) ([]byte , error ) {
96- if subcommand != "languages" {
97- t .Fatalf ("expected subcommand 'languages', got %q" , subcommand )
98- }
99- if len (args ) != 0 {
100- t .Fatalf ("expected no args, got %v" , args )
101- }
102- return []byte (expectedOutput ), nil
103- }
104-
105- client , _ , err := newTestPair (t , WithExecutor (executor ))
106- if err != nil {
107- t .Fatal (err )
108- }
109-
110- result , err := client .ReadResource (context .Background (), & mcp.ReadResourceParams {
111- URI : "func://languages" ,
112- })
113- if err != nil {
114- t .Fatal (err )
115- }
116-
117- if len (result .Contents ) != 1 {
118- t .Fatalf ("expected 1 content, got %d" , len (result .Contents ))
119- }
120-
121- content := result .Contents [0 ]
122- if content .URI != "func://languages" {
123- t .Fatalf ("expected URI 'func://languages', got %q" , content .URI )
124- }
125- if content .MIMEType != "text/plain" {
126- t .Fatalf ("expected MIME type 'text/plain', got %q" , content .MIMEType )
127- }
128- if content .Text != expectedOutput {
129- t .Fatalf ("expected output:\n %s\n got:\n %s" , expectedOutput , content .Text )
130- }
131-
132- if ! executor .ExecuteInvoked {
133- t .Fatal ("executor was not invoked" )
134- }
135- }
136-
137- func TestResource_Templates (t * testing.T ) {
138- expectedOutput := `LANGUAGE TEMPLATE
102+ ` ,
103+ },
104+ {
105+ name : "templates" ,
106+ uri : "func://templates" ,
107+ subcommand : "templates" ,
108+ expectedOutput : `LANGUAGE TEMPLATE
139109go cloudevents
140110go http
141111node cloudevents
142112node http
143113python cloudevents
144114python http
145115etc etc
146- `
147-
148- executor := mock .NewExecutor ()
149- executor .ExecuteFn = func (ctx context.Context , subcommand string , args ... string ) ([]byte , error ) {
150- if subcommand != "templates" {
151- t .Fatalf ("expected subcommand 'templates', got %q" , subcommand )
152- }
153- if len (args ) != 0 {
154- t .Fatalf ("expected no args, got %v" , args )
155- }
156- return []byte (expectedOutput ), nil
157- }
158-
159- client , _ , err := newTestPair (t , WithExecutor (executor ))
160- if err != nil {
161- t .Fatal (err )
162- }
163-
164- result , err := client .ReadResource (context .Background (), & mcp.ReadResourceParams {
165- URI : "func://templates" ,
166- })
167- if err != nil {
168- t .Fatal (err )
169- }
170-
171- if len (result .Contents ) != 1 {
172- t .Fatalf ("expected 1 content, got %d" , len (result .Contents ))
173- }
174-
175- content := result .Contents [0 ]
176- if content .URI != "func://templates" {
177- t .Fatalf ("expected URI 'func://templates', got %q" , content .URI )
178- }
179- if content .MIMEType != "text/plain" {
180- t .Fatalf ("expected MIME type 'text/plain', got %q" , content .MIMEType )
181- }
182- if content .Text != expectedOutput {
183- t .Fatalf ("expected output:\n %s\n got:\n %s" , expectedOutput , content .Text )
184- }
185-
186- if ! executor .ExecuteInvoked {
187- t .Fatal ("executor was not invoked" )
116+ ` ,
117+ },
118+ }
119+
120+ for _ , tc := range cases {
121+ t .Run (tc .name , func (t * testing.T ) {
122+ executor := mock .NewExecutor ()
123+ executor .ExecuteFn = func (ctx context.Context , subcommand string , args ... string ) ([]byte , error ) {
124+ if subcommand != tc .subcommand {
125+ t .Fatalf ("expected subcommand %q, got %q" , tc .subcommand , subcommand )
126+ }
127+ if len (args ) != 0 {
128+ t .Fatalf ("expected no args, got %v" , args )
129+ }
130+ return []byte (tc .expectedOutput ), nil
131+ }
132+
133+ client , _ , err := newTestPair (t , WithExecutor (executor ))
134+ if err != nil {
135+ t .Fatal (err )
136+ }
137+
138+ result , err := client .ReadResource (context .Background (), & mcp.ReadResourceParams {
139+ URI : tc .uri ,
140+ })
141+ if err != nil {
142+ t .Fatal (err )
143+ }
144+
145+ if len (result .Contents ) != 1 {
146+ t .Fatalf ("expected 1 content, got %d" , len (result .Contents ))
147+ }
148+
149+ content := result .Contents [0 ]
150+ if content .URI != tc .uri {
151+ t .Fatalf ("expected URI %q, got %q" , tc .uri , content .URI )
152+ }
153+ if content .MIMEType != "text/plain" {
154+ t .Fatalf ("expected MIME type 'text/plain', got %q" , content .MIMEType )
155+ }
156+ if content .Text != tc .expectedOutput {
157+ t .Fatalf ("expected output:\n %s\n got:\n %s" , tc .expectedOutput , content .Text )
158+ }
159+
160+ if ! executor .ExecuteInvoked {
161+ t .Fatal ("executor was not invoked" )
162+ }
163+ })
188164 }
189165}
0 commit comments