Skip to content

Commit

Permalink
fix handling of simple filters and add a unit test for filters being …
Browse files Browse the repository at this point in the history
…passed from manager.
  • Loading branch information
singhsays committed Mar 19, 2018
1 parent dbf9b67 commit af653b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package goresource_test

import (
"fmt"
"net/url"

"goresource"
"goresource/mocks"
Expand Down Expand Up @@ -73,6 +74,17 @@ var _ = Describe("DefaultManager", func() {
})
Describe(".ListEntities", func() {
It("returns the fetched entities from the store.", func() {
want := []map[string]interface{}{{"item1": "value1"}, {"item2": "value2"}}
store.EXPECT().ListEntities("test", url.Values{"field": []string{"value"}}, gomock.Any()).Times(1).SetArg(2, want).Return(nil)
result, err := manager.ListEntities(url.Values{"field": []string{"value"}})
Expect(err).To(BeNil())
got, ok := result.([]map[string]interface{})
Expect(ok).To(BeTrue())
Expect(len(got)).To(Equal(2))
Expect(got[0]["item1"]).To(Equal("value1"))
Expect(got[1]["item2"]).To(Equal("value2"))
})
It("returns the fetched entities with filters from the store.", func() {
want := []map[string]interface{}{{"item1": "value1"}, {"item2": "value2"}}
store.EXPECT().ListEntities("test", nil, gomock.Any()).Times(1).SetArg(2, want).Return(nil)
result, err := manager.ListEntities(nil)
Expand Down
2 changes: 1 addition & 1 deletion store/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (s *MongoStore) ListEntities(name string, filters url.Values, result interf
if strings.HasSuffix(k, "~") {
search[k[0:len(k)-1]] = bson.M{"$regex": v[0], "$options": "im"}
} else {
if len(v) > 0 {
if len(v) > 1 {
search[k] = bson.M{"$in": v}
} else {
search[k] = v[0]
Expand Down

0 comments on commit af653b8

Please sign in to comment.