MCPcopy
hub / github.com/pocketbase/pocketbase / TestBoolFieldValidateValue

Function TestBoolFieldValidateValue

core/field_bool_test.go:61–145  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func TestBoolFieldValidateValue(t *testing.T) {
62 app, _ := tests.NewTestApp()
63 defer app.Cleanup()
64
65 collection := core.NewBaseCollection("test_collection")
66
67 scenarios := []struct {
68 name string
69 field *core.BoolField
70 record func() *core.Record
71 expectError bool
72 }{
73 {
74 "invalid raw value",
75 &core.BoolField{Name: "test"},
76 func() *core.Record {
77 record := core.NewRecord(collection)
78 record.SetRaw("test", 123)
79 return record
80 },
81 true,
82 },
83 {
84 "missing field value (non-required)",
85 &core.BoolField{Name: "test"},
86 func() *core.Record {
87 record := core.NewRecord(collection)
88 record.SetRaw("abc", true)
89 return record
90 },
91 true, // because of failed nil.(bool) cast
92 },
93 {
94 "missing field value (required)",
95 &core.BoolField{Name: "test", Required: true},
96 func() *core.Record {
97 record := core.NewRecord(collection)
98 record.SetRaw("abc", true)
99 return record
100 },
101 true,
102 },
103 {
104 "false field value (non-required)",
105 &core.BoolField{Name: "test"},
106 func() *core.Record {
107 record := core.NewRecord(collection)
108 record.SetRaw("test", false)
109 return record
110 },
111 false,
112 },
113 {
114 "false field value (required)",
115 &core.BoolField{Name: "test", Required: true},
116 func() *core.Record {
117 record := core.NewRecord(collection)
118 record.SetRaw("test", false)

Callers

nothing calls this directly

Calls 7

CleanupMethod · 0.95
SetRawMethod · 0.95
NewTestAppFunction · 0.92
NewBaseCollectionFunction · 0.92
NewRecordFunction · 0.92
ValidateValueMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…