(t *testing.T)
| 544 | } |
| 545 | |
| 546 | func 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 |
| 554 | 1,2,3,4,5 |
| 555 | 1,2,3,4,5 |
| 556 | 1,2,3,4,5 |
| 557 | `, |
| 558 | "/sources/foo.yaml": ` |
| 559 | connector: local_file |
| 560 | path: 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 | } |
nothing calls this directly
no test coverage detected