tests

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClientId = os.Getenv("CLIENT_ID")
View Source
var ServiceAccountEmail = os.Getenv("SERVICE_ACCOUNT_EMAIL")

Functions

func AddMSSQLExecuteSqlConfig added in v0.9.0

func AddMSSQLExecuteSqlConfig(t *testing.T, config map[string]any) map[string]any

AddMSSQLExecuteSqlConfig gets the tools config for `mssql-execute-sql`

func AddMSSQLPrebuiltToolConfig added in v0.16.0

func AddMSSQLPrebuiltToolConfig(t *testing.T, config map[string]any) map[string]any

AddMSSQLPrebuiltToolConfig gets the tools config for mssql prebuilt tools

func AddMySQLPrebuiltToolConfig added in v0.15.0

func AddMySQLPrebuiltToolConfig(t *testing.T, config map[string]any) map[string]any

AddMySQLPrebuiltToolConfig gets the tools config for mysql prebuilt tools

func AddMySqlExecuteSqlConfig added in v0.6.0

func AddMySqlExecuteSqlConfig(t *testing.T, config map[string]any) map[string]any

AddMySqlExecuteSqlConfig gets the tools config for `mysql-execute-sql`

func AddPgExecuteSqlConfig

func AddPgExecuteSqlConfig(t *testing.T, config map[string]any) map[string]any

AddPgExecuteSqlConfig gets the tools config for `postgres-execute-sql`

func AddTemplateParamConfig added in v0.7.0

func AddTemplateParamConfig(t *testing.T, config map[string]any, toolKind, tmplSelectCombined, tmplSelectFilterCombined string, tmplSelectAll string) map[string]any

func GetCloudSQLDialOpts

func GetCloudSQLDialOpts(ipType string) ([]cloudsqlconn.DialOption, error)

GetCloudSQLDialOpts returns cloud sql connector's dial option for ip type.

func GetGoogleIdToken

func GetGoogleIdToken(audience string) (string, error)

GetGoogleIdToken retrieve and return the Google ID token

func GetMSSQLAuthToolInfo added in v0.9.0

func GetMSSQLAuthToolInfo(tableName string) (string, string, string, []any)

GetMSSQLAuthToolInfo returns statements and param of my-auth-tool for mssql-sql kind

func GetMSSQLParamToolInfo added in v0.9.0

func GetMSSQLParamToolInfo(tableName string) (string, string, string, string, string, string, []any)

GetMSSQLParamToolInfo returns statements and param for my-tool mssql-sql kind

func GetMSSQLTmplToolStatement added in v0.9.0

func GetMSSQLTmplToolStatement() (string, string)

GetMSSQLTmplToolStatement returns statements and param for template parameter test cases for mysql-sql kind

func GetMSSQLWants added in v0.9.0

func GetMSSQLWants() (string, string, string, string)

GetMSSQLWants return the expected wants for mssql

func GetMySQLAuthToolInfo added in v0.9.0

func GetMySQLAuthToolInfo(tableName string) (string, string, string, []any)

GetMySQLAuthToolInfo returns statements and param of my-auth-tool for mysql-sql kind

func GetMySQLParamToolInfo added in v0.9.0

func GetMySQLParamToolInfo(tableName string) (string, string, string, string, string, string, []any)

GetMySQLParamToolInfo returns statements and param for my-tool mysql-sql kind

func GetMySQLTmplToolStatement added in v0.9.0

func GetMySQLTmplToolStatement() (string, string)

GetMySQLTmplToolStatement returns statements and param for template parameter test cases for mysql-sql kind

func GetMySQLWants added in v0.9.0

func GetMySQLWants() (string, string, string, string)

GetMySQLWants return the expected wants for mysql

func GetPostgresSQLAuthToolInfo

func GetPostgresSQLAuthToolInfo(tableName string) (string, string, string, []any)

GetPostgresSQLAuthToolInfo returns statements and param of my-auth-tool for postgres-sql kind

func GetPostgresSQLParamToolInfo

func GetPostgresSQLParamToolInfo(tableName string) (string, string, string, string, string, string, []any)

GetPostgresSQLParamToolInfo returns statements and param for my-tool postgres-sql kind

func GetPostgresSQLTmplToolStatement added in v0.7.0

func GetPostgresSQLTmplToolStatement() (string, string)

GetPostgresSQLTmplToolStatement returns statements and param for template parameter test cases for postgres-sql kind

