mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-01-10 07:58:12 -05:00
refactor: add configurable result options for ExecuteSql tests (#2271)
Adds WithExecuteCreateWant, WithExecuteDropWant, and WithExecuteSelectEmptyWant to RunExecuteSqlToolInvokeTest to allow sources like Snowflake to validate specific DDL/DML status responses instead of defaulting to null.
This commit is contained in:
@@ -161,6 +161,9 @@ func WithMcpSelect1Want(want string) McpTestOption {
|
||||
// ExecuteSqlTestConfig represents the various configuration options for RunExecuteSqlToolInvokeTest()
|
||||
type ExecuteSqlTestConfig struct {
|
||||
select1Statement string
|
||||
createWant string
|
||||
dropWant string
|
||||
selectEmptyWant string
|
||||
}
|
||||
|
||||
type ExecuteSqlOption func(*ExecuteSqlTestConfig)
|
||||
@@ -173,6 +176,27 @@ func WithSelect1Statement(s string) ExecuteSqlOption {
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
@@ -611,6 +611,9 @@ func RunExecuteSqlToolInvokeTest(t *testing.T, createTableStatement, select1Want
|
||||
// Default values for ExecuteSqlTestConfig
|
||||
configs := &ExecuteSqlTestConfig{
|
||||
select1Statement: `"SELECT 1"`,
|
||||
createWant: "null",
|
||||
dropWant: "null",
|
||||
selectEmptyWant: "null",
|
||||
}
|
||||
|
||||
// Apply provided options
|
||||
@@ -646,7 +649,7 @@ func RunExecuteSqlToolInvokeTest(t *testing.T, createTableStatement, select1Want
|
||||
api: "http://127.0.0.1:5000/api/tool/my-exec-sql-tool/invoke",
|
||||
requestHeader: map[string]string{},
|
||||
requestBody: bytes.NewBuffer([]byte(fmt.Sprintf(`{"sql": %s}`, createTableStatement))),
|
||||
want: "null",
|
||||
want: configs.createWant,
|
||||
isErr: false,
|
||||
},
|
||||
{
|
||||
@@ -654,7 +657,7 @@ func RunExecuteSqlToolInvokeTest(t *testing.T, createTableStatement, select1Want
|
||||
api: "http://127.0.0.1:5000/api/tool/my-exec-sql-tool/invoke",
|
||||
requestHeader: map[string]string{},
|
||||
requestBody: bytes.NewBuffer([]byte(`{"sql":"SELECT * FROM t"}`)),
|
||||
want: "null",
|
||||
want: configs.selectEmptyWant,
|
||||
isErr: false,
|
||||
},
|
||||
{
|
||||
@@ -662,7 +665,7 @@ func RunExecuteSqlToolInvokeTest(t *testing.T, createTableStatement, select1Want
|
||||
api: "http://127.0.0.1:5000/api/tool/my-exec-sql-tool/invoke",
|
||||
requestHeader: map[string]string{},
|
||||
requestBody: bytes.NewBuffer([]byte(`{"sql":"DROP TABLE t"}`)),
|
||||
want: "null",
|
||||
want: configs.dropWant,
|
||||
isErr: false,
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user