MCPcopy Index your code
hub / github.com/rilldata/rill / newInstanceHelper

Function newInstanceHelper

runtime/testruntime/testruntime.go:254–312  ·  view source on GitHub ↗
(t TestingT, name string, instConfig map[string]string)

Source from the content-addressed store, hash-verified

252}
253
254func newInstanceHelper(t TestingT, name string, instConfig map[string]string) (*runtime.Runtime, string) {
255 rt := New(t, true)
256 ctx := t.Context()
257
258 _, currentFile, _, _ := goruntime.Caller(0)
259 projectPath := filepath.Join(currentFile, "..", "testdata", name)
260
261 olapDriver := os.Getenv("RILL_RUNTIME_TEST_OLAP_DRIVER") // todo: refactor a couple of tests that use envs
262 if olapDriver == "" {
263 olapDriver = "duckdb"
264 }
265 olapDSN := os.Getenv("RILL_RUNTIME_TEST_OLAP_DSN")
266 if olapDSN == "" {
267 olapDSN = ":memory:"
268 }
269
270 inst := &drivers.Instance{
271 Environment: "test",
272 OLAPConnector: olapDriver,
273 RepoConnector: "repo",
274 CatalogConnector: "catalog",
275 AdminConnector: "noop_admin",
276 Connectors: []*runtimev1.Connector{
277 {
278 Type: "file",
279 Name: "repo",
280 Config: Must(structpb.NewStruct(map[string]any{"dsn": projectPath})),
281 },
282 {
283 Type: olapDriver,
284 Name: olapDriver,
285 Config: Must(structpb.NewStruct(map[string]any{"dsn": olapDSN, "mode": "readwrite"})),
286 },
287 {
288 Type: "sqlite",
289 Name: "catalog",
290 // Setting a test-specific name ensures a unique connection when "cache=shared" is enabled.
291 // "cache=shared" is needed to prevent threading problems.
292 Config: Must(structpb.NewStruct(map[string]any{"dsn": fmt.Sprintf("file:%s?mode=memory&cache=shared", t.Name())})),
293 },
294 },
295 Variables: instConfig,
296 }
297
298 err := rt.CreateInstance(ctx, inst)
299 require.NoError(t, err)
300 require.NotEmpty(t, inst.ID)
301
302 ctrl, err := rt.Controller(ctx, inst.ID)
303 require.NoError(t, err)
304
305 _, err = ctrl.Get(ctx, runtime.GlobalProjectParserName, false)
306 require.NoError(t, err)
307
308 err = ctrl.WaitUntilIdle(ctx, false)
309 require.NoError(t, err)
310
311 return rt, inst.ID

Callers 2

NewInstanceForProjectFunction · 0.85

Calls 8

ControllerMethod · 0.80
NewFunction · 0.70
MustFunction · 0.70
ContextMethod · 0.65
NameMethod · 0.65
CreateInstanceMethod · 0.65
GetMethod · 0.65
WaitUntilIdleMethod · 0.45

Tested by

no test coverage detected