veyron2: Remove client from reserved functions.
The client is no longer necessary, since it is retrieved from the
context, and the user can simply set a new client in the context.
Also added SetClient to the runtime implementation, to allow
tests to supply a mock client in the context.
Change-Id: Id7114a2f9c694f753cde9fdd506e2522c6c698d2
MultiPart: 1/2
diff --git a/runtimes/google/ipc/signature_test.go b/runtimes/google/ipc/signature_test.go
index 0d3d0d1..1dea588 100644
--- a/runtimes/google/ipc/signature_test.go
+++ b/runtimes/google/ipc/signature_test.go
@@ -97,7 +97,7 @@
}},
}
for _, test := range tests {
- sig, err := reserved.MethodSignature(runtime.NewContext(), nil, name, test.Method)
+ sig, err := reserved.MethodSignature(runtime.NewContext(), name, test.Method)
if err != nil {
t.Errorf("call failed: %v", err)
}
@@ -120,7 +120,7 @@
}
defer stop()
name := naming.JoinAddressName(ep, "")
- sig, err := reserved.Signature(runtime.NewContext(), nil, name)
+ sig, err := reserved.Signature(runtime.NewContext(), name)
if err != nil {
t.Errorf("call failed: %v", err)
}
diff --git a/runtimes/google/rt/runtimex.go b/runtimes/google/rt/runtimex.go
index 8a2e4a0..426d0cf 100644
--- a/runtimes/google/rt/runtimex.go
+++ b/runtimes/google/rt/runtimex.go
@@ -53,7 +53,7 @@
ctx = context.WithValue(ctx, reservedNameKey,
&reservedNameDispatcher{rt.reservedDisp, rt.reservedOpts})
ctx = context.WithValue(ctx, streamManagerKey, rt.sm[0])
- ctx = context.WithValue(ctx, clientKey, rt.client)
+ ctx = SetClient(ctx, rt.client)
ctx = context.WithValue(ctx, namespaceKey, rt.ns)
ctx = context.WithValue(ctx, loggerKey, vlog.Log)
ctx = context.WithValue(ctx, principalKey, rt.principal)
@@ -208,7 +208,7 @@
client, err := iipc.InternalNewClient(sm, ns, otherOpts...)
if err == nil {
- ctx = context.WithValue(ctx, clientKey, client)
+ ctx = SetClient(ctx, client)
}
return ctx, client, err
}
@@ -218,6 +218,14 @@
return cl
}
+// SetClient attaches client to ctx and returns the resulting context.
+//
+// WARNING: This function is only exposed for tests; regular production code
+// should never call this function.
+func SetClient(ctx *context.T, client ipc.Client) *context.T {
+ return context.WithValue(ctx, clientKey, client)
+}
+
func (*RuntimeX) setNewNamespace(ctx *context.T, roots ...string) (*context.T, naming.Namespace, error) {
ns, err := namespace.New(roots...)
if err == nil {