func GetPostgresWants

func GetPostgresWants() (string, string, string, string)

GetPostgresWants return the expected wants for postgres

func GetRedisValkeyToolsConfig added in v0.8.0

func GetRedisValkeyToolsConfig(sourceConfig map[string]any, toolKind string) map[string]any

func GetRedisValkeyWants added in v0.8.0

func GetRedisValkeyWants() (string, string, string, string, string, string, string)

GetRedisWants return the expected wants for redis

func GetToolsConfig

func GetToolsConfig(sourceConfig map[string]any, toolKind, paramToolStatement, idParamToolStmt, nameParamToolStmt, arrayToolStatement, authToolStatement string) map[string]any

GetToolsConfig returns a mock tools config file

func RunExecuteSqlToolInvokeTest added in v0.6.0

func RunExecuteSqlToolInvokeTest(t *testing.T, createTableStatement, select1Want string, options ...ExecuteSqlOption)

func RunInitialize added in v0.8.0

func RunInitialize(t *testing.T, protocolVersion string) string

RunInitialize runs the initialize lifecycle for mcp to set up client-server connection

func RunMCPToolCallMethod

func RunMCPToolCallMethod(t *testing.T, myFailToolWant, select1Want string, options ...McpTestOption)

RunMCPToolCallMethod runs the tool/call for mcp endpoint

func RunMSSQLListTablesTest added in v0.16.0

func RunMSSQLListTablesTest(t *testing.T, tableNameParam, tableNameAuth string)

RunMSSQLListTablesTest run tests againsts the mssql-list-tables tools.

func RunMySQLListActiveQueriesTest added in v0.15.0

func RunMySQLListActiveQueriesTest(t *testing.T, ctx context.Context, pool *sql.DB)

RunMySQLListActiveQueriesTest run tests against the mysql-list-active-queries tests

func RunMySQLListTableFragmentationTest added in v0.15.0

func RunMySQLListTableFragmentationTest(t *testing.T, databaseName, tableNameParam, tableNameAuth string)

func RunMySQLListTablesMissingUniqueIndexes added in v0.15.0

func RunMySQLListTablesMissingUniqueIndexes(t *testing.T, ctx context.Context, pool *sql.DB, databaseName string)

func RunMySQLListTablesTest added in v0.15.0

func RunMySQLListTablesTest(t *testing.T, databaseName, tableNameParam, tableNameAuth string)

RunMySQLListTablesTest run tests against the mysql-list-tables tool

func RunRequest added in v0.15.0

func RunRequest(t *testing.T, method, url string, body io.Reader, headers map[string]string) (*http.Response, []byte)

RunRequest is a helper function to send HTTP requests and return the response

func RunSourceConnectionTest

func RunSourceConnectionTest(t *testing.T, sourceConfig map[string]any, toolKind string) error

RunSourceConnection test for source connection

func RunToolGetTest

func RunToolGetTest(t *testing.T)

RunToolGet runs the tool get endpoint

func RunToolGetTestByName added in v0.10.0

func RunToolGetTestByName(t *testing.T, name string, want map[string]any)

func RunToolInvokeParametersTest added in v0.10.0

func RunToolInvokeParametersTest(t *testing.T, name string, params []byte, simpleWant string)

func RunToolInvokeSimpleTest added in v0.10.0

func RunToolInvokeSimpleTest(t *testing.T, name string, simpleWant string)

RunToolInvokeSimpleTest runs the tool invoke endpoint with no parameters

func RunToolInvokeTest

func RunToolInvokeTest(t *testing.T, select1Want string, options ...InvokeTestOption)

RunToolInvoke runs the tool invoke endpoint

func RunToolInvokeWithTemplateParameters added in v0.7.0

func RunToolInvokeWithTemplateParameters(t *testing.T, tableName string, options ...TemplateParamOption)

RunToolInvokeWithTemplateParameters runs tool invoke test cases with template parameters.

func SetupMsSQLTable

func SetupMsSQLTable(t *testing.T, ctx context.Context, pool *sql.DB, createStatement, insertStatement, tableName string, params []any) func(*testing.T)

SetupMsSQLTable creates and inserts data into a table of tool compatible with mssql-sql tool

func SetupMySQLTable

func SetupMySQLTable(t *testing.T, ctx context.Context, pool *sql.DB, createStatement, insertStatement, tableName string, params []any) func(*testing.T)

