fix(module,store): allow querying on _id, _createdAt, _updatedAt attributes
This commit is contained in:
@ -6,7 +6,6 @@ import (
|
||||
|
||||
"forge.cadoles.com/arcad/edge/pkg/storage"
|
||||
"forge.cadoles.com/arcad/edge/pkg/storage/filter"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -58,6 +57,43 @@ var documentStoreOpsTestCases = []documentStoreOpsTestCase{
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Query on _id",
|
||||
Run: func(ctx context.Context, store storage.DocumentStore) error {
|
||||
collection := "query_on_id"
|
||||
|
||||
doc := storage.Document{
|
||||
"attr1": "Foo",
|
||||
}
|
||||
|
||||
upsertedDoc, err := store.Upsert(ctx, collection, doc)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
docID, ok := upsertedDoc.ID()
|
||||
if !ok {
|
||||
return errors.Errorf("")
|
||||
}
|
||||
|
||||
filter := filter.New(
|
||||
filter.NewEqOperator(map[string]interface{}{
|
||||
"_id": docID,
|
||||
}),
|
||||
)
|
||||
|
||||
results, err := store.Query(ctx, collection, filter, nil)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if e, g := 1, len(results); e != g {
|
||||
return errors.Errorf("len(results): expected '%v', got '%v'", e, g)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Query with 'IN' operator",
|
||||
Run: func(ctx context.Context, store storage.DocumentStore) error {
|
||||
@ -160,8 +196,6 @@ var documentStoreOpsTestCases = []documentStoreOpsTestCase{
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
spew.Dump(upsertedDoc, upsertedDoc2)
|
||||
|
||||
prevID, _ := upsertedDoc.ID()
|
||||
newID, _ := upsertedDoc2.ID()
|
||||
|
||||
|
Reference in New Issue
Block a user