Skip to content

Commit

Permalink
Fixing json name of constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfireman committed Sep 1, 2020
1 parent 3cc64ed commit 80cddb2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion schema/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type Field struct {

// Constraints can be used by consumers to list constraints for validating
// field values.
Constraints Constraints
Constraints Constraints `json:"constraints,omitempty"`
}

// UnmarshalJSON sets *f to a copy of data. It will respect the default values
Expand Down
13 changes: 10 additions & 3 deletions schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ func TestRead_Sucess(t *testing.T) {
`{"fields":[{"name":"n1"}], "foreignKeys":{"reference":{"fields":["n1"]}}}`,
Schema{Fields: []Field{asJSONField(Field{Name: "n1"})}, ForeignKeys: ForeignKeys{Reference: ForeignKeyReference{Fields: []string{"n1"}}}},
},
{
"Constraints",
`{"fields":[{"name":"n1", "constraints":{"unique":true}}]}`,
Schema{Fields: []Field{asJSONField(Field{Name: "n1", Constraints: Constraints{Unique: true}})}},
},
}
for _, d := range data {
t.Run(d.Desc, func(t *testing.T) {
Expand Down Expand Up @@ -423,7 +428,7 @@ func TestValidate_Invalid(t *testing.T) {
func TestWrite(t *testing.T) {
is := is.New(t)
s := Schema{
Fields: []Field{{Name: "Foo"}, {Name: "Bar"}},
Fields: []Field{{Name: "Foo", Constraints: Constraints{Unique: true}}, {Name: "Bar"}},
PrimaryKeys: []string{"Foo"},
ForeignKeys: ForeignKeys{Reference: ForeignKeyReference{Fields: []string{"Foo"}}},
}
Expand All @@ -434,11 +439,13 @@ func TestWrite(t *testing.T) {
"fields": [
{
"name": "Foo",
"Constraints": {}
"constraints": {
"unique": true
}
},
{
"name": "Bar",
"Constraints": {}
"constraints": {}
}
],
"primaryKey": [
Expand Down

0 comments on commit 80cddb2

Please sign in to comment.