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

Side by Side Diff: service/datastore/datastore_test.go

Issue 1292913002: Split off serialization and key functions to their own packages. (Closed) Base URL: https://github.com/luci/gae.git@make_queries_better
Patch Set: rebase 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 unified diff | Download patch
« no previous file with comments | « service/datastore/context_test.go ('k') | service/datastore/dskey/doc.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // adapted from github.com/golang/appengine/datastore 5 // adapted from github.com/golang/appengine/datastore
6 6
7 package datastore 7 package datastore
8 8
9 import ( 9 import (
10 "fmt" 10 "fmt"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 return q 54 return q
55 } 55 }
56 56
57 type fakeDatastore struct { 57 type fakeDatastore struct {
58 RawInterface 58 RawInterface
59 aid string 59 aid string
60 ns string 60 ns string
61 } 61 }
62 62
63 func (f *fakeDatastore) NewKey(kind, stringID string, intID int64, parent Key) K ey { 63 func (f *fakeDatastore) NewKey(kind, stringID string, intID int64, parent Key) K ey {
64 » return NewKey(f.aid, f.ns, kind, stringID, intID, parent) 64 » id := interface{}(stringID)
65 » if stringID == "" {
66 » » id = intID
67 » }
68 » return mkKey(f.aid, f.ns, kind, id, parent)
65 } 69 }
66 70
67 func (f *fakeDatastore) NewQuery(string) Query { 71 func (f *fakeDatastore) NewQuery(string) Query {
68 return &fakeQuery{} 72 return &fakeQuery{}
69 } 73 }
70 74
71 func (f *fakeDatastore) Run(q Query, cb RawRunCB) error { 75 func (f *fakeDatastore) Run(q Query, cb RawRunCB) error {
72 rq := q.(*fakeQuery) 76 rq := q.(*fakeQuery)
73 if rq.err != nil { 77 if rq.err != nil {
74 return rq.err 78 return rq.err
(...skipping 25 matching lines...) Expand all
100 } 104 }
101 for i, k := range keys { 105 for i, k := range keys {
102 err := error(nil) 106 err := error(nil)
103 if k.Kind() == "Fail" { 107 if k.Kind() == "Fail" {
104 err = errors.New("PutMulti fail") 108 err = errors.New("PutMulti fail")
105 } else { 109 } else {
106 So(vals[i]["Value"], ShouldResemble, []Property{MkProper ty(i)}) 110 So(vals[i]["Value"], ShouldResemble, []Property{MkProper ty(i)})
107 if assertExtra { 111 if assertExtra {
108 So(vals[i]["Extra"], ShouldResemble, []Property{ MkProperty("whoa")}) 112 So(vals[i]["Extra"], ShouldResemble, []Property{ MkProperty("whoa")})
109 } 113 }
110 » » » if KeyIncomplete(k) { 114 » » » if k.Incomplete() {
111 » » » » k = NewKey(k.AppID(), k.Namespace(), k.Kind(), " ", int64(i+1), k.Parent()) 115 » » » » k = mkKey(k.AppID(), k.Namespace(), k.Kind(), in t64(i+1), k.Parent())
112 } 116 }
113 } 117 }
114 cb(k, err) 118 cb(k, err)
115 } 119 }
116 return nil 120 return nil
117 } 121 }
118 122
119 func (f *fakeDatastore) GetMulti(keys []Key, _meta MultiMetaGetter, cb GetMultiC B) error { 123 func (f *fakeDatastore) GetMulti(keys []Key, _meta MultiMetaGetter, cb GetMultiC B) error {
120 if keys[0].Kind() == "FailAll" { 124 if keys[0].Kind() == "FailAll" {
121 return errors.New("GetMulti fail all") 125 return errors.New("GetMulti fail all")
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 545
542 Convey("Test Delete/DeleteMulti", t, func() { 546 Convey("Test Delete/DeleteMulti", t, func() {
543 c := info.Set(context.Background(), fakeInfo{}) 547 c := info.Set(context.Background(), fakeInfo{})
544 c = SetRawFactory(c, fakeDatastoreFactory) 548 c = SetRawFactory(c, fakeDatastoreFactory)
545 ds := Get(c) 549 ds := Get(c)
546 So(ds, ShouldNotBeNil) 550 So(ds, ShouldNotBeNil)
547 551
548 Convey("bad", func() { 552 Convey("bad", func() {
549 Convey("get single error for RPC failure", func() { 553 Convey("get single error for RPC failure", func() {
550 keys := []Key{ 554 keys := []Key{
551 » » » » » NewKey("aid", "ns", "FailAll", "", 1, ni l), 555 » » » » » mkKey("aid", "ns", "FailAll", 1, nil),
552 » » » » » NewKey("aid", "ns", "Ok", "", 1, nil), 556 » » » » » mkKey("aid", "ns", "Ok", 1, nil),
553 } 557 }
554 So(ds.DeleteMulti(keys).Error(), ShouldEqual, "D eleteMulti fail all") 558 So(ds.DeleteMulti(keys).Error(), ShouldEqual, "D eleteMulti fail all")
555 }) 559 })
556 560
557 Convey("get multi error for individual failure", func() { 561 Convey("get multi error for individual failure", func() {
558 keys := []Key{ 562 keys := []Key{
559 ds.NewKey("Ok", "", 1, nil), 563 ds.NewKey("Ok", "", 1, nil),
560 ds.NewKey("Fail", "", 2, nil), 564 ds.NewKey("Fail", "", 2, nil),
561 } 565 }
562 So(ds.DeleteMulti(keys).Error(), ShouldEqual, "D eleteMulti fail") 566 So(ds.DeleteMulti(keys).Error(), ShouldEqual, "D eleteMulti fail")
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 So(ds.Run(q, func(k Key, _ CursorCB) bool { 894 So(ds.Run(q, func(k Key, _ CursorCB) bool {
891 So(k.IntID(), ShouldEqual, i+1) 895 So(k.IntID(), ShouldEqual, i+1)
892 i++ 896 i++
893 return true 897 return true
894 }), ShouldBeNil) 898 }), ShouldBeNil)
895 }) 899 })
896 900
897 }) 901 })
898 }) 902 })
899 } 903 }
OLDNEW
« no previous file with comments | « service/datastore/context_test.go ('k') | service/datastore/dskey/doc.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698