(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func 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 | { |
nothing calls this directly
no test coverage detected
searching dependent graphs…