MCPcopy Create free account
hub / github.com/rilldata/rill / NewInstanceWithOptions

Function NewInstanceWithOptions

runtime/testruntime/testruntime.go:115–222  ·  view source on GitHub ↗

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.

(t TestingT, opts InstanceOptions)

Source from the content-addressed store, hash-verified

113// NewInstanceWithOptions creates a runtime and an instance for use in tests.
114// The instance's repo is a temp directory that will be cleared when the tests finish.
115func NewInstanceWithOptions(t TestingT, opts InstanceOptions) (*runtime.Runtime, string) {
116 rt := New(t, !opts.DisableHostAccess)
117 ctx := t.Context()
118
119 olapDriver := os.Getenv("RILL_RUNTIME_TEST_OLAP_DRIVER")
120 if olapDriver == "" {
121 olapDriver = "duckdb"
122 }
123 olapDSN := os.Getenv("RILL_RUNTIME_TEST_OLAP_DSN")
124 if olapDSN == "" {
125 olapDSN = ":memory:"
126 }
127
128 vars := make(map[string]string)
129 maps.Copy(vars, opts.Variables)
130 if vars["rill.stage_changes"] == "" {
131 vars["rill.stage_changes"] = strconv.FormatBool(opts.StageChanges)
132 }
133 if vars["rill.watch_repo"] == "" {
134 vars["rill.watch_repo"] = strconv.FormatBool(opts.WatchRepo)
135 }
136
137 // Making LLM completions in tests is disabled by default.
138 // If enabled, we skip the test in CI (short mode) to prevent running up costs.
139 var aiConnector string
140 if opts.AIConnector != "" {
141 // Mark AI tests as expensive
142 testmode.Expensive(t)
143
144 // Add it to the test connectors if not already present.
145 if !slices.Contains(opts.TestConnectors, opts.AIConnector) {
146 opts.TestConnectors = append(opts.TestConnectors, opts.AIConnector)
147 }
148
149 // Set the AI test connector as the instance's default AI connector.
150 // This enables LLM completions.
151 aiConnector = opts.AIConnector
152 }
153
154 for _, conn := range opts.TestConnectors {
155 acquire, ok := Connectors[conn]
156 require.True(t, ok, "unknown test connector %q", conn)
157 cfg := acquire(t)
158 for k, v := range cfg {
159 k = fmt.Sprintf("connector.%s.%s", conn, k)
160 vars[k] = v
161 }
162 }
163
164 tmpDir := t.TempDir()
165 inst := &drivers.Instance{
166 Environment: "test",
167 OLAPConnector: olapDriver,
168 RepoConnector: "repo",
169 AIConnector: aiConnector,
170 CatalogConnector: "catalog",
171 AdminConnector: "noop_admin",
172 Connectors: []*runtimev1.Connector{

Callers 15

TestHealthFunction · 0.92
TestStageChangesFunction · 0.92
TestWatchFunction · 0.92
TestDedicatedConnectorFunction · 0.92
TestAcquireHandleFunction · 0.92
TestValidateLineChartFunction · 0.92
TestValidateBarChartFunction · 0.92
TestValidateDonutChartFunction · 0.92

Calls 12

ExpensiveFunction · 0.92
ContainsMethod · 0.80
ControllerMethod · 0.80
NewFunction · 0.70
MustFunction · 0.70
ContextMethod · 0.65
TempDirMethod · 0.65
NameMethod · 0.65
MkdirAllMethod · 0.65
CreateInstanceMethod · 0.65
GetMethod · 0.65
WaitUntilIdleMethod · 0.45

Tested by 15

TestHealthFunction · 0.74
TestStageChangesFunction · 0.74
TestWatchFunction · 0.74
TestDedicatedConnectorFunction · 0.74
TestAcquireHandleFunction · 0.74
TestValidateLineChartFunction · 0.74
TestValidateBarChartFunction · 0.74
TestValidateDonutChartFunction · 0.74