SetupMySQLTable creates and inserts data into a table of tool compatible with mysql-sql tool

func SetupPostgresSQLTable

func SetupPostgresSQLTable(t *testing.T, ctx context.Context, pool *pgxpool.Pool, createStatement, insertStatement, tableName string, params []any) func(*testing.T)

SetupPostgresSQLTable creates and inserts data into a table of tool compatible with postgres-sql tool

func TestCloudSQLMySQL_IPTypeParsingFromYAML added in v0.15.0

func TestCloudSQLMySQL_IPTypeParsingFromYAML(t *testing.T)

TestCloudSQLMySQL_IPTypeParsingFromYAML verifies the IPType field parsing from YAML for the cloud-sql-mysql source, mimicking the structure of tests in cloudsql_mysql_test.go.

Types

type CmdExec

type CmdExec struct {
	Out io.ReadCloser
	// contains filtered or unexported fields
}

CmdExec represents an invocation of a toolbox command.

func StartCmd

func StartCmd(ctx context.Context, toolsFile map[string]any, args ...string) (*CmdExec, func(), error)

StartCmd returns a CmdExec representing a running instance of a toolbox command.

func (*CmdExec) Close

func (c *CmdExec) Close()

Close releases any resources associated with the instance.

func (*CmdExec) Done

func (c *CmdExec) Done() bool

Done returns true if the command has exited.

func (*CmdExec) Stop

func (c *CmdExec) Stop()

Stop sends the TERM signal to the cmd and returns.

func (*CmdExec) Wait

func (c *CmdExec) Wait(ctx context.Context) error

Waits until the execution is completed and returns any error from the result.

type ExecuteSqlOption added in v0.13.0

type ExecuteSqlOption func(*ExecuteSqlTestConfig)

func WithSelect1Statement added in v0.13.0

func WithSelect1Statement(s string) ExecuteSqlOption

WithSelect1Statement represents the database's statement for `SELECT 1`. e.g. tests.RunExecuteSqlToolInvokeTest(t, createTableStatement, select1Want, tests.WithSelect1Statement("custom"))

type ExecuteSqlTestConfig added in v0.13.0

type ExecuteSqlTestConfig struct {
	// contains filtered or unexported fields
}

ExecuteSqlTestConfig represents the various configuration options for RunExecuteSqlToolInvokeTest()

type InvokeTestConfig added in v0.13.0

type InvokeTestConfig struct {
	// contains filtered or unexported fields
}

InvokeTestConfig represents the various configuration options for RunToolInvokeTest()

type InvokeTestOption added in v0.13.0

type InvokeTestOption func(*InvokeTestConfig)

func DisableArrayTest added in v0.13.0

func DisableArrayTest() InvokeTestOption

DisableArrayTest disables tests for sources that do not support array. e.g. tests.RunToolInvokeTest(t, select1Want, tests.DisableArrayTest())

func DisableOptionalNullParamTest added in v0.13.0

func DisableOptionalNullParamTest() InvokeTestOption

DisableOptionalNullParamTest disables tests for optional null parameters. e.g. tests.RunToolInvokeTest(t, select1Want, tests.DisableOptionalNullParamTest())

func DisableSelect1AuthTest added in v0.16.0

func DisableSelect1AuthTest() InvokeTestOption

DisableSelect1AuthTest disables auth tests for sources that do not support SELECT 1 query. e.g. tests.RunToolInvokeTest(t, "", tests.DisableSelect1AuthTest())

func DisableSelect1Test added in v0.16.0

func DisableSelect1Test() InvokeTestOption

DisableSelect1Test disables tests for sources that do not support SELECT 1 query. e.g. tests.RunToolInvokeTest(t, "", tests.DisableSelect1Test())

func EnableClientAuthTest added in v0.13.0

func EnableClientAuthTest() InvokeTestOption

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 WithMyArrayToolWant added in v0.16.0

func WithMyArrayToolWant(s string) InvokeTestOption

WithMyArrayToolWant represents the response value for my-array-tool. e.g. tests.RunToolInvokeTest(t, select1Want, tests.WithMyArrayToolWant("custom"))

func WithMyToolById4Want added in v0.13.0

func WithMyToolById4Want(s string) InvokeTestOption

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 WithMyToolId3NameAliceWant added in v0.13.0

func WithMyToolId3NameAliceWant(s string) InvokeTestOption

