forked from googleapis/genai-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoption.go
More file actions
316 lines (271 loc) · 11 KB
/
option.go
File metadata and controls
316 lines (271 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package tests
/* Configurations for RunToolInvokeTest() */
// InvokeTestConfig represents the various configuration options for RunToolInvokeTest()
type InvokeTestConfig struct {
myAuthToolWant string
myToolId3NameAliceWant string
myToolById4Want string
nullWant string
myArrayToolWant string
supportSelect1Want bool
supportOptionalNullParam bool
supportArrayParam bool
supportClientAuth bool
supportSelect1Auth bool
}
type InvokeTestOption func(*InvokeTestConfig)
// WithMyAuthToolWant represents the response value for my-auth-tool.
// e.g. tests.RunToolInvokeTest(t, select1Want, tests.WithMyAuthToolWant("custom"))
func WithMyAuthToolWant(s string) InvokeTestOption {
return func(c *InvokeTestConfig) {
c.myAuthToolWant = s
}
}
// WithMyToolId3NameAliceWant represents the response value for my-tool with id=3 and name=Alice.
// e.g. tests.RunToolInvokeTest(t, select1Want, tests.WithMyToolId3NameAliceWant("custom"))
func WithMyToolId3NameAliceWant(s string) InvokeTestOption {
return func(c *InvokeTestConfig) {
c.myToolId3NameAliceWant = s
}
}
// WithMyArrayToolWant represents the response value for my-array-tool.
// e.g. tests.RunToolInvokeTest(t, select1Want, tests.WithMyArrayToolWant("custom"))
func WithMyArrayToolWant(s string) InvokeTestOption {
return func(c *InvokeTestConfig) {
c.myArrayToolWant = s
}
}
// WithMyToolById4Want represents the response value for my-tool-by-id with id=4.
// This response includes a null value column.
// e.g. tests.RunToolInvokeTest(t, select1Want, tests.WithMyToolById4Want("custom"))
func WithMyToolById4Want(s string) InvokeTestOption {
return func(c *InvokeTestConfig) {
c.myToolById4Want = s
}
}
// WithNullWant represents a response value of null string.
// e.g. tests.RunToolInvokeTest(t, select1Want, tests.WithNullWant("custom"))
func WithNullWant(s string) InvokeTestOption {
return func(c *InvokeTestConfig) {
c.nullWant = s
}
}
// DisableOptionalNullParamTest disables tests for optional null parameters.
// e.g. tests.RunToolInvokeTest(t, select1Want, tests.DisableOptionalNullParamTest())
func DisableOptionalNullParamTest() InvokeTestOption {
return func(c *InvokeTestConfig) {
c.supportOptionalNullParam = false
}
}
// DisableArrayTest disables tests for sources that do not support array.
// e.g. tests.RunToolInvokeTest(t, select1Want, tests.DisableArrayTest())
func DisableArrayTest() InvokeTestOption {
return func(c *InvokeTestConfig) {
c.supportArrayParam = false
}
}
// DisableSelect1Test disables tests for sources that do not support SELECT 1 query.
// e.g. tests.RunToolInvokeTest(t, "", tests.DisableSelect1Test())
func DisableSelect1Test() InvokeTestOption {
return func(c *InvokeTestConfig) {
c.supportSelect1Want = false
}
}
// DisableSelect1AuthTest disables auth tests for sources that do not support SELECT 1 query.
// e.g. tests.RunToolInvokeTest(t, "", tests.DisableSelect1AuthTest())
func DisableSelect1AuthTest() InvokeTestOption {
return func(c *InvokeTestConfig) {
c.supportSelect1Auth = false
}
}
// EnableClientAuthTest runs the client authorization tests.
// Only enable it if your source supports the `useClientOAuth` configuration.
// Currently, this should only be used with the BigQuery tests.
func EnableClientAuthTest() InvokeTestOption {
return func(c *InvokeTestConfig) {
c.supportClientAuth = true
}
}
/* Configurations for RunMCPToolCallMethod() */
// MCPTestConfig represents the various configuration options for mcp tool call tests.
type MCPTestConfig struct {
myToolId3NameAliceWant string
mcpSelect1Want string
supportClientAuth bool
supportSelect1Auth bool
}
type McpTestOption func(*MCPTestConfig)
// WithMcpMyToolId3NameAliceWant represents the response value for my-tool with id=3 and name=Alice.
// e.g. tests.RunMCPToolCallMethod(t, mcpMyFailToolWant, tests.WithMcpMyToolId3NameAliceWant("custom"))
func WithMcpMyToolId3NameAliceWant(s string) McpTestOption {
return func(c *MCPTestConfig) {
c.myToolId3NameAliceWant = s
}
}
// EnableMcpClientAuthTest runs the client authorization tests.
// Only enable it if your source supports the `useClientOAuth` configuration.
// Currently, this should only be used with the BigQuery tests.
func EnableMcpClientAuthTest() McpTestOption {
return func(c *MCPTestConfig) {
c.supportClientAuth = true
}
}
// DisableMcpSelect1AuthTest disables the auth tool tests which use select 1.
func DisableMcpSelect1AuthTest() McpTestOption {
return func(c *MCPTestConfig) {
c.supportSelect1Auth = false
}
}
func WithMcpSelect1Want(want string) McpTestOption {
return func(c *MCPTestConfig) {
c.mcpSelect1Want = want
}
}
/* Configurations for RunExecuteSqlToolInvokeTest() */
// ExecuteSqlTestConfig represents the various configuration options for RunExecuteSqlToolInvokeTest()
type ExecuteSqlTestConfig struct {
select1Statement string
createWant string
dropWant string
selectEmptyWant string
}
type ExecuteSqlOption func(*ExecuteSqlTestConfig)
// WithSelect1Statement represents the database's statement for `SELECT 1`.
// e.g. tests.RunExecuteSqlToolInvokeTest(t, createTableStatement, select1Want, tests.WithSelect1Statement("custom"))
func WithSelect1Statement(s string) ExecuteSqlOption {
return func(c *ExecuteSqlTestConfig) {
c.select1Statement = s
}
}
// WithExecuteCreateWant represents the expected response for a CREATE TABLE statement.
func WithExecuteCreateWant(s string) ExecuteSqlOption {
return func(c *ExecuteSqlTestConfig) {
c.createWant = s
}
}
// WithExecuteDropWant represents the expected response for a DROP TABLE statement.
func WithExecuteDropWant(s string) ExecuteSqlOption {
return func(c *ExecuteSqlTestConfig) {
c.dropWant = s
}
}
// WithExecuteSelectEmptyWant represents the expected response for a SELECT from an empty table.
func WithExecuteSelectEmptyWant(s string) ExecuteSqlOption {
return func(c *ExecuteSqlTestConfig) {
c.selectEmptyWant = s
}
}
/* Configurations for RunToolInvokeWithTemplateParameters() */
// TemplateParameterTestConfig represents the various configuration options for template parameter tests.
type TemplateParameterTestConfig struct {
ddlWant string
selectAllWant string
selectId1Want string
selectNameWant string
selectEmptyWant string
insert1Want string
nameFieldArray string
nameColFilter string
createColArray string
supportDdl bool
supportInsert bool
supportSelectFields bool
}
type TemplateParamOption func(*TemplateParameterTestConfig)
// WithDdlWant represents the response value of ddl statements.
// e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithDdlWant("custom"))
func WithDdlWant(s string) TemplateParamOption {
return func(c *TemplateParameterTestConfig) {
c.ddlWant = s
}
}
// WithSelectAllWant represents the response value of select-templateParams-tool.
// e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithSelectAllWant("custom"))
func WithSelectAllWant(s string) TemplateParamOption {
return func(c *TemplateParameterTestConfig) {
c.selectAllWant = s
}
}
// WithTmplSelectId1Want represents the response value of select-templateParams-combined-tool with id=1.
// e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithTmplSelectId1Want("custom"))
func WithTmplSelectId1Want(s string) TemplateParamOption {
return func(c *TemplateParameterTestConfig) {
c.selectId1Want = s
}
}
// WithTmplSelectNameWant represents the response value of select-filter-templateParams-combined-tool with name.
// e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithTmplSelectNameWant("custom"))
func WithTmplSelectNameWant(s string) TemplateParamOption {
return func(c *TemplateParameterTestConfig) {
c.selectNameWant = s
}
}
// WithSelectEmptyWant represents the response value of select-templateParams-combined-tool with no results.
// e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithSelectEmptyWant("custom"))
func WithSelectEmptyWant(s string) TemplateParamOption {
return func(c *TemplateParameterTestConfig) {
c.selectEmptyWant = s
}
}
// WithInsert1Want represents the response value of insert-table-templateParams-tool.
// e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithInsert1Want("custom"))
func WithInsert1Want(s string) TemplateParamOption {
return func(c *TemplateParameterTestConfig) {
c.insert1Want = s
}
}
// WithNameFieldArray represents fields array parameter for select-fields-templateParams-tool.
// e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithNameFieldArray("custom"))
func WithNameFieldArray(s string) TemplateParamOption {
return func(c *TemplateParameterTestConfig) {
c.nameFieldArray = s
}
}
// WithNameColFilter represents the columnFilter parameter for select-filter-templateParams-combined-tool.
// e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithNameColFilter("custom"))
func WithNameColFilter(s string) TemplateParamOption {
return func(c *TemplateParameterTestConfig) {
c.nameColFilter = s
}
}
// WithCreateColArray represents the columns array parameter for create-table-templateParams-tool.
// e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithCreateColArray("custom"))
func WithCreateColArray(s string) TemplateParamOption {
return func(c *TemplateParameterTestConfig) {
c.createColArray = s
}
}
// DisableDdlTest disables tests for ddl statements for sources that do not support ddl.
// e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.DisableDdlTest())
func DisableDdlTest() TemplateParamOption {
return func(c *TemplateParameterTestConfig) {
c.supportDdl = false
}
}
// DisableInsertTest disables tests of insert statements for sources that do not support insert.
// e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.DisableInsertTest())
func DisableInsertTest() TemplateParamOption {
return func(c *TemplateParameterTestConfig) {
c.supportInsert = false
}
}
// DisableInsertTest disables tests of select-fields-templateParams-tool test.
// e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.DisableSelectFilterTest())
func DisableSelectFilterTest() TemplateParamOption {
return func(c *TemplateParameterTestConfig) {
c.supportSelectFields = false
}
}