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

Function TestRename

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

Source from the content-addressed store, hash-verified

544}
545
546func TestRename(t *testing.T) {
547 // Rename model A to B and model B to A, verify success
548 // Rename model A to B and source B to A, verify success
549
550 // Create source and model
551 rt, id := testruntime.NewInstance(t)
552 testruntime.PutFiles(t, rt, id, map[string]string{
553 "/data/foo.csv": `a,b,c,d,e
5541,2,3,4,5
5551,2,3,4,5
5561,2,3,4,5
557`,
558 "/sources/foo.yaml": `
559connector: local_file
560path: data/foo.csv
561`,
562 "/models/bar.sql": `SELECT * FROM foo`,
563 })
564 testruntime.ReconcileParserAndWait(t, rt, id)
565 testruntime.RequireReconcileState(t, rt, id, 3, 0, 0)
566 model, modelRes := newModel("SELECT * FROM foo", "bar", "foo", 3)
567 testruntime.RequireResource(t, rt, id, modelRes)
568 testruntime.RequireOLAPTable(t, rt, id, "bar")
569
570 // Rename the model
571 testruntime.RenameFile(t, rt, id, "/models/bar.sql", "/models/bar_new.sql")
572 testruntime.ReconcileParserAndWait(t, rt, id)
573 testruntime.RequireReconcileState(t, rt, id, 3, 0, 0)
574 modelRes.Meta.Name.Name = "bar_new"
575 modelRes.Meta.FilePaths[0] = "/models/bar_new.sql"
576 model.State.ResultProperties = testruntime.Must(structpb.NewStruct(map[string]any{"table": "bar_new", "used_model_name": true, "view": true}))
577 model.State.ResultTable = "bar_new"
578 testruntime.RequireResource(t, rt, id, modelRes)
579 testruntime.RequireOLAPTable(t, rt, id, "bar_new")
580 testruntime.RequireNoOLAPTable(t, rt, id, "bar")
581
582 // Rename the model to same name but different case
583 testruntime.RenameFile(t, rt, id, "/models/bar_new.sql", "/models/Bar_New.sql")
584 testruntime.ReconcileParserAndWait(t, rt, id)
585 testruntime.RequireReconcileState(t, rt, id, 3, 0, 0)
586 modelRes.Meta.Name.Name = "Bar_New"
587 modelRes.Meta.FilePaths[0] = "/models/Bar_New.sql"
588 model.State.ResultProperties = testruntime.Must(structpb.NewStruct(map[string]any{"table": "Bar_New", "used_model_name": true, "view": true}))
589 model.State.ResultTable = "Bar_New"
590 testruntime.RequireResource(t, rt, id, modelRes)
591 testruntime.RequireOLAPTable(t, rt, id, "Bar_New")
592
593 // Create a model referencing the new model name from before
594 testruntime.PutFiles(t, rt, id, map[string]string{
595 "/models/bar_another.sql": `SELECT * FROM Bar_New`,
596 })
597 testruntime.ReconcileParserAndWait(t, rt, id)
598 testruntime.RequireReconcileState(t, rt, id, 4, 0, 0)
599 _, anotherModelRes := newModel("SELECT * FROM Bar_New", "bar_another", "Bar_New", 3)
600 anotherModelRes.Meta.Refs[0].Kind = runtime.ResourceKindModel
601 testruntime.RequireResource(t, rt, id, anotherModelRes)
602 testruntime.RequireOLAPTable(t, rt, id, "bar_another")
603}

Callers

nothing calls this directly

Calls 10

NewInstanceFunction · 0.92
PutFilesFunction · 0.92
ReconcileParserAndWaitFunction · 0.92
RequireReconcileStateFunction · 0.92
RequireResourceFunction · 0.92
RequireOLAPTableFunction · 0.92
RenameFileFunction · 0.92
MustFunction · 0.92
RequireNoOLAPTableFunction · 0.92
newModelFunction · 0.85

Tested by

no test coverage detected