mirror of
https://github.com/ent/ent.git
synced 2026-05-28 09:49:08 +03:00
@@ -141,6 +141,8 @@ func NewType(c *Config, schema *load.Schema) (*Type, error) {
|
||||
}
|
||||
for _, f := range schema.Fields {
|
||||
switch {
|
||||
case f.Name == "":
|
||||
return nil, fmt.Errorf("field name cannot be empty")
|
||||
case f.Info == nil || !f.Info.Valid():
|
||||
return nil, fmt.Errorf("invalid type for field %s", f.Name)
|
||||
case f.Nillable && !f.Optional:
|
||||
|
||||
@@ -61,6 +61,14 @@ func TestType(t *testing.T) {
|
||||
},
|
||||
})
|
||||
require.Error(err, "empty value for enums")
|
||||
|
||||
_, err = NewType(&Config{Package: "entc/gen"}, &load.Schema{
|
||||
Name: "T",
|
||||
Fields: []*load.Field{
|
||||
{Name: "", Info: &field.TypeInfo{Type: field.TypeInt}},
|
||||
},
|
||||
})
|
||||
require.Error(err, "empty field name")
|
||||
}
|
||||
|
||||
func TestType_Label(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user