| OLD | NEW |
| 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" |
| 11 "testing" | 11 "testing" |
| 12 | 12 |
| 13 "github.com/luci/gae/service/info" | 13 "github.com/luci/gae/service/info" |
| 14 "github.com/luci/luci-go/common/errors" | 14 "github.com/luci/luci-go/common/errors" |
| 15 . "github.com/smartystreets/goconvey/convey" | 15 . "github.com/smartystreets/goconvey/convey" |
| 16 "golang.org/x/net/context" | 16 "golang.org/x/net/context" |
| 17 ) | 17 ) |
| 18 | 18 |
| 19 func fakeDatastoreFactory(c context.Context) RawInterface { | 19 func fakeDatastoreFactory(c context.Context) RawInterface { |
| 20 i := info.Get(c) | 20 i := info.Get(c) |
| 21 return &fakeDatastore{ | 21 return &fakeDatastore{ |
| 22 » » aid: i.AppID(), | 22 » » aid: i.FullyQualifiedAppID(), |
| 23 ns: i.GetNamespace(), | 23 ns: i.GetNamespace(), |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 type fakeQuery struct { | 27 type fakeQuery struct { |
| 28 Query | 28 Query |
| 29 | 29 |
| 30 limit int | 30 limit int |
| 31 | 31 |
| 32 err error | 32 err error |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 | 545 |
| 546 Convey("Test Delete/DeleteMulti", t, func() { | 546 Convey("Test Delete/DeleteMulti", t, func() { |
| 547 c := info.Set(context.Background(), fakeInfo{}) | 547 c := info.Set(context.Background(), fakeInfo{}) |
| 548 c = SetRawFactory(c, fakeDatastoreFactory) | 548 c = SetRawFactory(c, fakeDatastoreFactory) |
| 549 ds := Get(c) | 549 ds := Get(c) |
| 550 So(ds, ShouldNotBeNil) | 550 So(ds, ShouldNotBeNil) |
| 551 | 551 |
| 552 Convey("bad", func() { | 552 Convey("bad", func() { |
| 553 Convey("get single error for RPC failure", func() { | 553 Convey("get single error for RPC failure", func() { |
| 554 keys := []Key{ | 554 keys := []Key{ |
| 555 » » » » » mkKey("aid", "ns", "FailAll", 1, nil), | 555 » » » » » mkKey("s~aid", "ns", "FailAll", 1, nil), |
| 556 » » » » » mkKey("aid", "ns", "Ok", 1, nil), | 556 » » » » » mkKey("s~aid", "ns", "Ok", 1, nil), |
| 557 } | 557 } |
| 558 So(ds.DeleteMulti(keys).Error(), ShouldEqual, "D
eleteMulti fail all") | 558 So(ds.DeleteMulti(keys).Error(), ShouldEqual, "D
eleteMulti fail all") |
| 559 }) | 559 }) |
| 560 | 560 |
| 561 Convey("get multi error for individual failure", func()
{ | 561 Convey("get multi error for individual failure", func()
{ |
| 562 keys := []Key{ | 562 keys := []Key{ |
| 563 ds.NewKey("Ok", "", 1, nil), | 563 ds.NewKey("Ok", "", 1, nil), |
| 564 ds.NewKey("Fail", "", 2, nil), | 564 ds.NewKey("Fail", "", 2, nil), |
| 565 } | 565 } |
| 566 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 Loading... |
| 894 So(ds.Run(q, func(k Key, _ CursorCB) bool { | 894 So(ds.Run(q, func(k Key, _ CursorCB) bool { |
| 895 So(k.IntID(), ShouldEqual, i+1) | 895 So(k.IntID(), ShouldEqual, i+1) |
| 896 i++ | 896 i++ |
| 897 return true | 897 return true |
| 898 }), ShouldBeNil) | 898 }), ShouldBeNil) |
| 899 }) | 899 }) |
| 900 | 900 |
| 901 }) | 901 }) |
| 902 }) | 902 }) |
| 903 } | 903 } |
| OLD | NEW |