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
+8 -2
View File
@@ -15,6 +15,7 @@
package tend
import (
"fmt"
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
)
@@ -28,9 +29,14 @@ func (repository TendRepository) Create(headerId int64, models []interface{}) er
if err != nil {
return err
}
var tend TendModel
for _, model := range models {
tend = model.(TendModel)
tend, ok := model.(TendModel)
if !ok {
tx.Rollback()
return fmt.Errorf("model of type %T, not %T", model, TendModel{})
}
_, err = tx.Exec(
`INSERT into maker.tend (header_id, bid_id, lot, bid, guy, tic, tx_idx, raw_log)
VALUES($1, $2, $3, $4, $5, $6, $7, $8)`,
+6
View File
@@ -98,6 +98,12 @@ var _ = Describe("TendRepository", func() {
Expect(err).NotTo(HaveOccurred())
Expect(count).To(Equal(0))
})
It("Returns an error if model is of wrong type", func() {
err = tendRepository.Create(headerId, []interface{}{test_data.WrongModel{}})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("model of type"))
})
})
Describe("MarkHeaderChecked", func() {