(t *testing.T)
| 546 | } |
| 547 | |
| 548 | func TestCreateViewFieldsWithNumberOnlyInt(t *testing.T) { |
| 549 | t.Parallel() |
| 550 | |
| 551 | app, _ := tests.NewTestApp() |
| 552 | defer app.Cleanup() |
| 553 | |
| 554 | sql := `select |
| 555 | a.id, |
| 556 | count(a.id) count, |
| 557 | total(a.id) total, |
| 558 | cast(a.id as int) cast_int, |
| 559 | cast(a.id as integer) cast_integer, |
| 560 | cast(a.id as real) cast_real, |
| 561 | cast(a.id as decimal) cast_decimal, |
| 562 | cast(a.id as numeric) cast_numeric |
| 563 | from demo1 a` |
| 564 | |
| 565 | result, err := app.CreateViewFields(sql) |
| 566 | if err != nil { |
| 567 | t.Fatal(err) |
| 568 | } |
| 569 | |
| 570 | onlyInts := map[string]bool{ |
| 571 | "count": true, |
| 572 | "total": false, |
| 573 | "cast_int": true, |
| 574 | "cast_integer": true, |
| 575 | "cast_real": false, |
| 576 | "cast_decimal": false, |
| 577 | "cast_numeric": false, |
| 578 | } |
| 579 | |
| 580 | totalExpected := len(onlyInts) + 1 |
| 581 | if total := len(result); total != totalExpected { |
| 582 | t.Fatalf("Expected %d, got %d", totalExpected, total) |
| 583 | } |
| 584 | |
| 585 | for _, f := range result { |
| 586 | if f.GetName() == "id" { |
| 587 | continue |
| 588 | } |
| 589 | |
| 590 | t.Run(f.GetName(), func(t *testing.T) { |
| 591 | nf, ok := f.(*core.NumberField) |
| 592 | if !ok { |
| 593 | t.Fatalf("Expected *core.NumberField, got %v", f) |
| 594 | } |
| 595 | |
| 596 | if nf.OnlyInt != onlyInts[nf.Name] { |
| 597 | t.Fatalf("Expected OnlyInt %v, got %v", onlyInts[nf.Name], nf.OnlyInt) |
| 598 | } |
| 599 | }) |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | func TestFindRecordByViewFile(t *testing.T) { |
| 604 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…