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)
| 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. |
| 115 | func 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{ |