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 defaultData = []ds.PropertyMap{ |
| 36 pmap("$key", key("Something", 1), NEXT, |
| 37 "Val", 1, 2, 3, NEXT, |
| 38 "Extra", "hello", |
| 39 ), |
| 40 pmap("$key", key("Something", 2), NEXT, |
| 41 "Val", 6, 8, 7, NEXT, |
| 42 "Extra", "zebra", |
| 43 ), |
| 44 pmap("$key", key("Something", 3), NEXT, |
| 45 "Val", 1, 2, 2, 100, NEXT, |
| 46 "Extra", "waffle", |
| 47 ), |
| 48 pmap("$key", key("Something", 6), NEXT, |
| 49 "Val", 5, NEXT, |
| 50 "Extra", "waffle", |
| 51 ), |
| 52 } |
| 53 |
| 54 var queryExecutionTests = []qExTest{ |
| 55 {"basic", []qExStage{ |
| 56 { |
| 57 addEnts: defaultData, |
| 58 expect: []qExpect{ |
| 59 {q: nq("Something")}, |
| 60 }, |
| 61 }, |
| 62 { |
| 63 expect: []qExpect{ |
| 64 {q: nq("Something"), get: defaultData}, |
| 65 {q: nq("Something").Filter("Extra =", "waffle"),
get: []ds.PropertyMap{ |
| 66 defaultData[2], defaultData[3], |
| 67 }}, |
| 68 // get ziggy with it |
| 69 {q: nq("Something").Filter("Extra =", "waffle").
Filter("Val =", 100), get: []ds.PropertyMap{ |
| 70 defaultData[2], |
| 71 }}, |
| 72 {q: nq("Something").Filter("Val >", 2).Filter("V
al <=", 5), get: []ds.PropertyMap{ |
| 73 defaultData[0], defaultData[3], |
| 74 }}, |
| 75 }, |
| 76 }, |
| 77 }}, |
| 78 } |
| 79 |
| 80 func TestQueryExecution(t *testing.T) { |
| 81 t.Parallel() |
| 82 |
| 83 Convey("Test query execution", t, func() { |
| 84 c, err := info.Get(Use(context.Background())).Namespace("ns") |
| 85 So(err, ShouldBeNil) |
| 86 |
| 87 data := ds.Get(c) |
| 88 testing := data.Raw().Testable() |
| 89 |
| 90 for _, tc := range queryExecutionTests { |
| 91 Convey(tc.name, func() { |
| 92 for _, stage := range tc.test { |
| 93 testing.CatchupIndexes() |
| 94 |
| 95 testing.AddIndexes(stage.addIdxs...) |
| 96 So(data.PutMulti(stage.addEnts), ShouldB
eNil) |
| 97 |
| 98 for _, expect := range stage.expect { |
| 99 rslt := []ds.PropertyMap(nil) |
| 100 So(data.GetAll(expect.q, &rslt),
ShouldBeNil) |
| 101 So(rslt, ShouldResemble, expect.
get) |
| 102 } |
| 103 } |
| 104 }) |
| 105 } |
| 106 }) |
| 107 } |
OLD | NEW |