test: clears the namespace roots in tests
Currently, any test that doesn't create its own mounttable 'inherits'
the default namespace root,
"/(dev.v.io:role:vprod:service:mounttabled)@ns.dev.v.io:8101". We don't
want this kind of dependency in tests, both to isolate tests and to
prevent undue load on the prod mounttable.
This change clears the namespace roots when using V23Init to create a
context.
This 'cleanup' is part of a larger effort to get all the tests to use
some sort of test context.
Change-Id: I5ab4e1edcfaa83e19ab6b5cf93061ab21195a289
diff --git a/runtime/internal/testing/mocks/naming/namespace.go b/runtime/internal/testing/mocks/naming/namespace.go
index a15e6d3..3032fde 100644
--- a/runtime/internal/testing/mocks/naming/namespace.go
+++ b/runtime/internal/testing/mocks/naming/namespace.go
@@ -161,9 +161,12 @@
panic("Glob not implemented")
}
-func (ns *namespaceMock) SetRoots(...string) error {
+func (ns *namespaceMock) SetRoots(args ...string) error {
defer apilog.LogCall(nil)(nil) // gologcop: DO NOT EDIT, MUST BE FIRST STATEMENT
- panic("Calling SetRoots on a mock namespace. This is not supported.")
+ if len(args) > 0 {
+ panic("Calling SetRoots with arguments on a mock namespace. This is not supported.")
+ }
+ return nil
}
func (ns *namespaceMock) Roots() []string {
diff --git a/test/init.go b/test/init.go
index 427cfda..e18b014 100644
--- a/test/init.go
+++ b/test/init.go
@@ -23,6 +23,12 @@
" and hang so you can look at it. This only works when running a single test,"+
" because you have to ctrl-c to finish the test.")
+// TODO(caprita): Instead of V23Init, should we have a test runtime factory? The
+// problem with V23Init is that it creates a context using v23.Init, and then we
+// edit the context to configure things like the listen spec, namespace, and
+// principal. Would be better to set these things correctly for the test to
+// begin with.
+
// V23Init initializes the runtime and sets up the principal with a self-signed
// TestBlessing. The blessing setup step is skipped if this function is invoked
// from a v23test.Shell child process, since v23test.Shell passes credentials to
diff --git a/test/init_common.go b/test/init_common.go
index b487d27..da27cc0 100644
--- a/test/init_common.go
+++ b/test/init_common.go
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// TODO(caprita): Merge this with init.go now that v.io/c/20864 got rid of
+// init_mojo.go.
+
package test
import (
@@ -51,16 +54,23 @@
ns := v23.GetNamespace(ctx)
ns.CacheCtl(naming.DisableCache(true))
- if !v23testProcess && createMounttable {
- disp, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
- if err != nil {
- panic(err)
+ // TODO(caprita): Whether this is a Shell child process is but an
+ // approximation as to whether we should or should not edit the
+ // namespace in the context. See also TODO on V23Init.
+ if !v23testProcess {
+ if createMounttable {
+ disp, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
+ if err != nil {
+ panic(err)
+ }
+ _, s, err := v23.WithNewDispatchingServer(ctx, "", disp, options.ServesMountTable(true))
+ if err != nil {
+ panic(err)
+ }
+ ns.SetRoots(s.Status().Endpoints[0].Name())
+ } else {
+ ns.SetRoots()
}
- _, s, err := v23.WithNewDispatchingServer(ctx, "", disp, options.ServesMountTable(true))
- if err != nil {
- panic(err)
- }
- ns.SetRoots(s.Status().Endpoints[0].Name())
}
return ctx