MCPcopy Index your code
hub / github.com/pocketbase/pocketbase / TestCreateViewFieldsWithNumberOnlyInt

Function TestCreateViewFieldsWithNumberOnlyInt

core/view_test.go:548–601  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

546}
547
548func 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
603func TestFindRecordByViewFile(t *testing.T) {
604 t.Parallel()

Callers

nothing calls this directly

Calls 5

CleanupMethod · 0.95
NewTestAppFunction · 0.92
CreateViewFieldsMethod · 0.65
GetNameMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…