Add cat file repository tests
This commit is contained in:
parent
00bb48bafb
commit
5de949f4c5
@ -52,12 +52,12 @@ var _ = Describe("Cat file chop lump repository", func() {
|
|||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileChopLumpModel})
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("adds a cat file chop lump event", func() {
|
It("adds a cat file chop lump event", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileChopLumpModel})
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
var dbResult chop_lump.CatFileChopLumpModel
|
var dbResult chop_lump.CatFileChopLumpModel
|
||||||
err = db.Get(&dbResult, `SELECT ilk, what, data, tx_idx, log_idx, raw_log FROM maker.cat_file_chop_lump WHERE header_id = $1`, headerID)
|
err = db.Get(&dbResult, `SELECT ilk, what, data, tx_idx, log_idx, raw_log FROM maker.cat_file_chop_lump WHERE header_id = $1`, headerID)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
@ -70,6 +70,22 @@ var _ = Describe("Cat file chop lump repository", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("marks header as checked for logs", func() {
|
It("marks header as checked for logs", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileChopLumpModel})
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
var headerChecked bool
|
||||||
|
err = db.Get(&headerChecked, `SELECT cat_file_chop_lump_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(headerChecked).To(BeTrue())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("updates the header to checked if checked headers row already exists", func() {
|
||||||
|
_, err := db.Exec(`INSERT INTO public.checked_headers (header_id) VALUES ($1)`, headerID)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileChopLumpModel})
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
var headerChecked bool
|
var headerChecked bool
|
||||||
err = db.Get(&headerChecked, `SELECT cat_file_chop_lump_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
err = db.Get(&headerChecked, `SELECT cat_file_chop_lump_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
@ -77,6 +93,9 @@ var _ = Describe("Cat file chop lump repository", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("does not duplicate cat file chop lump events", func() {
|
It("does not duplicate cat file chop lump events", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileChopLumpModel})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileChopLumpModel})
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileChopLumpModel})
|
||||||
|
|
||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
@ -84,14 +103,20 @@ var _ = Describe("Cat file chop lump repository", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("allows for multiple cat file chop lump events in one transaction if they have different log indexes", func() {
|
It("allows for multiple cat file chop lump events in one transaction if they have different log indexes", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileChopLumpModel})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
newCatFileChopLump := test_data.CatFileChopLumpModel
|
newCatFileChopLump := test_data.CatFileChopLumpModel
|
||||||
newCatFileChopLump.LogIndex = newCatFileChopLump.LogIndex + 1
|
newCatFileChopLump.LogIndex = newCatFileChopLump.LogIndex + 1
|
||||||
|
|
||||||
err = catFileRepository.Create(headerID, []interface{}{newCatFileChopLump})
|
err = catFileRepository.Create(headerID, []interface{}{newCatFileChopLump})
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("removes cat file chop lump if corresponding header is deleted", func() {
|
It("removes cat file chop lump if corresponding header is deleted", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileChopLumpModel})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
_, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID)
|
_, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID)
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
@ -100,6 +125,12 @@ var _ = Describe("Cat file chop lump repository", func() {
|
|||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
Expect(err).To(MatchError(sql.ErrNoRows))
|
Expect(err).To(MatchError(sql.ErrNoRows))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("returns an error if model is of wrong type", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.WrongModel{}})
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
Expect(err.Error()).To(ContainSubstring("model of type"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("MarkHeaderChecked", func() {
|
Describe("MarkHeaderChecked", func() {
|
||||||
|
@ -52,12 +52,12 @@ var _ = Describe("Cat file flip repository", func() {
|
|||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileFlipModel})
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("adds a cat file flip event", func() {
|
It("adds a cat file flip event", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileFlipModel})
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
var dbResult flip.CatFileFlipModel
|
var dbResult flip.CatFileFlipModel
|
||||||
err = db.Get(&dbResult, `SELECT ilk, what, flip, tx_idx, log_idx, raw_log FROM maker.cat_file_flip WHERE header_id = $1`, headerID)
|
err = db.Get(&dbResult, `SELECT ilk, what, flip, tx_idx, log_idx, raw_log FROM maker.cat_file_flip WHERE header_id = $1`, headerID)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
@ -70,6 +70,22 @@ var _ = Describe("Cat file flip repository", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("marks header as checked for logs", func() {
|
It("marks header as checked for logs", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileFlipModel})
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
var headerChecked bool
|
||||||
|
err = db.Get(&headerChecked, `SELECT cat_file_flip_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(headerChecked).To(BeTrue())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("updates the header to checked if checked headers row already exists", func() {
|
||||||
|
_, err := db.Exec(`INSERT INTO public.checked_headers (header_id) VALUES ($1)`, headerID)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileFlipModel})
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
var headerChecked bool
|
var headerChecked bool
|
||||||
err = db.Get(&headerChecked, `SELECT cat_file_flip_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
err = db.Get(&headerChecked, `SELECT cat_file_flip_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
@ -77,6 +93,9 @@ var _ = Describe("Cat file flip repository", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("does not duplicate cat file flip events", func() {
|
It("does not duplicate cat file flip events", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileFlipModel})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileFlipModel})
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileFlipModel})
|
||||||
|
|
||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
@ -84,14 +103,20 @@ var _ = Describe("Cat file flip repository", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("allows for multiple cat file flip events in one transaction if they have different log indexes", func() {
|
It("allows for multiple cat file flip events in one transaction if they have different log indexes", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileFlipModel})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
catFileFlip := test_data.CatFileFlipModel
|
catFileFlip := test_data.CatFileFlipModel
|
||||||
catFileFlip.LogIndex = catFileFlip.LogIndex + 1
|
catFileFlip.LogIndex = catFileFlip.LogIndex + 1
|
||||||
|
|
||||||
err = catFileRepository.Create(headerID, []interface{}{catFileFlip})
|
err = catFileRepository.Create(headerID, []interface{}{catFileFlip})
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("removes cat file flip if corresponding header is deleted", func() {
|
It("removes cat file flip if corresponding header is deleted", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFileFlipModel})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
_, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID)
|
_, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID)
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
@ -100,6 +125,12 @@ var _ = Describe("Cat file flip repository", func() {
|
|||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
Expect(err).To(MatchError(sql.ErrNoRows))
|
Expect(err).To(MatchError(sql.ErrNoRows))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("returns an error if model is of wrong type", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.WrongModel{}})
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
Expect(err.Error()).To(ContainSubstring("model of type"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("MarkHeaderChecked", func() {
|
Describe("MarkHeaderChecked", func() {
|
||||||
|
@ -52,12 +52,12 @@ var _ = Describe("Cat file pit vow repository", func() {
|
|||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFilePitVowModel})
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("adds a cat file pit vow event", func() {
|
It("adds a cat file pit vow event", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFilePitVowModel})
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
var dbResult pit_vow.CatFilePitVowModel
|
var dbResult pit_vow.CatFilePitVowModel
|
||||||
err = db.Get(&dbResult, `SELECT what, data, tx_idx, log_idx, raw_log FROM maker.cat_file_pit_vow WHERE header_id = $1`, headerID)
|
err = db.Get(&dbResult, `SELECT what, data, tx_idx, log_idx, raw_log FROM maker.cat_file_pit_vow WHERE header_id = $1`, headerID)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
@ -69,6 +69,22 @@ var _ = Describe("Cat file pit vow repository", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("marks header as checked for logs", func() {
|
It("marks header as checked for logs", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFilePitVowModel})
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
var headerChecked bool
|
||||||
|
err = db.Get(&headerChecked, `SELECT cat_file_pit_vow_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(headerChecked).To(BeTrue())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("updates the header to checked if checked headers row already exists", func() {
|
||||||
|
_, err := db.Exec(`INSERT INTO public.checked_headers (header_id) VALUES ($1)`, headerID)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFilePitVowModel})
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
var headerChecked bool
|
var headerChecked bool
|
||||||
err = db.Get(&headerChecked, `SELECT cat_file_pit_vow_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
err = db.Get(&headerChecked, `SELECT cat_file_pit_vow_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
@ -76,6 +92,9 @@ var _ = Describe("Cat file pit vow repository", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("does not duplicate cat file pit vow events", func() {
|
It("does not duplicate cat file pit vow events", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFilePitVowModel})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFilePitVowModel})
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFilePitVowModel})
|
||||||
|
|
||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
@ -83,14 +102,20 @@ var _ = Describe("Cat file pit vow repository", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("allows for multiple cat file pit events in one transaction if they have different log indexes", func() {
|
It("allows for multiple cat file pit events in one transaction if they have different log indexes", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFilePitVowModel})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
catFilePitVow := test_data.CatFilePitVowModel
|
catFilePitVow := test_data.CatFilePitVowModel
|
||||||
catFilePitVow.LogIndex = catFilePitVow.LogIndex + 1
|
catFilePitVow.LogIndex = catFilePitVow.LogIndex + 1
|
||||||
|
|
||||||
err = catFileRepository.Create(headerID, []interface{}{catFilePitVow})
|
err = catFileRepository.Create(headerID, []interface{}{catFilePitVow})
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("removes cat file pit vow if corresponding header is deleted", func() {
|
It("removes cat file pit vow if corresponding header is deleted", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.CatFilePitVowModel})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
_, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID)
|
_, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID)
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
@ -99,6 +124,12 @@ var _ = Describe("Cat file pit vow repository", func() {
|
|||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
Expect(err).To(MatchError(sql.ErrNoRows))
|
Expect(err).To(MatchError(sql.ErrNoRows))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("returns an error if model is of wrong type", func() {
|
||||||
|
err = catFileRepository.Create(headerID, []interface{}{test_data.WrongModel{}})
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
Expect(err.Error()).To(ContainSubstring("model of type"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("MarkHeaderChecked", func() {
|
Describe("MarkHeaderChecked", func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user