Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1127)

Unified Diff: impl/memory/datastore_query_execution_test.go

Issue 1302813003: impl/memory: Implement Queries (Closed) Base URL: https://github.com/luci/gae.git@add_multi_iterator
Patch Set: inequalities work now Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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)
+ }
+ }
+ })
+ }
+ })
+}

Powered by Google App Engine
This is Rietveld 408576698