OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package memory |
| 6 |
| 7 import ( |
| 8 "testing" |
| 9 |
| 10 ds "github.com/luci/gae/service/datastore" |
| 11 "github.com/luci/gae/service/info" |
| 12 . "github.com/smartystreets/goconvey/convey" |
| 13 "golang.org/x/net/context" |
| 14 ) |
| 15 |
| 16 type qExpect struct { |
| 17 q ds.Query |
| 18 inTxn bool |
| 19 |
| 20 get []ds.PropertyMap |
| 21 } |
| 22 |
| 23 type qExStage struct { |
| 24 addIdxs []*ds.IndexDefinition |
| 25 addEnts []ds.PropertyMap |
| 26 |
| 27 expect []qExpect |
| 28 } |
| 29 |
| 30 type qExTest struct { |
| 31 name string |
| 32 test []qExStage |
| 33 } |
| 34 |
| 35 var queryExecutionTests = []qExTest{ |
| 36 {"basic", []qExStage{ |
| 37 { |
| 38 addEnts: []ds.PropertyMap{ |
| 39 pmap("$key", key("Something", 1), NEXT, |
| 40 "Val", 1, 2, 3, NEXT, |
| 41 "Extra", "hello", |
| 42 ), |
| 43 pmap("$key", key("Something", 2), NEXT, |
| 44 "Val", 8, 7, NEXT, |
| 45 "Extra", "zebra", |
| 46 ), |
| 47 pmap("$key", key("Something", 3), NEXT, |
| 48 "Val", 1, 2, 2, 100, NEXT, |
| 49 "Extra", "waffle", |
| 50 ), |
| 51 }, |
| 52 expect: []qExpect{ |
| 53 {q: nq("Something")}, |
| 54 }, |
| 55 }, |
| 56 { |
| 57 expect: []qExpect{ |
| 58 {q: nq("Something"), |
| 59 get: []ds.PropertyMap{ |
| 60 pmap("$key", key("Something", 1)
, NEXT, |
| 61 "Val", 1, 2, 3, NEXT, |
| 62 "Extra", "hello", |
| 63 ), |
| 64 pmap("$key", key("Something", 2)
, NEXT, |
| 65 "Val", 8, 7, NEXT, |
| 66 "Extra", "zebra", |
| 67 ), |
| 68 pmap("$key", key("Something", 3)
, NEXT, |
| 69 "Val", 1, 2, 2, 100, NEX
T, |
| 70 "Extra", "waffle", |
| 71 ), |
| 72 }}, |
| 73 }, |
| 74 }, |
| 75 }}, |
| 76 } |
| 77 |
| 78 func TestQueryExecution(t *testing.T) { |
| 79 t.Parallel() |
| 80 |
| 81 Convey("Test query execution", t, func() { |
| 82 c, err := info.Get(Use(context.Background())).Namespace("ns") |
| 83 So(err, ShouldBeNil) |
| 84 |
| 85 data := ds.Get(c) |
| 86 testing := data.Raw().Testable() |
| 87 |
| 88 for _, tc := range queryExecutionTests { |
| 89 Convey(tc.name, func() { |
| 90 for _, stage := range tc.test { |
| 91 testing.CatchupIndexes() |
| 92 |
| 93 testing.AddIndexes(stage.addIdxs...) |
| 94 So(data.PutMulti(stage.addEnts), ShouldB
eNil) |
| 95 |
| 96 for _, expect := range stage.expect { |
| 97 rslt := []ds.PropertyMap(nil) |
| 98 So(data.GetAll(expect.q, &rslt),
ShouldBeNil) |
| 99 So(rslt, ShouldResemble, expect.
get) |
| 100 } |
| 101 } |
| 102 }) |
| 103 } |
| 104 }) |
| 105 } |
OLD | NEW |