fix(orm): ValidateJSON fails when tables are missing (#11174)

This commit is contained in:
Aaron Craelius 2022-02-11 16:02:36 -05:00 committed by GitHub
parent d98503b21f
commit 94e6a379a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -42,6 +42,10 @@ func (m moduleDB) ValidateJSON(source ormjson.ReadSource) error {
return err
}
if r == nil {
continue
}
err = table.ValidateJSON(r)
if err != nil {
errMap[name] = err

View File

@ -245,12 +245,20 @@ func TestModuleDB(t *testing.T) {
rawJson, err = target.JSON()
assert.NilError(t, err)
goodJSON := `{
"testpb.Supply": []
}`
source, err := ormjson.NewRawMessageSource(json.RawMessage(goodJSON))
assert.NilError(t, err)
assert.NilError(t, db.ValidateJSON(source))
assert.NilError(t, db.ImportJSON(ormtable.WrapContextDefault(ormtest.NewMemoryBackend()), source))
badJSON := `{
"testpb.Balance": 5,
"testpb.Supply": {}
}
`
source, err := ormjson.NewRawMessageSource(json.RawMessage(badJSON))
source, err = ormjson.NewRawMessageSource(json.RawMessage(badJSON))
assert.NilError(t, err)
assert.ErrorIs(t, db.ValidateJSON(source), ormerrors.JSONValidationError)