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

Function TestSource

runtime/controller_test.go:204–338  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

202}
203
204func TestSource(t *testing.T) {
205 // Add source
206 rt, id := testruntime.NewInstance(t)
207 testruntime.PutFiles(t, rt, id, map[string]string{
208 "/data/foo.csv": `a,b,c,d,e
2091,2,3,4,5
2101,2,3,4,5
2111,2,3,4,5
212`,
213 "/sources/foo.yaml": `
214connector: local_file
215path: data/foo.csv
216`,
217 })
218 testruntime.ReconcileParserAndWait(t, rt, id)
219 testruntime.RequireReconcileState(t, rt, id, 2, 0, 0)
220 testruntime.RequireResource(t, rt, id, &runtimev1.Resource{
221 Meta: &runtimev1.ResourceMeta{
222 Name: &runtimev1.ResourceName{Kind: runtime.ResourceKindModel, Name: "foo"},
223 Owner: runtime.GlobalProjectParserName,
224 FilePaths: []string{"/sources/foo.yaml"},
225 },
226 Resource: &runtimev1.Resource_Model{
227 Model: &runtimev1.Model{
228 Spec: &runtimev1.ModelSpec{
229 InputConnector: "local_file",
230 OutputConnector: "duckdb",
231 InputProperties: testruntime.Must(structpb.NewStruct(map[string]any{"path": "data/foo.csv", "local_files_hash": localFileHash(t, rt, id, []string{"data/foo.csv"})})),
232 OutputProperties: testruntime.Must(structpb.NewStruct(map[string]any{"materialize": true})),
233 RefreshSchedule: &runtimev1.Schedule{RefUpdate: true},
234 DefinedAsSource: true,
235 ChangeMode: runtimev1.ModelChangeMode_MODEL_CHANGE_MODE_RESET,
236 },
237 State: &runtimev1.ModelState{
238 ExecutorConnector: "duckdb",
239 ResultConnector: "duckdb",
240 ResultProperties: testruntime.Must(structpb.NewStruct(map[string]any{"table": "foo", "used_model_name": true, "view": false})),
241 ResultTable: "foo",
242 RowsTotal: 3,
243 },
244 },
245 },
246 })
247 testruntime.RequireOLAPTable(t, rt, id, "foo")
248 testruntime.RequireOLAPTableCount(t, rt, id, "foo", 3)
249
250 // Update underlying data and refresh, verify table is updated
251 testruntime.PutFiles(t, rt, id, map[string]string{
252 "/data/foo.csv": `a,b,c,d,e
2531,2,3,4,5
254`,
255 })
256 testruntime.RefreshAndWait(t, rt, id, &runtimev1.ResourceName{Kind: runtime.ResourceKindModel, Name: "foo"})
257 testruntime.RequireReconcileState(t, rt, id, 2, 0, 0)
258 testruntime.RequireOLAPTable(t, rt, id, "foo")
259 testruntime.RequireOLAPTableCount(t, rt, id, "foo", 1)
260
261 // Get the model and the ModelManager for its output

Callers

nothing calls this directly

Calls 15

NewInstanceFunction · 0.92
PutFilesFunction · 0.92
ReconcileParserAndWaitFunction · 0.92
RequireReconcileStateFunction · 0.92
RequireResourceFunction · 0.92
MustFunction · 0.92
RequireOLAPTableFunction · 0.92
RequireOLAPTableCountFunction · 0.92
RefreshAndWaitFunction · 0.92
RequireNoOLAPTableFunction · 0.92
ReconcileAndWaitFunction · 0.92
localFileHashFunction · 0.85

Tested by

no test coverage detected