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 wrapper | |
6 | |
7 import ( | |
8 "fmt" | |
9 "runtime" | |
10 "strings" | |
11 "time" | |
12 | |
13 "golang.org/x/net/context" | |
14 | |
15 "appengine" | |
16 "appengine/datastore" | |
17 "appengine/memcache" | |
18 "appengine/taskqueue" | |
19 | |
20 "github.com/mjibson/goon" | |
21 ) | |
22 | |
23 const niFmtStr = "wrapper: method %s.%s is not implemented" | |
24 | |
25 func ni() error { | |
26 iface := "UNKNOWN" | |
27 funcName := "UNKNOWN" | |
28 | |
29 if ptr, _, _, ok := runtime.Caller(1); ok { | |
30 f := runtime.FuncForPC(ptr) | |
31 n := f.Name() | |
32 if n != "" { | |
33 parts := strings.Split(n, ".") | |
34 if len(parts) == 3 { | |
35 switch parts[1][len(parts[1])-2:] { | |
36 case "DS": | |
37 iface = "Datastore" | |
38 case "MC": | |
39 iface = "Memcache" | |
40 case "TQ": | |
41 iface = "TaskQueue" | |
42 case "GI": | |
43 iface = "GlobalInformation" | |
44 case "QY": | |
45 iface = "Query" | |
46 } | |
47 funcName = parts[2] | |
48 } | |
49 } | |
50 } | |
51 | |
52 return fmt.Errorf(niFmtStr, iface, funcName) | |
53 } | |
54 | |
55 /////////////////////////////////// dummyDS //////////////////////////////////// | |
56 | |
57 type dummyDS struct{} | |
58 | |
59 func (dummyDS) Kind(interface{}) string { pa
nic(ni()) } | |
60 func (dummyDS) KindNameResolver() goon.KindNameResolver { pa
nic(ni()) } | |
61 func (dummyDS) SetKindNameResolver(goon.KindNameResolver) { pa
nic(ni()) } | |
62 func (dummyDS) NewKey(string, string, int64, *datastore.Key) *datastore.Key { pa
nic(ni()) } | |
63 func (dummyDS) NewKeyObj(interface{}) *datastore.Key { pa
nic(ni()) } | |
64 func (dummyDS) NewKeyObjError(interface{}) (*datastore.Key, error) { pa
nic(ni()) } | |
65 func (dummyDS) Put(interface{}) (*datastore.Key, error) { pa
nic(ni()) } | |
66 func (dummyDS) Get(interface{}) error { pa
nic(ni()) } | |
67 func (dummyDS) Delete(*datastore.Key) error { pa
nic(ni()) } | |
68 func (dummyDS) PutMulti(interface{}) ([]*datastore.Key, error) { pa
nic(ni()) } | |
69 func (dummyDS) GetMulti(interface{}) error { pa
nic(ni()) } | |
70 func (dummyDS) DeleteMulti([]*datastore.Key) error { pa
nic(ni()) } | |
71 func (dummyDS) NewQuery(string) DSQuery { pa
nic(ni()) } | |
72 func (dummyDS) Run(DSQuery) DSIterator { pa
nic(ni()) } | |
73 func (dummyDS) GetAll(DSQuery, interface{}) ([]*datastore.Key, error) { pa
nic(ni()) } | |
74 func (dummyDS) Count(DSQuery) (int, error) { pa
nic(ni()) } | |
75 func (dummyDS) RunInTransaction(func(context.Context) error, *datastore.Transact
ionOptions) error { | |
76 panic(ni()) | |
77 } | |
78 | |
79 var dummyDSInst = dummyDS{} | |
80 | |
81 // DummyDS returns a dummy Datastore implementation suitable for embedding. | |
82 // Every method panics with a message containing the name of the method which | |
83 // was unimplemented. | |
84 func DummyDS() Datastore { return dummyDSInst } | |
85 | |
86 /////////////////////////////////// dummyMC //////////////////////////////////// | |
87 | |
88 type dummyMC struct{} | |
89 | |
90 func (dummyMC) Add(*memcache.Item) error { panic(ni(
)) } | |
91 func (dummyMC) Set(*memcache.Item) error { panic(ni(
)) } | |
92 func (dummyMC) Get(string) (*memcache.Item, error) { panic(ni(
)) } | |
93 func (dummyMC) Delete(string) error { panic(ni(
)) } | |
94 func (dummyMC) CompareAndSwap(*memcache.Item) error { panic(ni(
)) } | |
95 func (dummyMC) AddMulti([]*memcache.Item) error { panic(ni(
)) } | |
96 func (dummyMC) SetMulti([]*memcache.Item) error { panic(ni(
)) } | |
97 func (dummyMC) GetMulti([]string) (map[string]*memcache.Item, error) { panic(ni(
)) } | |
98 func (dummyMC) DeleteMulti([]string) error { panic(ni(
)) } | |
99 func (dummyMC) CompareAndSwapMulti([]*memcache.Item) error { panic(ni(
)) } | |
100 func (dummyMC) Increment(string, int64, uint64) (uint64, error) { panic(ni(
)) } | |
101 func (dummyMC) IncrementExisting(string, int64) (uint64, error) { panic(ni(
)) } | |
102 func (dummyMC) Flush() error { panic(ni(
)) } | |
103 func (dummyMC) Stats() (*memcache.Statistics, error) { panic(ni(
)) } | |
104 func (dummyMC) InflateCodec(memcache.Codec) MCCodec { panic(ni(
)) } | |
105 | |
106 var dummyMCInst = dummyMC{} | |
107 | |
108 // DummyMC returns a dummy Memcache implementation suitable for embedding. | |
109 // Every method panics with a message containing the name of the method which | |
110 // was unimplemented. | |
111 func DummyMC() Memcache { return dummyMCInst } | |
112 | |
113 /////////////////////////////////// dummyTQ //////////////////////////////////// | |
114 | |
115 type dummyTQ struct{} | |
116 | |
117 func (dummyTQ) Add(*taskqueue.Task, string) (*taskqueue.Task, error) {
panic(ni()) } | |
118 func (dummyTQ) Delete(*taskqueue.Task, string) error {
panic(ni()) } | |
119 func (dummyTQ) AddMulti([]*taskqueue.Task, string) ([]*taskqueue.Task, error) {
panic(ni()) } | |
120 func (dummyTQ) DeleteMulti([]*taskqueue.Task, string) error {
panic(ni()) } | |
121 func (dummyTQ) Lease(int, string, int) ([]*taskqueue.Task, error) {
panic(ni()) } | |
122 func (dummyTQ) LeaseByTag(int, string, int, string) ([]*taskqueue.Task, error) {
panic(ni()) } | |
123 func (dummyTQ) ModifyLease(*taskqueue.Task, string, int) error {
panic(ni()) } | |
124 func (dummyTQ) Purge(string) error {
panic(ni()) } | |
125 func (dummyTQ) QueueStats([]string, int) ([]taskqueue.QueueStatistics, error) {
panic(ni()) } | |
126 | |
127 var dummyTQInst = dummyTQ{} | |
128 | |
129 // DummyTQ returns a dummy TaskQueue implementation suitable for embedding. | |
130 // Every method panics with a message containing the name of the method which | |
131 // was unimplemented. | |
132 func DummyTQ() TaskQueue { return dummyTQInst } | |
133 | |
134 /////////////////////////////////// dummyQY //////////////////////////////////// | |
135 | |
136 type dummyQY struct{} | |
137 | |
138 func (dummyQY) Ancestor(ancestor *datastore.Key) DSQuery { panic(ni())
} | |
139 func (dummyQY) Distinct() DSQuery { panic(ni())
} | |
140 func (dummyQY) End(c DSCursor) DSQuery { panic(ni())
} | |
141 func (dummyQY) EventualConsistency() DSQuery { panic(ni())
} | |
142 func (dummyQY) Filter(filterStr string, value interface{}) DSQuery { panic(ni())
} | |
143 func (dummyQY) KeysOnly() DSQuery { panic(ni())
} | |
144 func (dummyQY) Limit(limit int) DSQuery { panic(ni())
} | |
145 func (dummyQY) Offset(offset int) DSQuery { panic(ni())
} | |
146 func (dummyQY) Order(fieldName string) DSQuery { panic(ni())
} | |
147 func (dummyQY) Project(fieldNames ...string) DSQuery { panic(ni())
} | |
148 func (dummyQY) Start(c DSCursor) DSQuery { panic(ni())
} | |
149 | |
150 var dummyQYInst = dummyQY{} | |
151 | |
152 // DummyQY returns a dummy DSQuery implementation suitable for embedding. | |
153 // Every method panics with a message containing the name of the method which | |
154 // was unimplemented. | |
155 func DummyQY() DSQuery { return dummyQYInst } | |
156 | |
157 /////////////////////////////////// dummyGI //////////////////////////////////// | |
158 | |
159 type dummyGI struct{} | |
160 | |
161 func (dummyGI) AccessToken(scopes ...string) (token string, expiry time.Time, er
r error) { panic(ni()) } | |
162 func (dummyGI) AppID() string
{ panic(ni()) } | |
163 func (dummyGI) ModuleHostname(module, version, instance string) (string, error)
{ panic(ni()) } | |
164 func (dummyGI) ModuleName() string
{ panic(ni()) } | |
165 func (dummyGI) DefaultVersionHostname() string
{ panic(ni()) } | |
166 func (dummyGI) PublicCertificates() ([]appengine.Certificate, error)
{ panic(ni()) } | |
167 func (dummyGI) RequestID() string
{ panic(ni()) } | |
168 func (dummyGI) ServiceAccount() (string, error)
{ panic(ni()) } | |
169 func (dummyGI) SignBytes(bytes []byte) (keyName string, signature []byte, err er
ror) { panic(ni()) } | |
170 func (dummyGI) VersionID() string
{ panic(ni()) } | |
171 func (dummyGI) Namespace(namespace string) (context.Context, error)
{ panic(ni()) } | |
172 func (dummyGI) Datacenter() string
{ panic(ni()) } | |
173 func (dummyGI) InstanceID() string
{ panic(ni()) } | |
174 func (dummyGI) IsDevAppserver() bool
{ panic(ni()) } | |
175 func (dummyGI) ServerSoftware() string
{ panic(ni()) } | |
176 func (dummyGI) IsCapabilityDisabled(err error) bool
{ panic(ni()) } | |
177 func (dummyGI) IsOverQuota(err error) bool
{ panic(ni()) } | |
178 func (dummyGI) IsTimeoutError(err error) bool
{ panic(ni()) } | |
179 | |
180 var dummyGIInst = dummyGI{} | |
181 | |
182 // DummyGI returns a dummy GlobalInfo implementation suitable for embedding. | |
183 // Every method panics with a message containing the name of the method which | |
184 // was unimplemented. | |
185 func DummyGI() GlobalInfo { return dummyGIInst } | |
OLD | NEW |