MCPcopy
hub / github.com/pocketbase/pocketbase / TestCollectionValidate

Function TestCollectionValidate

core/collection_validate_test.go:11–909  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestCollectionValidate(t *testing.T) {
12 t.Parallel()
13
14 scenarios := []struct {
15 name string
16 collection func(app core.App) (*core.Collection, error)
17 expectedErrors []string
18 }{
19 {
20 name: "empty collection",
21 collection: func(app core.App) (*core.Collection, error) {
22 return &core.Collection{}, nil
23 },
24 expectedErrors: []string{
25 "id", "name", "type", "fields", // no default fields because the type is unknown
26 },
27 },
28 {
29 name: "unknown type with all invalid fields",
30 collection: func(app core.App) (*core.Collection, error) {
31 c := &core.Collection{}
32 c.Id = "invalid_id ?!@#$"
33 c.Name = "invalid_name ?!@#$"
34 c.Type = "invalid_type"
35 c.ListRule = types.Pointer("missing = '123'")
36 c.ViewRule = types.Pointer("missing = '123'")
37 c.CreateRule = types.Pointer("missing = '123'")
38 c.UpdateRule = types.Pointer("missing = '123'")
39 c.DeleteRule = types.Pointer("missing = '123'")
40 c.Indexes = []string{"create index '' on '' ()"}
41
42 // type specific fields
43 c.ViewQuery = "invalid" // should be ignored
44 c.AuthRule = types.Pointer("missing = '123'") // should be ignored
45
46 return c, nil
47 },
48 expectedErrors: []string{
49 "id", "name", "type", "indexes",
50 "listRule", "viewRule", "createRule", "updateRule", "deleteRule",
51 "fields", // no default fields because the type is unknown
52 },
53 },
54 {
55 name: "base with invalid fields",
56 collection: func(app core.App) (*core.Collection, error) {
57 c := core.NewBaseCollection("invalid_name ?!@#$")
58 c.Indexes = []string{"create index '' on '' ()"}
59
60 // type specific fields
61 c.ViewQuery = "invalid" // should be ignored
62 c.AuthRule = types.Pointer("missing = '123'") // should be ignored
63
64 return c, nil
65 },
66 expectedErrors: []string{"name", "indexes"},
67 },
68 {

Callers

nothing calls this directly

Calls 15

CleanupMethod · 0.95
PointerFunction · 0.92
NewBaseCollectionFunction · 0.92
NewViewCollectionFunction · 0.92
NewAuthCollectionFunction · 0.92
NewFieldsListFunction · 0.92
NewTestAppFunction · 0.92
TestValidationErrorsFunction · 0.92
GetByNameMethod · 0.80
RemoveIndexMethod · 0.80
AddIndexMethod · 0.80
RemoveByNameMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…