From 6d662a6ce7dc0d3dae4e41c4d23c4ae6bc643606 Mon Sep 17 00:00:00 2001 From: Rob Mulholand Date: Wed, 24 Oct 2018 16:44:35 -0500 Subject: [PATCH] Add test for can't create Vat tune of wrong type --- pkg/transformers/vat_tune/converter_test.go | 2 +- pkg/transformers/vat_tune/repository_test.go | 15 +++++++++++---- pkg/transformers/vat_tune/transformer_test.go | 16 +++++++++------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/pkg/transformers/vat_tune/converter_test.go b/pkg/transformers/vat_tune/converter_test.go index 09347aaa..6f8c21a3 100644 --- a/pkg/transformers/vat_tune/converter_test.go +++ b/pkg/transformers/vat_tune/converter_test.go @@ -33,7 +33,7 @@ var _ = Describe("Vat tune converter", func() { Expect(err).To(HaveOccurred()) }) - It("converts a log to an model", func() { + It("converts a log to a model", func() { converter := vat_tune.VatTuneConverter{} models, err := converter.ToModels([]types.Log{test_data.EthVatTuneLog}) diff --git a/pkg/transformers/vat_tune/repository_test.go b/pkg/transformers/vat_tune/repository_test.go index 7ab3fbd2..06bcedcc 100644 --- a/pkg/transformers/vat_tune/repository_test.go +++ b/pkg/transformers/vat_tune/repository_test.go @@ -14,6 +14,7 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_tune" "github.com/vulcanize/vulcanizedb/test_config" + "math/rand" ) var _ = Describe("Vat tune repository", func() { @@ -80,7 +81,7 @@ var _ = Describe("Vat tune repository", func() { Expect(headerChecked).To(BeTrue()) }) - It("does not duplicate pit file vat_tune events", func() { + It("does not duplicate vat tune events", func() { err = vatTuneRepository.Create(headerID, []interface{}{test_data.VatTuneModel}) Expect(err).NotTo(HaveOccurred()) @@ -90,7 +91,7 @@ var _ = Describe("Vat tune repository", func() { Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint")) }) - It("allows for multiple flop kick events in one transaction if they have different log indexes", func() { + It("allows for multiple vat tune events in one transaction if they have different log indexes", func() { err = vatTuneRepository.Create(headerID, []interface{}{test_data.VatTuneModel}) Expect(err).NotTo(HaveOccurred()) @@ -101,7 +102,7 @@ var _ = Describe("Vat tune repository", func() { Expect(err).NotTo(HaveOccurred()) }) - It("removes pit file vat_tune if corresponding header is deleted", func() { + It("removes vat tune if corresponding header is deleted", func() { err = vatTuneRepository.Create(headerID, []interface{}{test_data.VatTuneModel}) Expect(err).NotTo(HaveOccurred()) @@ -113,6 +114,12 @@ var _ = Describe("Vat tune repository", func() { Expect(err).To(HaveOccurred()) Expect(err).To(MatchError(sql.ErrNoRows)) }) + + It("returns an error if model is of wrong type", func() { + err = vatTuneRepository.Create(headerID, []interface{}{test_data.WrongModel{}}) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring("model of type")) + }) }) Describe("MarkHeaderChecked", func() { @@ -153,7 +160,7 @@ var _ = Describe("Vat tune repository", func() { ) BeforeEach(func() { - startingBlockNumber = GinkgoRandomSeed() + startingBlockNumber = rand.Int63() vatTuneBlockNumber = startingBlockNumber + 1 endingBlockNumber = startingBlockNumber + 2 diff --git a/pkg/transformers/vat_tune/transformer_test.go b/pkg/transformers/vat_tune/transformer_test.go index 743473ce..da9b59f6 100644 --- a/pkg/transformers/vat_tune/transformer_test.go +++ b/pkg/transformers/vat_tune/transformer_test.go @@ -18,13 +18,15 @@ import ( ) var _ = Describe("Vat tune transformer", func() { - var config = vat_tune.VatTuneConfig - var fetcher mocks.MockLogFetcher - var converter vat_tune_mocks.MockVatTuneConverter - var repository vat_tune_mocks.MockVatTuneRepository - var transformer shared.Transformer - var headerOne core.Header - var headerTwo core.Header + var ( + config = vat_tune.VatTuneConfig + fetcher mocks.MockLogFetcher + converter vat_tune_mocks.MockVatTuneConverter + repository vat_tune_mocks.MockVatTuneRepository + transformer shared.Transformer + headerOne core.Header + headerTwo core.Header + ) BeforeEach(func() { fetcher = mocks.MockLogFetcher{}