Add cast error checking to refactored transformers

This commit is contained in:
Edvard
2018-10-23 10:47:01 +02:00
parent b7f8432e65
commit cb74cbe990
26 changed files with 210 additions and 43 deletions
+7 -2
View File
@@ -15,6 +15,7 @@
package ilk
import (
"fmt"
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
)
@@ -29,9 +30,13 @@ func (repository DripFileIlkRepository) Create(headerID int64, models []interfac
return err
}
var ilk DripFileIlkModel
for _, model := range models {
ilk = model.(DripFileIlkModel)
ilk, ok := model.(DripFileIlkModel)
if !ok {
tx.Rollback()
return fmt.Errorf("model of type %T, not %T", model, DripFileIlkModel{})
}
_, err = tx.Exec(
`INSERT into maker.drip_file_ilk (header_id, ilk, vow, tax, log_idx, tx_idx, raw_log)
VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`,
@@ -89,6 +89,12 @@ var _ = Describe("Drip file ilk repository", func() {
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(sql.ErrNoRows))
})
It("Returns an error if model is of wrong type", func() {
err = dripFileIlkRepository.Create(headerID, []interface{}{test_data.WrongModel{}})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("model of type"))
})
})
Describe("MarkHeaderChecked", func() {