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

Unified Diff: impl/memory/info.go

Issue 1871943003: Add Info Testable interface, implement for memory. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Fall through in filter. Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « impl/memory/context.go ('k') | impl/memory/info_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/info.go
diff --git a/impl/memory/info.go b/impl/memory/info.go
index 6d28d5ab45478255432528ab560d1442b1c8b766..432f70195ee82efab6f464cde55b466392c049af 100644
--- a/impl/memory/info.go
+++ b/impl/memory/info.go
@@ -20,23 +20,46 @@ var giContextKey giContextKeyType
// validNamespace matches valid namespace names.
var validNamespace = regexp.MustCompile(`^[0-9A-Za-z._-]{0,100}$`)
+var defaultGlobalInfoData = globalInfoData{
+ // versionID returns X.Y where Y is autogenerated by appengine, and X is
+ // whatever's in app.yaml.
+ versionID: "testVersionID.1",
+ requestID: "test-request-id",
+}
+
+type globalInfoData struct {
+ appid string
+ namespace string
+ versionID string
+ requestID string
+}
+
func curGID(c context.Context) *globalInfoData {
- return c.Value(giContextKey).(*globalInfoData)
+ if gid, ok := c.Value(giContextKey).(*globalInfoData); ok {
+ return gid
+ }
+ return &defaultGlobalInfoData
+}
+
+func useGID(c context.Context, f func(mod *globalInfoData)) context.Context {
+ cur := curGID(c)
+ if cur == nil {
+ cur = &defaultGlobalInfoData
+ }
+
+ clone := *cur
+ f(&clone)
+ return context.WithValue(c, giContextKey, &clone)
}
// useGI adds a gae.GlobalInfo context, accessible
// by gae.GetGI(c)
-func useGI(c context.Context, appID string) context.Context {
+func useGI(c context.Context) context.Context {
return info.SetFactory(c, func(ic context.Context) info.Interface {
return &giImpl{dummy.Info(), curGID(ic), ic}
})
}
-type globalInfoData struct {
- appid string
- namespace string
-}
-
type giImpl struct {
info.Interface
*globalInfoData
@@ -53,7 +76,10 @@ func (gi *giImpl) Namespace(ns string) (ret context.Context, err error) {
if !validNamespace.MatchString(ns) {
return nil, fmt.Errorf("appengine: namespace %q does not match /%s/", ns, validNamespace)
}
- return context.WithValue(gi.c, giContextKey, &globalInfoData{gi.appid, ns}), nil
+
+ return useGID(gi.c, func(mod *globalInfoData) {
+ mod.namespace = ns
+ }), nil
}
func (gi *giImpl) MustNamespace(ns string) context.Context {
@@ -77,7 +103,25 @@ func (gi *giImpl) IsDevAppServer() bool {
}
func (gi *giImpl) VersionID() string {
- // VersionID returns X.Y where Y is autogenerated by appengine, and X is
- // whatever's in app.yaml.
- return "testVersionID.1"
+ return curGID(gi.c).versionID
+}
+
+func (gi *giImpl) RequestID() string {
+ return curGID(gi.c).requestID
+}
+
+func (gi *giImpl) Testable() info.Testable {
+ return gi
+}
+
+func (gi *giImpl) SetVersionID(v string) context.Context {
+ return useGID(gi.c, func(mod *globalInfoData) {
+ mod.versionID = v
+ })
+}
+
+func (gi *giImpl) SetRequestID(v string) context.Context {
+ return useGID(gi.c, func(mod *globalInfoData) {
+ mod.requestID = v
+ })
}
« no previous file with comments | « impl/memory/context.go ('k') | impl/memory/info_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698