Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: dummy/dummy.go

Issue 1243323002: Refactor a bit. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix golint Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « dummy/doc.go ('k') | dummy/dummy_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 dummy
6
7 import (
8 "fmt"
9 "runtime"
10 "strings"
11 "time"
12
13 "github.com/luci/gae"
14 "golang.org/x/net/context"
15 )
16
17 const niFmtStr = "dummy: method %s.%s is not implemented"
18
19 // ni returns an error whose message is an appropriate expansion of niFmtStr.
20 //
21 // It walks the stack to find out what interface and method it's being
22 // called from. For example, it might return a message which looks like:
23 // dummy: method RawDatastore.Get is not implemented
24 //
25 // This allows the various dummy objects below to have clear boilerplate which
26 // avoids copy+paste errors (such as if each one of them filled in the template
27 // manually).
28 //
29 // If this function is somehow called from something other than one of the dummy
30 // objects in this package, it will substitute the string UNKNOWN for the
31 // interface and/or the method in the niFmtStr template.
32 func ni() error {
33 iface := "UNKNOWN"
34 funcName := "UNKNOWN"
35
36 if ptr, _, _, ok := runtime.Caller(1); ok {
37 f := runtime.FuncForPC(ptr)
38 n := f.Name()
39 if n != "" {
40 parts := strings.Split(n, ".")
41 if len(parts) > 2 {
42 switch parts[len(parts)-2] {
43 case "rds":
44 iface = "RawDatastore"
45 case "mc":
46 iface = "Memcache"
47 case "tq":
48 iface = "TaskQueue"
49 case "gi":
50 iface = "GlobalInfo"
51 case "qy":
52 iface = "DSQuery"
53 }
54 funcName = parts[len(parts)-1]
55 }
56 }
57 }
58
59 return fmt.Errorf(niFmtStr, iface, funcName)
60 }
61
62 /////////////////////////////////// rds ////////////////////////////////////
63
64 type rds struct{}
65
66 func (rds) NewKey(string, string, int64, gae.DSKey) gae.DSKey { panic(ni()) }
67 func (rds) DecodeKey(string) (gae.DSKey, error) { panic(ni()) }
68 func (rds) KeyFromTokens(a, n string, t []gae.DSKeyTok) (gae.DSKey, error) { panic(ni()) }
69 func (rds) Put(gae.DSKey, gae.DSPropertyLoadSaver) (gae.DSKey, error) { panic(ni()) }
70 func (rds) Get(gae.DSKey, gae.DSPropertyLoadSaver) error { panic(ni()) }
71 func (rds) Delete(gae.DSKey) error { panic(ni()) }
72 func (rds) PutMulti([]gae.DSKey, []gae.DSPropertyLoadSaver) ([]gae.DSKey, error) { panic(ni()) }
73 func (rds) GetMulti([]gae.DSKey, []gae.DSPropertyLoadSaver) error { panic(ni()) }
74 func (rds) DeleteMulti([]gae.DSKey) error { panic(ni()) }
75 func (rds) NewQuery(string) gae.DSQuery { panic(ni()) }
76 func (rds) Run(gae.DSQuery) gae.RDSIterator { panic(ni()) }
77 func (rds) GetAll(gae.DSQuery, *[]gae.DSPropertyMap) ([]gae.DSKey, error) { panic(ni()) }
78 func (rds) Count(gae.DSQuery) (int, error) { panic(ni()) }
79 func (rds) RunInTransaction(func(context.Context) error, *gae.DSTransactionOptio ns) error {
80 panic(ni())
81 }
82
83 var dummyRDSInst = rds{}
84
85 // RDS returns a dummy RawDatastore implementation suitable for embedding.
86 // Every method panics with a message containing the name of the method which
87 // was unimplemented.
88 func RDS() gae.RawDatastore { return dummyRDSInst }
89
90 /////////////////////////////////// mc ////////////////////////////////////
91
92 type mc struct{}
93
94 func (mc) Add(gae.MCItem) error { panic(ni()) }
95 func (mc) NewItem(key string) gae.MCItem { panic(ni()) }
96 func (mc) Set(gae.MCItem) error { panic(ni()) }
97 func (mc) Get(string) (gae.MCItem, error) { panic(ni()) }
98 func (mc) Delete(string) error { panic(ni()) }
99 func (mc) CompareAndSwap(gae.MCItem) error { panic(ni()) }
100 func (mc) AddMulti([]gae.MCItem) error { panic(ni()) }
101 func (mc) SetMulti([]gae.MCItem) error { panic(ni()) }
102 func (mc) GetMulti([]string) (map[string]gae.MCItem, error) { panic(ni()) }
103 func (mc) DeleteMulti([]string) error { panic(ni()) }
104 func (mc) CompareAndSwapMulti([]gae.MCItem) error { panic(ni()) }
105 func (mc) Increment(string, int64, uint64) (uint64, error) { panic(ni()) }
106 func (mc) IncrementExisting(string, int64) (uint64, error) { panic(ni()) }
107 func (mc) Flush() error { panic(ni()) }
108 func (mc) Stats() (*gae.MCStatistics, error) { panic(ni()) }
109
110 var dummyMCInst = mc{}
111
112 // MC returns a dummy Memcache implementation suitable for embedding.
113 // Every method panics with a message containing the name of the method which
114 // was unimplemented.
115 func MC() gae.Memcache { return dummyMCInst }
116
117 /////////////////////////////////// tq ////////////////////////////////////
118
119 type tq struct{}
120
121 func (tq) Add(*gae.TQTask, string) (*gae.TQTask, error) { panic(ni ()) }
122 func (tq) Delete(*gae.TQTask, string) error { panic(ni ()) }
123 func (tq) AddMulti([]*gae.TQTask, string) ([]*gae.TQTask, error) { panic(ni ()) }
124 func (tq) DeleteMulti([]*gae.TQTask, string) error { panic(ni ()) }
125 func (tq) Lease(int, string, int) ([]*gae.TQTask, error) { panic(ni ()) }
126 func (tq) LeaseByTag(int, string, int, string) ([]*gae.TQTask, error) { panic(ni ()) }
127 func (tq) ModifyLease(*gae.TQTask, string, int) error { panic(ni ()) }
128 func (tq) Purge(string) error { panic(ni ()) }
129 func (tq) QueueStats([]string) ([]gae.TQStatistics, error) { panic(ni ()) }
130
131 var dummyTQInst = tq{}
132
133 // TQ returns a dummy TaskQueue implementation suitable for embedding.
134 // Every method panics with a message containing the name of the method which
135 // was unimplemented.
136 func TQ() gae.TaskQueue { return dummyTQInst }
137
138 /////////////////////////////////// qy ////////////////////////////////////
139
140 type qy struct{}
141
142 func (qy) Ancestor(ancestor gae.DSKey) gae.DSQuery { panic(ni()) }
143 func (qy) Distinct() gae.DSQuery { panic(ni()) }
144 func (qy) End(c gae.DSCursor) gae.DSQuery { panic(ni()) }
145 func (qy) EventualConsistency() gae.DSQuery { panic(ni()) }
146 func (qy) Filter(filterStr string, value interface{}) gae.DSQuery { panic(ni()) }
147 func (qy) KeysOnly() gae.DSQuery { panic(ni()) }
148 func (qy) Limit(limit int) gae.DSQuery { panic(ni()) }
149 func (qy) Offset(offset int) gae.DSQuery { panic(ni()) }
150 func (qy) Order(fieldName string) gae.DSQuery { panic(ni()) }
151 func (qy) Project(fieldNames ...string) gae.DSQuery { panic(ni()) }
152 func (qy) Start(c gae.DSCursor) gae.DSQuery { panic(ni()) }
153
154 var dummyQYInst = qy{}
155
156 // QY returns a dummy gae.DSQuery implementation suitable for embedding.
157 // Every method panics with a message containing the name of the method which
158 // was unimplemented.
159 func QY() gae.DSQuery { return dummyQYInst }
160
161 /////////////////////////////////// gi ////////////////////////////////////
162
163 type gi struct{}
164
165 func (gi) AccessToken(scopes ...string) (token string, expiry time.Time, err err or) { panic(ni()) }
166 func (gi) AppID() string { panic(ni()) }
167 func (gi) ModuleHostname(module, version, instance string) (string, error) { panic(ni()) }
168 func (gi) ModuleName() string { panic(ni()) }
169 func (gi) DefaultVersionHostname() string { panic(ni()) }
170 func (gi) PublicCertificates() ([]gae.GICertificate, error) { panic(ni()) }
171 func (gi) RequestID() string { panic(ni()) }
172 func (gi) ServiceAccount() (string, error) { panic(ni()) }
173 func (gi) SignBytes(bytes []byte) (keyName string, signature []byte, err error) { panic(ni()) }
174 func (gi) VersionID() string { panic(ni()) }
175 func (gi) Namespace(namespace string) (context.Context, error) { panic(ni()) }
176 func (gi) Datacenter() string { panic(ni()) }
177 func (gi) InstanceID() string { panic(ni()) }
178 func (gi) IsDevAppServer() bool { panic(ni()) }
179 func (gi) ServerSoftware() string { panic(ni()) }
180 func (gi) IsCapabilityDisabled(err error) bool { panic(ni()) }
181 func (gi) IsOverQuota(err error) bool { panic(ni()) }
182 func (gi) IsTimeoutError(err error) bool { panic(ni()) }
183
184 var dummyGIInst = gi{}
185
186 // GI returns a dummy GlobalInfo implementation suitable for embedding.
187 // Every method panics with a message containing the name of the method which
188 // was unimplemented.
189 func GI() gae.GlobalInfo { return dummyGIInst }
OLDNEW
« no previous file with comments | « dummy/doc.go ('k') | dummy/dummy_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698