Documentation
¶
Index ¶
- Variables
- func AcquireConnector(t TestingT, name string) map[string]any
- func DatasetPath(t TestingT, ds Dataset) string
- func DeleteFiles(t testing.TB, rt *runtime.Runtime, id string, files ...string)
- func DumpResources(t testing.TB, rt *runtime.Runtime, id string)
- func GetResource(t testing.TB, rt *runtime.Runtime, id, kind, name string) *runtimev1.Resource
- func Must[T any](v T, err error) T
- func New(t TestingT, allowHostAccess bool) *runtime.Runtime
- func NewInstance(t TestingT) (*runtime.Runtime, string)
- func NewInstanceForDruidProject(t *testing.T) (*runtime.Runtime, string, error)
- func NewInstanceForProject(t TestingT, name string) (*runtime.Runtime, string)
- func NewInstanceForProjectWithConfigs(t TestingT, name string, instConfig map[string]string) (*runtime.Runtime, string)
- func NewInstanceWithClickhouseProject(t TestingT, withCluster bool) (*runtime.Runtime, string)
- func NewInstanceWithModel(t TestingT, name, sql string) (*runtime.Runtime, string)
- func NewInstanceWithOptions(t TestingT, opts InstanceOptions) (*runtime.Runtime, string)
- func ProjectOpenRTB(t TestingT) (int, map[string]string)
- func PutFiles(t testing.TB, rt *runtime.Runtime, id string, files map[string]string)
- func ReconcileAndWait(t testing.TB, rt *runtime.Runtime, id string, n *runtimev1.ResourceName)
- func ReconcileParserAndWait(t testing.TB, rt *runtime.Runtime, id string)
- func RefreshAndWait(t testing.TB, rt *runtime.Runtime, id string, n *runtimev1.ResourceName)
- func RefreshModelAndWait(t testing.TB, rt *runtime.Runtime, id string, ...)
- func RenameFile(t testing.TB, rt *runtime.Runtime, id, from, to string)
- func RequireIsView(t testing.TB, olap drivers.OLAPStore, tableName string, isView bool)
- func RequireNoOLAPTable(t testing.TB, rt *runtime.Runtime, id, name string)
- func RequireOLAPTable(t testing.TB, rt *runtime.Runtime, id, name string)
- func RequireOLAPTableCount(t testing.TB, rt *runtime.Runtime, id, name string, count int)
- func RequireParseErrors(t testing.TB, rt *runtime.Runtime, id string, ...)
- func RequireReconcileState(t testing.TB, rt *runtime.Runtime, id string, ...)
- func RequireResolve(t testing.TB, rt *runtime.Runtime, id string, opts *RequireResolveOptions)
- func RequireResource(t testing.TB, rt *runtime.Runtime, id string, a *runtimev1.Resource)
- type ConnectorAcquireFunc
- type Dataset
- type InstanceOptions
- type RequireResolveOptions
- type TestingT
Constants ¶
This section is empty.
Variables ¶
var Connectors = map[string]ConnectorAcquireFunc{ "clickhouse": func(t TestingT) map[string]string { dsn := testclickhouse.Start(t) return map[string]string{"dsn": dsn, "mode": "readwrite"} }, "clickhouse_cluster": func(t TestingT) map[string]string { dsn, cluster := testclickhouse.StartCluster(t) return map[string]string{"dsn": dsn, "cluster": cluster, "mode": "readwrite"} }, "bigquery": func(t TestingT) map[string]string { loadDotEnv(t) gac := os.Getenv("RILL_RUNTIME_BIGQUERY_TEST_GOOGLE_APPLICATION_CREDENTIALS_JSON") require.NotEmpty(t, gac, "Bigquery RILL_RUNTIME_BIGQUERY_TEST_GOOGLE_APPLICATION_CREDENTIALS_JSON not configured") return map[string]string{"google_application_credentials": gac} }, "snowflake": func(t TestingT) map[string]string { loadDotEnv(t) dsn := os.Getenv("RILL_RUNTIME_SNOWFLAKE_TEST_DSN") require.NotEmpty(t, dsn, "RILL_RUNTIME_SNOWFLAKE_TEST_DSN not configured") return map[string]string{"dsn": dsn} }, "motherduck": func(t TestingT) map[string]string { loadDotEnv(t) path := os.Getenv("RILL_RUNTIME_MOTHERDUCK_TEST_PATH") require.NotEmpty(t, path) token := os.Getenv("RILL_RUNTIME_MOTHERDUCK_TEST_TOKEN") require.NotEmpty(t, token) return map[string]string{"path": path, "token": token} }, "gcs": func(t TestingT) map[string]string { loadDotEnv(t) gac := os.Getenv("RILL_RUNTIME_GCS_TEST_GOOGLE_APPLICATION_CREDENTIALS_JSON") require.NotEmpty(t, gac, "GCS RILL_RUNTIME_GCS_TEST_GOOGLE_APPLICATION_CREDENTIALS_JSON not configured") hmacKey := os.Getenv("RILL_RUNTIME_GCS_TEST_HMAC_KEY") hmacSecret := os.Getenv("RILL_RUNTIME_GCS_TEST_HMAC_SECRET") require.NotEmpty(t, hmacKey, "GCS RILL_RUNTIME_GCS_TEST_HMAC_KEY not configured") require.NotEmpty(t, hmacSecret, "GCS RILL_RUNTIME_GCS_TEST_HMAC_SECRET not configured") return map[string]string{ "google_application_credentials": gac, "key_id": hmacKey, "secret": hmacSecret, } }, "gcs_s3_compat": func(t TestingT) map[string]string { loadDotEnv(t) hmacKey := os.Getenv("RILL_RUNTIME_GCS_TEST_HMAC_KEY") hmacSecret := os.Getenv("RILL_RUNTIME_GCS_TEST_HMAC_SECRET") require.NotEmpty(t, hmacKey, "GCS RILL_RUNTIME_GCS_TEST_HMAC_KEY not configured") require.NotEmpty(t, hmacSecret, "GCS RILL_RUNTIME_GCS_TEST_HMAC_SECRET not configured") return map[string]string{ "key_id": hmacKey, "secret": hmacSecret, } }, "s3": func(t TestingT) map[string]string { loadDotEnv(t) accessKeyID := os.Getenv("RILL_RUNTIME_S3_TEST_AWS_ACCESS_KEY_ID") secretAccessKey := os.Getenv("RILL_RUNTIME_S3_TEST_AWS_SECRET_ACCESS_KEY") require.NotEmpty(t, accessKeyID, "S3 RILL_RUNTIME_S3_TEST_AWS_ACCESS_KEY_ID not configured") require.NotEmpty(t, secretAccessKey, "S3 RILL_RUNTIME_S3_TEST_AWS_SECRET_ACCESS_KEY not configured") return map[string]string{ "aws_access_key_id": accessKeyID, "aws_secret_access_key": secretAccessKey, } }, "athena": func(t TestingT) map[string]string { loadDotEnv(t) accessKeyID := os.Getenv("RILL_RUNTIME_ATHENA_TEST_AWS_ACCESS_KEY_ID") secretAccessKey := os.Getenv("RILL_RUNTIME_ATHENA_TEST_AWS_SECRET_ACCESS_KEY") require.NotEmpty(t, accessKeyID, "Athena RILL_RUNTIME_ATHENA_TEST_AWS_ACCESS_KEY_ID not configured") require.NotEmpty(t, secretAccessKey, "Athena RILL_RUNTIME_ATHENA_TEST_AWS_SECRET_ACCESS_KEY not configured") return map[string]string{ "aws_access_key_id": accessKeyID, "aws_secret_access_key": secretAccessKey, } }, "redshift": func(t TestingT) map[string]string { loadDotEnv(t) accessKeyID := os.Getenv("RILL_RUNTIME_REDSHIFT_TEST_AWS_ACCESS_KEY_ID") secretAccessKey := os.Getenv("RILL_RUNTIME_REDSHIFT_TEST_AWS_SECRET_ACCESS_KEY") require.NotEmpty(t, accessKeyID, "RILL_RUNTIME_REDSHIFT_TEST_AWS_ACCESS_KEY_ID not configured") require.NotEmpty(t, secretAccessKey, "RILL_RUNTIME_REDSHIFT_TEST_AWS_SECRET_ACCESS_KEY not configured") return map[string]string{ "aws_access_key_id": accessKeyID, "aws_secret_access_key": secretAccessKey, } }, "druid": func(t TestingT) map[string]string { loadDotEnv(t) dsn := os.Getenv("RILL_RUNTIME_DRUID_TEST_DSN") require.NotEmpty(t, dsn, "Druid test DSN not configured") return map[string]string{"dsn": dsn} }, "postgres": func(t TestingT) map[string]string { _, currentFile, _, _ := goruntime.Caller(0) testdataPath := filepath.Join(currentFile, "..", "testdata") postgresInitData := filepath.Join(testdataPath, "init_data", "postgres_init_data.sql") pgc := pgtestcontainer.New(t.(*testing.T)) t.Cleanup(func() { pgc.Terminate(t.(*testing.T)) }) db, err := sql.Open("pgx", pgc.DatabaseURL) require.NoError(t, err) defer db.Close() sqlFile, err := os.ReadFile(postgresInitData) require.NoError(t, err) _, err = db.Exec(string(sqlFile)) require.NoError(t, err) ip, err := pgc.Container.ContainerIP(context.Background()) require.NoError(t, err) return map[string]string{ "dsn": pgc.DatabaseURL, "ip": ip, } }, "mysql": func(t TestingT) map[string]string { _, currentFile, _, _ := goruntime.Caller(0) testdataPath := filepath.Join(currentFile, "..", "testdata") mysqlInitData := filepath.Join(testdataPath, "init_data", "mysql_init_data.sql") ctx := context.Background() mysqlContainer, err := mysql.Run(ctx, "mysql:8.0.36", mysql.WithUsername("mysql"), mysql.WithPassword("mysql"), mysql.WithDatabase("mysql"), mysql.WithScripts(mysqlInitData), ) require.NoError(t, err) t.Cleanup(func() { err := mysqlContainer.Terminate(ctx) require.NoError(t, err) }) host, err := mysqlContainer.Host(ctx) require.NoError(t, err) port, err := mysqlContainer.MappedPort(ctx, "3306/tcp") require.NoError(t, err) dsn := fmt.Sprintf("mysql://mysql:mysql@%v:%v/mysql", host, port.Port()) ip, err := mysqlContainer.ContainerIP(context.Background()) require.NoError(t, err) return map[string]string{"dsn": dsn, "ip": ip} }, "azure": func(t TestingT) map[string]string { ctx := context.Background() azuriteContainer, err := azurite.Run( ctx, "mcr.microsoft.com/azure-storage/azurite:3.34.0", azurite.WithInMemoryPersistence(64), ) t.Cleanup(func() { err := testcontainers.TerminateContainer(azuriteContainer) require.NoError(t, err) }) require.NoError(t, err) blobServiceURL := fmt.Sprintf("%s/%s", azuriteContainer.MustServiceURL(ctx, azurite.BlobService), azurite.AccountName) cred, err := azblob.NewSharedKeyCredential(azurite.AccountName, azurite.AccountKey) require.NoError(t, err) client, err := azblob.NewClientWithSharedKeyCredential(blobServiceURL, cred, nil) require.NoError(t, err) containerName := "integration-test" _, err = client.CreateContainer(ctx, containerName, nil) require.NoError(t, err) _, currentFile, _, _ := goruntime.Caller(0) testdataPath := filepath.Join(currentFile, "..", "testdata") azureInitData := filepath.Join(testdataPath, "init_data", "azure") err = uploadDirectory(ctx, client, containerName, azureInitData) require.NoError(t, err) connectionString := fmt.Sprintf("DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=%s;BlobEndpoint=%s;", azurite.AccountName, azurite.AccountKey, blobServiceURL) ip, err := azuriteContainer.ContainerIP(context.Background()) require.NoError(t, err) blobEndpointWithIP := fmt.Sprintf("http://%s:%d/%s", ip, 10000, azurite.AccountName) connectionStringWithIP := fmt.Sprintf("DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=%s;BlobEndpoint=%s;", azurite.AccountName, azurite.AccountKey, blobEndpointWithIP) return map[string]string{ "azure_storage_connection_string": connectionString, "azure_storage_connection_string_ip": connectionStringWithIP, "azure_storage_account": azurite.AccountName, } }, "pinot": func(t TestingT) map[string]string { ctx := context.Background() pinot, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ Image: "apachepinot/pinot:latest", ExposedPorts: []string{"9000/tcp", "8000/tcp"}, Cmd: []string{"QuickStart", "-type", "batch"}, WaitingFor: wait.ForLog("You can always go to http://localhost:9000").WithStartupTimeout(2 * time.Minute), }, Started: true, }) require.NoError(t, err) t.Cleanup(func() { err := pinot.Terminate(ctx) require.NoError(t, err) }) host, err := pinot.Host(ctx) require.NoError(t, err) brokerPort, err := pinot.MappedPort(ctx, "8000") require.NoError(t, err) controllerPort, err := pinot.MappedPort(ctx, "9000") require.NoError(t, err) dsn := fmt.Sprintf("http://%s:%s?controller=http://%s:%s", host, brokerPort.Port(), host, controllerPort.Port()) return map[string]string{"dsn": dsn} }, "openai": func(t TestingT) map[string]string { loadDotEnv(t) apiKey := os.Getenv("RILL_RUNTIME_OPENAI_TEST_API_KEY") require.NotEmpty(t, apiKey) return map[string]string{"api_key": apiKey} }, }
Connectors is a map of available connectors for use in tests. When acquiring a connector, it will only be cleaned up when the test has completed. You should avoid acquiring the same connector multiple times in the same test.
Test connectors can either be implemented as: - Services embedded in the current process - Services started as ephemeral testcontainers - Real external services configured for use in tests with credentials provided in the root .env file with the prefix RILL_RUNTIME_TEST_.
Functions ¶
func AcquireConnector ¶ added in v0.52.0
AcquireConnector acquires a test connector by name. For a list of available connectors, see the Connectors map below.
func DatasetPath ¶ added in v0.78.0
DatasetPath returns a local path to the given dataset. For remote datasets, it downloads and caches them locally in ./testruntime/testdata/cache.
func DeleteFiles ¶ added in v0.35.0
func DumpResources ¶ added in v0.35.0
func GetResource ¶ added in v0.50.0
func NewInstance ¶
NewInstance is a convenience wrapper around NewInstanceWithOptions, using defaults sensible for most tests.
func NewInstanceForDruidProject ¶ added in v0.46.0
func NewInstanceForProject ¶
NewInstanceForProject creates a runtime and an instance for use in tests. The passed name should match a test project in the testdata folder. You should not do mutable repo operations on the returned instance.
func NewInstanceForProjectWithConfigs ¶ added in v0.78.0
func NewInstanceWithClickhouseProject ¶ added in v0.49.0
func NewInstanceWithModel ¶
NewInstanceWithModel creates a runtime and an instance for use in tests. The passed model name and SQL SELECT statement will be loaded into the instance.
func NewInstanceWithOptions ¶ added in v0.35.0
func NewInstanceWithOptions(t TestingT, opts InstanceOptions) (*runtime.Runtime, string)
NewInstanceWithOptions creates a runtime and an instance for use in tests. The instance's repo is a temp directory that will be cleared when the tests finish.
func ProjectOpenRTB ¶ added in v0.78.0
ProjectOpenRTB returns project files that resemble our public rill-openrtb-prog-ads example project. Unlike the example project, it: 1. uses local cached copies of the datasets for faster and more reliable tests. 2. has been trimmed to the essential resources and properties.
func ReconcileAndWait ¶ added in v0.35.0
func ReconcileParserAndWait ¶ added in v0.35.0
func RefreshAndWait ¶ added in v0.35.0
func RefreshModelAndWait ¶ added in v0.78.0
func RenameFile ¶ added in v0.36.0
func RequireIsView ¶ added in v0.36.0
func RequireNoOLAPTable ¶ added in v0.35.0
func RequireOLAPTable ¶ added in v0.35.0
func RequireOLAPTableCount ¶ added in v0.35.0
func RequireParseErrors ¶ added in v0.36.0
func RequireReconcileState ¶ added in v0.35.0
func RequireResolve ¶ added in v0.61.3
Types ¶
type ConnectorAcquireFunc ¶ added in v0.51.0
ConnectorAcquireFunc is a function that acquires a connector for a test. It should return a map of config keys suitable for passing to drivers.Open.
type InstanceOptions ¶ added in v0.35.0
type InstanceOptions struct {
Files map[string]string
Variables map[string]string
WatchRepo bool
StageChanges bool
DisableHostAccess bool
EnableLLM bool
TestConnectors []string
FrontendURL string
}
InstanceOptions enables configuration of the instance options that are configurable in tests.