| 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 package dummy | 5 package dummy |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "runtime" | 9 "runtime" |
| 10 "strings" | 10 "strings" |
| 11 "time" | 11 "time" |
| 12 | 12 |
| 13 "github.com/luci/gae/service/datastore" |
| 13 "github.com/luci/gae/service/info" | 14 "github.com/luci/gae/service/info" |
| 14 "github.com/luci/gae/service/memcache" | 15 "github.com/luci/gae/service/memcache" |
| 15 "github.com/luci/gae/service/rawdatastore" | |
| 16 "github.com/luci/gae/service/taskqueue" | 16 "github.com/luci/gae/service/taskqueue" |
| 17 "golang.org/x/net/context" | 17 "golang.org/x/net/context" |
| 18 ) | 18 ) |
| 19 | 19 |
| 20 const niFmtStr = "dummy: method %s.%s is not implemented" | 20 const niFmtStr = "dummy: method %s.%s is not implemented" |
| 21 | 21 |
| 22 // ni returns an error whose message is an appropriate expansion of niFmtStr. | 22 // ni returns an error whose message is an appropriate expansion of niFmtStr. |
| 23 // | 23 // |
| 24 // It walks the stack to find out what interface and method it's being | 24 // It walks the stack to find out what interface and method it's being |
| 25 // called from. For example, it might return a message which looks like: | 25 // called from. For example, it might return a message which looks like: |
| 26 // dummy: method RawDatastore.Get is not implemented | 26 // dummy: method Datastore.Get is not implemented |
| 27 // | 27 // |
| 28 // This allows the various dummy objects below to have clear boilerplate which | 28 // This allows the various dummy objects below to have clear boilerplate which |
| 29 // avoids copy+paste errors (such as if each one of them filled in the template | 29 // avoids copy+paste errors (such as if each one of them filled in the template |
| 30 // manually). | 30 // manually). |
| 31 // | 31 // |
| 32 // If this function is somehow called from something other than one of the dummy | 32 // If this function is somehow called from something other than one of the dummy |
| 33 // objects in this package, it will substitute the string UNKNOWN for the | 33 // objects in this package, it will substitute the string UNKNOWN for the |
| 34 // interface and/or the method in the niFmtStr template. | 34 // interface and/or the method in the niFmtStr template. |
| 35 func ni() error { | 35 func ni() error { |
| 36 iface := "UNKNOWN" | 36 iface := "UNKNOWN" |
| 37 funcName := "UNKNOWN" | 37 funcName := "UNKNOWN" |
| 38 | 38 |
| 39 if ptr, _, _, ok := runtime.Caller(1); ok { | 39 if ptr, _, _, ok := runtime.Caller(1); ok { |
| 40 f := runtime.FuncForPC(ptr) | 40 f := runtime.FuncForPC(ptr) |
| 41 n := f.Name() | 41 n := f.Name() |
| 42 if n != "" { | 42 if n != "" { |
| 43 parts := strings.Split(n, ".") | 43 parts := strings.Split(n, ".") |
| 44 if len(parts) > 2 { | 44 if len(parts) > 2 { |
| 45 switch parts[len(parts)-2] { | 45 switch parts[len(parts)-2] { |
| 46 » » » » case "rds": | 46 » » » » case "ds": |
| 47 » » » » » iface = "RawDatastore" | 47 » » » » » iface = "Datastore" |
| 48 case "mc": | 48 case "mc": |
| 49 iface = "Memcache" | 49 iface = "Memcache" |
| 50 case "tq": | 50 case "tq": |
| 51 iface = "TaskQueue" | 51 iface = "TaskQueue" |
| 52 case "i": | 52 case "i": |
| 53 iface = "Info" | 53 iface = "Info" |
| 54 } | 54 } |
| 55 funcName = parts[len(parts)-1] | 55 funcName = parts[len(parts)-1] |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 return fmt.Errorf(niFmtStr, iface, funcName) | 60 return fmt.Errorf(niFmtStr, iface, funcName) |
| 61 } | 61 } |
| 62 | 62 |
| 63 /////////////////////////////////// rds //////////////////////////////////// | 63 /////////////////////////////////// ds //////////////////////////////////// |
| 64 | 64 |
| 65 type rds struct{} | 65 type ds struct{} |
| 66 | 66 |
| 67 func (rds) NewKey(kind string, sid string, iid int64, par rawdatastore.Key) rawd
atastore.Key { | 67 func (ds) NewKey(kind string, sid string, iid int64, par datastore.Key) datastor
e.Key { |
| 68 » return rawdatastore.NewKey("dummy~appid", "", kind, sid, iid, par) | 68 » return datastore.NewKey("dummy~appid", "", kind, sid, iid, par) |
| 69 } | 69 } |
| 70 func (rds) DecodeKey(string) (rawdatastore.Key, error) { panic(ni()) } | 70 func (ds) DecodeKey(string) (datastore.Key, error) { panic(ni()) } |
| 71 func (rds) PutMulti([]rawdatastore.Key, []rawdatastore.PropertyLoadSaver, rawdat
astore.PutMultiCB) error { | 71 func (ds) PutMulti([]datastore.Key, []datastore.PropertyLoadSaver, datastore.Put
MultiCB) error { |
| 72 panic(ni()) | 72 panic(ni()) |
| 73 } | 73 } |
| 74 func (rds) GetMulti([]rawdatastore.Key, rawdatastore.GetMultiCB) error { p
anic(ni()) } | 74 func (ds) GetMulti([]datastore.Key, datastore.GetMultiCB) error { panic(ni
()) } |
| 75 func (rds) DeleteMulti([]rawdatastore.Key, rawdatastore.DeleteMultiCB) error { p
anic(ni()) } | 75 func (ds) DeleteMulti([]datastore.Key, datastore.DeleteMultiCB) error { panic(ni
()) } |
| 76 func (rds) NewQuery(string) rawdatastore.Query { p
anic(ni()) } | 76 func (ds) NewQuery(string) datastore.Query { panic(ni
()) } |
| 77 func (rds) Run(rawdatastore.Query, rawdatastore.RunCB) error { p
anic(ni()) } | 77 func (ds) Run(datastore.Query, datastore.RunCB) error { panic(ni
()) } |
| 78 func (rds) RunInTransaction(func(context.Context) error, *rawdatastore.Transacti
onOptions) error { | 78 func (ds) RunInTransaction(func(context.Context) error, *datastore.TransactionOp
tions) error { |
| 79 panic(ni()) | 79 panic(ni()) |
| 80 } | 80 } |
| 81 | 81 |
| 82 var dummyRDSInst = rds{} | 82 var dummyDSInst = ds{} |
| 83 | 83 |
| 84 // RawDatastore returns a dummy rawdatastore.Interface implementation suitable | 84 // Datastore returns a dummy datastore.Interface implementation suitable |
| 85 // for embedding. Every method panics with a message containing the name of the | 85 // for embedding. Every method panics with a message containing the name of the |
| 86 // method which was unimplemented. | 86 // method which was unimplemented. |
| 87 func RawDatastore() rawdatastore.Interface { return dummyRDSInst } | 87 func Datastore() datastore.Interface { return dummyDSInst } |
| 88 | 88 |
| 89 /////////////////////////////////// mc //////////////////////////////////// | 89 /////////////////////////////////// mc //////////////////////////////////// |
| 90 | 90 |
| 91 type mc struct{} | 91 type mc struct{} |
| 92 | 92 |
| 93 func (mc) Add(memcache.Item) error { panic(ni()) } | 93 func (mc) Add(memcache.Item) error { panic(ni()) } |
| 94 func (mc) NewItem(key string) memcache.Item { panic(ni()) } | 94 func (mc) NewItem(key string) memcache.Item { panic(ni()) } |
| 95 func (mc) Set(memcache.Item) error { panic(ni()) } | 95 func (mc) Set(memcache.Item) error { panic(ni()) } |
| 96 func (mc) Get(string) (memcache.Item, error) { panic(ni()) } | 96 func (mc) Get(string) (memcache.Item, error) { panic(ni()) } |
| 97 func (mc) Delete(string) error { panic(ni()) } | 97 func (mc) Delete(string) error { panic(ni()) } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 func (i) IsCapabilityDisabled(err error) bool
{ panic(ni()) } | 157 func (i) IsCapabilityDisabled(err error) bool
{ panic(ni()) } |
| 158 func (i) IsOverQuota(err error) bool
{ panic(ni()) } | 158 func (i) IsOverQuota(err error) bool
{ panic(ni()) } |
| 159 func (i) IsTimeoutError(err error) bool
{ panic(ni()) } | 159 func (i) IsTimeoutError(err error) bool
{ panic(ni()) } |
| 160 | 160 |
| 161 var dummyInfoInst = i{} | 161 var dummyInfoInst = i{} |
| 162 | 162 |
| 163 // Info returns a dummy info.Interface implementation suitable for embedding. | 163 // Info returns a dummy info.Interface implementation suitable for embedding. |
| 164 // Every method panics with a message containing the name of the method which | 164 // Every method panics with a message containing the name of the method which |
| 165 // was unimplemented. | 165 // was unimplemented. |
| 166 func Info() info.Interface { return dummyInfoInst } | 166 func Info() info.Interface { return dummyInfoInst } |
| OLD | NEW |