Skip to content

Commit

Permalink
Merge pull request #57 from dpordomingo/kallaxTestsFixes
Browse files Browse the repository at this point in the history
Kallax integration tests fixes
  • Loading branch information
dpordomingo committed Jan 31, 2017
2 parents 335d899 + 7ab7453 commit 71e9e10
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions generator/templates/resultset.tgo
Expand Up @@ -19,6 +19,7 @@ func New{{.ResultSetName}}(rs kallax.ResultSet) *{{.ResultSetName}} {
func (rs *{{.ResultSetName}}) Next() bool {
if !rs.ResultSet.Next() {
rs.lastErr = rs.ResultSet.Close()
rs.last = nil
return false
}

Expand Down
5 changes: 1 addition & 4 deletions tests/common_test.go
Expand Up @@ -95,10 +95,7 @@ func (s *BaseTestSuite) resultOrError(res interface{}, err error) bool {
}

if err == nil && res == nil {
s.Fail(
`FindOne should return an error or a document, but nothing was returned
TODO: https://github.com/src-d/go-kallax/issues/49`,
)
s.Fail("FindOne should return an error or a document, but nothing was returned")
return false
}

Expand Down
12 changes: 12 additions & 0 deletions tests/kallax.go
Expand Up @@ -356,6 +356,7 @@ func NewCarResultSet(rs kallax.ResultSet) *CarResultSet {
func (rs *CarResultSet) Next() bool {
if !rs.ResultSet.Next() {
rs.lastErr = rs.ResultSet.Close()
rs.last = nil
return false
}

Expand Down Expand Up @@ -735,6 +736,7 @@ func NewEventsFixtureResultSet(rs kallax.ResultSet) *EventsFixtureResultSet {
func (rs *EventsFixtureResultSet) Next() bool {
if !rs.ResultSet.Next() {
rs.lastErr = rs.ResultSet.Close()
rs.last = nil
return false
}

Expand Down Expand Up @@ -1106,6 +1108,7 @@ func NewEventsSaveFixtureResultSet(rs kallax.ResultSet) *EventsSaveFixtureResult
func (rs *EventsSaveFixtureResultSet) Next() bool {
if !rs.ResultSet.Next() {
rs.lastErr = rs.ResultSet.Close()
rs.last = nil
return false
}

Expand Down Expand Up @@ -1465,6 +1468,7 @@ func NewMultiKeySortFixtureResultSet(rs kallax.ResultSet) *MultiKeySortFixtureRe
func (rs *MultiKeySortFixtureResultSet) Next() bool {
if !rs.ResultSet.Next() {
rs.lastErr = rs.ResultSet.Close()
rs.last = nil
return false
}

Expand Down Expand Up @@ -1987,6 +1991,7 @@ func NewPersonResultSet(rs kallax.ResultSet) *PersonResultSet {
func (rs *PersonResultSet) Next() bool {
if !rs.ResultSet.Next() {
rs.lastErr = rs.ResultSet.Close()
rs.last = nil
return false
}

Expand Down Expand Up @@ -2419,6 +2424,7 @@ func NewPetResultSet(rs kallax.ResultSet) *PetResultSet {
func (rs *PetResultSet) Next() bool {
if !rs.ResultSet.Next() {
rs.lastErr = rs.ResultSet.Close()
rs.last = nil
return false
}

Expand Down Expand Up @@ -2770,6 +2776,7 @@ func NewQueryFixtureResultSet(rs kallax.ResultSet) *QueryFixtureResultSet {
func (rs *QueryFixtureResultSet) Next() bool {
if !rs.ResultSet.Next() {
rs.lastErr = rs.ResultSet.Close()
rs.last = nil
return false
}

Expand Down Expand Up @@ -3121,6 +3128,7 @@ func NewResultSetFixtureResultSet(rs kallax.ResultSet) *ResultSetFixtureResultSe
func (rs *ResultSetFixtureResultSet) Next() bool {
if !rs.ResultSet.Next() {
rs.lastErr = rs.ResultSet.Close()
rs.last = nil
return false
}

Expand Down Expand Up @@ -3582,6 +3590,7 @@ func NewSchemaFixtureResultSet(rs kallax.ResultSet) *SchemaFixtureResultSet {
func (rs *SchemaFixtureResultSet) Next() bool {
if !rs.ResultSet.Next() {
rs.lastErr = rs.ResultSet.Close()
rs.last = nil
return false
}

Expand Down Expand Up @@ -3933,6 +3942,7 @@ func NewStoreFixtureResultSet(rs kallax.ResultSet) *StoreFixtureResultSet {
func (rs *StoreFixtureResultSet) Next() bool {
if !rs.ResultSet.Next() {
rs.lastErr = rs.ResultSet.Close()
rs.last = nil
return false
}

Expand Down Expand Up @@ -4284,6 +4294,7 @@ func NewStoreWithConstructFixtureResultSet(rs kallax.ResultSet) *StoreWithConstr
func (rs *StoreWithConstructFixtureResultSet) Next() bool {
if !rs.ResultSet.Next() {
rs.lastErr = rs.ResultSet.Close()
rs.last = nil
return false
}

Expand Down Expand Up @@ -4639,6 +4650,7 @@ func NewStoreWithNewFixtureResultSet(rs kallax.ResultSet) *StoreWithNewFixtureRe
func (rs *StoreWithNewFixtureResultSet) Next() bool {
if !rs.ResultSet.Next() {
rs.lastErr = rs.ResultSet.Close()
rs.last = nil
return false
}

Expand Down
3 changes: 2 additions & 1 deletion tests/query_test.go
Expand Up @@ -29,9 +29,10 @@ func (s *QuerySuite) TestQuery() {

query := NewQueryFixtureQuery()
query.Where(kallax.Eq(Schema.QueryFixture.ID, doc.ID))

s.NotPanics(func() {
s.Equal("bar", store.MustFindOne(query).Foo)
}, "TODO: https://github.com/src-d/go-kallax/issues/49")
})

notID := kallax.NewID()
queryErr := NewQueryFixtureQuery()
Expand Down
3 changes: 1 addition & 2 deletions tests/resultset_test.go
Expand Up @@ -136,7 +136,6 @@ func (s *ResulsetSuite) TestResultSetForEachError() {
})
}

// TODO: https://github.com/src-d/go-kallax/issues/49
func (s *ResulsetSuite) TestForEachAndCount() {
store := NewResultSetFixtureStore(s.db)

Expand All @@ -151,7 +150,7 @@ func (s *ResulsetSuite) TestForEachAndCount() {
manualCount := 0
rs.ForEach(func(doc *ResultSetFixture) error {
manualCount++
s.NotNil(doc, "TODO: https://github.com/src-d/go-kallax/issues/49")
s.NotNil(doc)
return nil
})
s.Equal(2, manualCount)
Expand Down
18 changes: 7 additions & 11 deletions tests/store_test.go
Expand Up @@ -86,15 +86,15 @@ func (s *StoreSuite) TestStoreInsertUpdateMustFind() {
s.Nil(err)
s.NotPanics(func() {
s.Equal("foo", store.MustFindOne(NewStoreWithConstructFixtureQuery()).Foo)
}, "TODO: https://github.com/src-d/go-kallax/issues/49")
})

doc.Foo = "bar"
updatedRows, err := store.Update(doc)
s.Nil(err)
s.True(updatedRows > 0)
s.NotPanics(func() {
s.Equal("bar", store.MustFindOne(NewStoreWithConstructFixtureQuery()).Foo)
}, "TODO: https://github.com/src-d/go-kallax/issues/49")
})
}

func (s *StoreSuite) TestStoreSave() {
Expand All @@ -107,15 +107,15 @@ func (s *StoreSuite) TestStoreSave() {
s.True(doc.IsPersisted())
s.NotPanics(func() {
s.Equal("foo", store.MustFindOne(NewStoreWithConstructFixtureQuery()).Foo)
}, "TODO: https://github.com/src-d/go-kallax/issues/49")
})

doc.Foo = "bar"
updated, err = store.Save(doc)
s.Nil(err)
s.True(updated)
s.NotPanics(func() {
s.Equal("bar", store.MustFindOne(NewStoreWithConstructFixtureQuery()).Foo)
}, "TODO: https://github.com/src-d/go-kallax/issues/49")
})
}

func (s *StoreSuite) TestMultiKeySort() {
Expand Down Expand Up @@ -169,16 +169,13 @@ func (s *StoreSuite) TestMultiKeySort() {
s.Len(documents, 4)
success := true
for _, doc := range documents {
if !s.NotNil(doc, "TODO: https://github.com/src-d/go-kallax/issues/49") {
if !s.NotNil(doc) {
success = false
}
}

if !success {
s.Fail(
`Testcase aborted. All retrieved Documents should be not-nil
TODO: https://github.com/src-d/go-kallax/issues/49`,
)
s.Fail("Testcase aborted. All retrieved Documents should be not-nil")
return
}

Expand All @@ -188,7 +185,6 @@ func (s *StoreSuite) TestMultiKeySort() {
s.Equal("2001-2012", documents[3].Name)
}

// TODO: https://github.com/src-d/go-kallax/issues/49
func (s *StoreSuite) TestFindOne() {
store := NewStoreWithConstructFixtureStore(s.db)

Expand All @@ -198,7 +194,7 @@ func (s *StoreSuite) TestFindOne() {
query := NewStoreWithConstructFixtureQuery()
docFound, err := store.FindOne(query)
s.resultOrError(docFound, err)
if s.NotNil(docFound, "TODO: https://github.com/src-d/go-kallax/issues/49") {
if s.NotNil(docFound) {
s.Equal(docInserted.Foo, docFound.Foo)
}
}

0 comments on commit 71e9e10

Please sign in to comment.