WithMyToolId3NameAliceWant represents the response value for my-tool with id=3 and name=Alice. e.g. tests.RunToolInvokeTest(t, select1Want, tests.WithMyToolId3NameAliceWant("custom"))

func WithNullWant added in v0.13.0

func WithNullWant(s string) InvokeTestOption

WithNullWant represents a response value of null string. e.g. tests.RunToolInvokeTest(t, select1Want, tests.WithNullWant("custom"))

type MCPTestConfig added in v0.13.0

type MCPTestConfig struct {
	// contains filtered or unexported fields
}

MCPTestConfig represents the various configuration options for mcp tool call tests.

type McpTestOption added in v0.13.0

type McpTestOption func(*MCPTestConfig)

func DisableMcpSelect1AuthTest added in v0.16.0

func DisableMcpSelect1AuthTest() McpTestOption

DisableMcpSelect1AuthTest disables the auth tool tests which use select 1.

func EnableMcpClientAuthTest added in v0.13.0

func EnableMcpClientAuthTest() McpTestOption

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 WithMcpMyToolId3NameAliceWant added in v0.13.0

func WithMcpMyToolId3NameAliceWant(s string) McpTestOption

WithMcpMyToolId3NameAliceWant represents the response value for my-tool with id=3 and name=Alice. e.g. tests.RunMCPToolCallMethod(t, mcpMyFailToolWant, tests.WithMcpMyToolId3NameAliceWant("custom"))

type TemplateParamOption added in v0.13.0

type TemplateParamOption func(*TemplateParameterTestConfig)

func DisableDdlTest added in v0.13.0

func DisableDdlTest() TemplateParamOption

DisableDdlTest disables tests for ddl statements for sources that do not support ddl. e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.DisableDdlTest())

func DisableInsertTest added in v0.13.0

func DisableInsertTest() TemplateParamOption

DisableInsertTest disables tests of insert statements for sources that do not support insert. e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.DisableInsertTest())

func DisableSelectFilterTest added in v0.16.0

func DisableSelectFilterTest() TemplateParamOption

DisableInsertTest disables tests of select-fields-templateParams-tool test. e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.DisableSelectFilterTest())

func WithCreateColArray added in v0.8.0

func WithCreateColArray(s string) TemplateParamOption

WithCreateColArray represents the columns array parameter for create-table-templateParams-tool. e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithCreateColArray("custom"))

func WithDdlWant added in v0.11.0

func WithDdlWant(s string) TemplateParamOption

WithDdlWant represents the response value of ddl statements. e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithDdlWant("custom"))

func WithInsert1Want added in v0.11.0

func WithInsert1Want(s string) TemplateParamOption

WithInsert1Want represents the response value of insert-table-templateParams-tool. e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithInsert1Want("custom"))

func WithNameColFilter added in v0.13.0

func WithNameColFilter(s string) TemplateParamOption

WithNameColFilter represents the columnFilter parameter for select-filter-templateParams-combined-tool. e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithNameColFilter("custom"))

func WithNameFieldArray added in v0.13.0

func WithNameFieldArray(s string) TemplateParamOption

WithNameFieldArray represents fields array parameter for select-fields-templateParams-tool. e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithNameFieldArray("custom"))

func WithSelectAllWant added in v0.8.0

func WithSelectAllWant(s string) TemplateParamOption

WithSelectAllWant represents the response value of select-templateParams-tool. e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithSelectAllWant("custom"))

func WithSelectEmptyWant added in v0.11.0

func WithSelectEmptyWant(s string) TemplateParamOption

WithSelectEmptyWant represents the response value of select-templateParams-combined-tool with no results. e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithSelectEmptyWant("custom"))

func WithTmplSelectId1Want added in v0.13.0

func WithTmplSelectId1Want(s string) TemplateParamOption

WithTmplSelectId1Want represents the response value of select-templateParams-combined-tool with id=1. e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithTmplSelectId1Want("custom"))

func WithTmplSelectNameWant added in v0.16.0

func WithTmplSelectNameWant(s string) TemplateParamOption

WithTmplSelectNameWant represents the response value of select-filter-templateParams-combined-tool with name. e.g. tests.RunToolInvokeWithTemplateParameters(t, tableNameTemplateParam, tests.WithTmplSelectNameWant("custom"))

type TemplateParameterTestConfig added in v0.8.0

type TemplateParameterTestConfig struct {
	// contains filtered or unexported fields
}

TemplateParameterTestConfig represents the various configuration options for template parameter tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL