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