Chromium Code Reviews| 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/datastore" |
| 14 "github.com/luci/gae/service/info" | 14 "github.com/luci/gae/service/info" |
| 15 "github.com/luci/gae/service/memcache" | 15 "github.com/luci/gae/service/memcache" |
| 16 "github.com/luci/gae/service/taskqueue" | 16 "github.com/luci/gae/service/taskqueue" |
| 17 "github.com/luci/gae/service/user" | |
| 17 "golang.org/x/net/context" | 18 "golang.org/x/net/context" |
| 18 ) | 19 ) |
| 19 | 20 |
| 20 const niFmtStr = "dummy: method %s.%s is not implemented" | 21 const niFmtStr = "dummy: method %s.%s is not implemented" |
| 21 | 22 |
| 22 // ni returns an error whose message is an appropriate expansion of niFmtStr. | 23 // ni returns an error whose message is an appropriate expansion of niFmtStr. |
| 23 // | 24 // |
| 24 // It walks the stack to find out what interface and method it's being | 25 // 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: | 26 // called from. For example, it might return a message which looks like: |
| 26 // dummy: method Datastore.Get is not implemented | 27 // dummy: method Datastore.Get is not implemented |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 38 | 39 |
| 39 if ptr, _, _, ok := runtime.Caller(1); ok { | 40 if ptr, _, _, ok := runtime.Caller(1); ok { |
| 40 f := runtime.FuncForPC(ptr) | 41 f := runtime.FuncForPC(ptr) |
| 41 n := f.Name() | 42 n := f.Name() |
| 42 if n != "" { | 43 if n != "" { |
| 43 parts := strings.Split(n, ".") | 44 parts := strings.Split(n, ".") |
| 44 if len(parts) > 2 { | 45 if len(parts) > 2 { |
| 45 switch parts[len(parts)-2] { | 46 switch parts[len(parts)-2] { |
| 46 case "ds": | 47 case "ds": |
| 47 iface = "Datastore" | 48 iface = "Datastore" |
| 49 case "i": | |
| 50 iface = "Info" | |
| 48 case "mc": | 51 case "mc": |
| 49 iface = "Memcache" | 52 iface = "Memcache" |
| 50 case "tq": | 53 case "tq": |
| 51 iface = "TaskQueue" | 54 iface = "TaskQueue" |
| 52 » » » » case "i": | 55 » » » » case "u": |
| 53 » » » » » iface = "Info" | 56 » » » » » iface = "User" |
| 54 } | 57 } |
| 55 funcName = parts[len(parts)-1] | 58 funcName = parts[len(parts)-1] |
| 56 } | 59 } |
| 57 } | 60 } |
| 58 } | 61 } |
| 59 | 62 |
| 60 return fmt.Errorf(niFmtStr, iface, funcName) | 63 return fmt.Errorf(niFmtStr, iface, funcName) |
| 61 } | 64 } |
| 62 | 65 |
| 63 /////////////////////////////////// ds //////////////////////////////////// | 66 /////////////////////////////////// ds //////////////////////////////////// |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 func (i) IsCapabilityDisabled(err error) bool { panic(ni()) } | 155 func (i) IsCapabilityDisabled(err error) bool { panic(ni()) } |
| 153 func (i) IsOverQuota(err error) bool { panic(ni()) } | 156 func (i) IsOverQuota(err error) bool { panic(ni()) } |
| 154 func (i) IsTimeoutError(err error) bool { panic(ni()) } | 157 func (i) IsTimeoutError(err error) bool { panic(ni()) } |
| 155 | 158 |
| 156 var dummyInfoInst = i{} | 159 var dummyInfoInst = i{} |
| 157 | 160 |
| 158 // Info returns a dummy info.Interface implementation suitable for embedding. | 161 // Info returns a dummy info.Interface implementation suitable for embedding. |
| 159 // Every method panics with a message containing the name of the method which | 162 // Every method panics with a message containing the name of the method which |
| 160 // was unimplemented. | 163 // was unimplemented. |
| 161 func Info() info.Interface { return dummyInfoInst } | 164 func Info() info.Interface { return dummyInfoInst } |
| 165 | |
| 166 ////////////////////////////////////// u /////////////////////////////////////// | |
| 167 | |
| 168 type u struct{} | |
| 169 | |
| 170 func (u) Current() *user.User { panic(ni()) } | |
| 171 func (u) CurrentOAuth() (*user.User, error) { panic(ni()) } | |
| 172 func (u) IsAdmin() bool { panic(ni()) } | |
| 173 func (u) LoginURL(string) (string, error) { panic(ni()) } | |
| 174 func (u) LoginURLFederated(string, string) (string, error) { panic(ni()) } | |
| 175 func (u) LogoutURL(string) (string, error) { panic(ni()) } | |
| 176 func (u) OAuthConsumerKey() (string, error) { panic(ni()) } | |
| 177 | |
| 178 var dummyUserInst = u{} | |
| 179 | |
| 180 // User returns a dummy user.Interface implementation suitable for embedding. | |
| 181 // Every methog panics with a message containing the name of the method which | |
|
Vadim Sh.
2015/12/03 00:55:56
typo: methog
iannucci
2015/12/03 01:00:24
hehe :)
| |
| 182 // was unimplemented. | |
| 183 func User() user.Interface { return dummyUserInst } | |
| OLD | NEW |