Skip to content

Commit

Permalink
Fix tests for firestore backends
Browse files Browse the repository at this point in the history
Reimplement cleanup code in the test itself, since the helper method is
gone.
  • Loading branch information
Andrew Lytvynov authored and awly committed May 27, 2020
1 parent 42c034e commit 983b735
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
18 changes: 15 additions & 3 deletions lib/backend/firestore/firestorebk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,24 @@ func (s *FirestoreSuite) SetUpSuite(c *check.C) {
s.suite.NewBackend = newBackend
}

func (s *FirestoreSuite) SetUpTest(c *check.C) {
s.bk.deleteAllItems()
func (s *FirestoreSuite) TearDownTest(c *check.C) {
// Delete all documents.
ctx := context.Background()
docSnaps, err := s.bk.svc.Collection(s.bk.CollectionName).Documents(ctx).GetAll()
c.Assert(err, check.IsNil)
if len(docSnaps) == 0 {
return
}
batch := s.bk.svc.Batch()
for _, docSnap := range docSnaps {
batch.Delete(docSnap.Ref)
}
_, err = batch.Commit(ctx)
c.Assert(err, check.IsNil)
}

func (s *FirestoreSuite) TearDownSuite(c *check.C) {
s.bk.deleteAllItems()
s.bk.Close()
}

func (s *FirestoreSuite) TestCRUD(c *check.C) {
Expand Down
25 changes: 19 additions & 6 deletions lib/events/firestoreevents/firestoreevents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
package firestoreevents

import (
"context"
"testing"
"time"

Expand Down Expand Up @@ -61,14 +62,26 @@ func (s *FirestoreeventsSuite) SetUpSuite(c *check.C) {
s.EventsSuite.QueryDelay = time.Second
}

func (s *FirestoreeventsSuite) SetUpTest(c *check.C) {
s.log.deleteAllItems()
func (s *FirestoreeventsSuite) TearDownSuite(c *check.C) {
s.log.Close()
}

func (s *FirestoreeventsSuite) TestSessionEventsCRUD(c *check.C) {
s.SessionEventsCRUD(c)
func (s *FirestoreeventsSuite) TearDownTest(c *check.C) {
// Delete all documents.
ctx := context.Background()
docSnaps, err := s.log.svc.Collection(s.log.CollectionName).Documents(ctx).GetAll()
c.Assert(err, check.IsNil)
if len(docSnaps) == 0 {
return
}
batch := s.log.svc.Batch()
for _, docSnap := range docSnaps {
batch.Delete(docSnap.Ref)
}
_, err = batch.Commit(ctx)
c.Assert(err, check.IsNil)
}

func (s *FirestoreeventsSuite) TearDownSuite(c *check.C) {
s.log.deleteAllItems()
func (s *FirestoreeventsSuite) TestSessionEventsCRUD(c *check.C) {
s.SessionEventsCRUD(c)
}

0 comments on commit 983b735

Please sign in to comment.