| Index: impl/memory/datastore_query_execution_test.go
|
| diff --git a/impl/memory/datastore_query_execution_test.go b/impl/memory/datastore_query_execution_test.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..57f649450f2e591c4491157932d0dcbe460b725b
|
| --- /dev/null
|
| +++ b/impl/memory/datastore_query_execution_test.go
|
| @@ -0,0 +1,107 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package memory
|
| +
|
| +import (
|
| + "testing"
|
| +
|
| + ds "github.com/luci/gae/service/datastore"
|
| + "github.com/luci/gae/service/info"
|
| + . "github.com/smartystreets/goconvey/convey"
|
| + "golang.org/x/net/context"
|
| +)
|
| +
|
| +type qExpect struct {
|
| + q ds.Query
|
| + inTxn bool
|
| +
|
| + get []ds.PropertyMap
|
| +}
|
| +
|
| +type qExStage struct {
|
| + addIdxs []*ds.IndexDefinition
|
| + addEnts []ds.PropertyMap
|
| +
|
| + expect []qExpect
|
| +}
|
| +
|
| +type qExTest struct {
|
| + name string
|
| + test []qExStage
|
| +}
|
| +
|
| +var defaultData = []ds.PropertyMap{
|
| + pmap("$key", key("Something", 1), NEXT,
|
| + "Val", 1, 2, 3, NEXT,
|
| + "Extra", "hello",
|
| + ),
|
| + pmap("$key", key("Something", 2), NEXT,
|
| + "Val", 6, 8, 7, NEXT,
|
| + "Extra", "zebra",
|
| + ),
|
| + pmap("$key", key("Something", 3), NEXT,
|
| + "Val", 1, 2, 2, 100, NEXT,
|
| + "Extra", "waffle",
|
| + ),
|
| + pmap("$key", key("Something", 6), NEXT,
|
| + "Val", 5, NEXT,
|
| + "Extra", "waffle",
|
| + ),
|
| +}
|
| +
|
| +var queryExecutionTests = []qExTest{
|
| + {"basic", []qExStage{
|
| + {
|
| + addEnts: defaultData,
|
| + expect: []qExpect{
|
| + {q: nq("Something")},
|
| + },
|
| + },
|
| + {
|
| + expect: []qExpect{
|
| + {q: nq("Something"), get: defaultData},
|
| + {q: nq("Something").Filter("Extra =", "waffle"), get: []ds.PropertyMap{
|
| + defaultData[2], defaultData[3],
|
| + }},
|
| + // get ziggy with it
|
| + {q: nq("Something").Filter("Extra =", "waffle").Filter("Val =", 100), get: []ds.PropertyMap{
|
| + defaultData[2],
|
| + }},
|
| + {q: nq("Something").Filter("Val >", 2).Filter("Val <=", 5), get: []ds.PropertyMap{
|
| + defaultData[0], defaultData[3],
|
| + }},
|
| + },
|
| + },
|
| + }},
|
| +}
|
| +
|
| +func TestQueryExecution(t *testing.T) {
|
| + t.Parallel()
|
| +
|
| + Convey("Test query execution", t, func() {
|
| + c, err := info.Get(Use(context.Background())).Namespace("ns")
|
| + So(err, ShouldBeNil)
|
| +
|
| + data := ds.Get(c)
|
| + testing := data.Raw().Testable()
|
| +
|
| + for _, tc := range queryExecutionTests {
|
| + Convey(tc.name, func() {
|
| + for _, stage := range tc.test {
|
| + testing.CatchupIndexes()
|
| +
|
| + testing.AddIndexes(stage.addIdxs...)
|
| + So(data.PutMulti(stage.addEnts), ShouldBeNil)
|
| +
|
| + for _, expect := range stage.expect {
|
| + rslt := []ds.PropertyMap(nil)
|
| + So(data.GetAll(expect.q, &rslt), ShouldBeNil)
|
| + So(rslt, ShouldResemble, expect.get)
|
| + }
|
| + }
|
| + })
|
| + }
|
| + })
|
| +}
|
|
|