"core/veyron/tools": Test must run under agent
This Part 2 of a series of changes to make go tests self-contained
and in particular run under an agent.
See: https://vanadium-review.googlesource.com/#/c/1931/
Change-Id: I956a15d7612e16d369c5b4882fa413c7c62aed04
diff --git a/tools/application/impl_test.go b/tools/application/impl_test.go
index 32481ca..4917d7d 100644
--- a/tools/application/impl_test.go
+++ b/tools/application/impl_test.go
@@ -11,12 +11,14 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
+ "v.io/core/veyron2/options"
"v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/mgmt/application"
"v.io/core/veyron2/services/security/access"
"v.io/core/veyron2/vlog"
+ tsecurity "v.io/core/veyron/lib/testutil/security"
"v.io/core/veyron/profiles"
"v.io/core/veyron/services/mgmt/repository"
)
@@ -117,7 +119,10 @@
func TestApplicationClient(t *testing.T) {
var err error
- runtime, err = rt.New()
+ // TODO(ataly, mattr, suharshs): This is a HACK to ensure that the server and the
+ // client have the same freshly created principal. One way to avoid the RuntimePrincipal
+ // option is to have a global client context.T (in main.go) instead of a veyron2.Runtime.
+ runtime, err = rt.New(options.RuntimePrincipal{tsecurity.NewPrincipal("test-blessing")})
if err != nil {
t.Fatalf("Unexpected error initializing runtime: %s", err)
}
diff --git a/tools/binary/impl_test.go b/tools/binary/impl_test.go
index 8d19bbd..d0f7ca6 100644
--- a/tools/binary/impl_test.go
+++ b/tools/binary/impl_test.go
@@ -22,6 +22,7 @@
"v.io/core/veyron2/services/security/access"
"v.io/core/veyron2/vlog"
+ tsecurity "v.io/core/veyron/lib/testutil/security"
"v.io/core/veyron/profiles"
)
@@ -126,6 +127,9 @@
}
defer runtime.Cleanup()
gctx = runtime.NewContext()
+ if gctx, err = veyron2.SetPrincipal(gctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+ panic(err)
+ }
server, endpoint, err := startServer(t, gctx)
if err != nil {
diff --git a/tools/build/impl_test.go b/tools/build/impl_test.go
index 8dd4045..83e085c 100644
--- a/tools/build/impl_test.go
+++ b/tools/build/impl_test.go
@@ -9,12 +9,14 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
+ "v.io/core/veyron2/options"
"v.io/core/veyron2/rt"
"v.io/core/veyron2/services/mgmt/binary"
"v.io/core/veyron2/services/mgmt/build"
verror "v.io/core/veyron2/verror2"
"v.io/core/veyron2/vlog"
+ tsecurity "v.io/core/veyron/lib/testutil/security"
"v.io/core/veyron/profiles"
)
@@ -63,7 +65,10 @@
func TestBuildClient(t *testing.T) {
var err error
- runtime, err = rt.New()
+ // TODO(ataly, mattr, suharshs): This is a HACK to ensure that the server and the
+ // client have the same freshly created principal. One way to avoid the RuntimePrincipal
+ // option is to have a global client context.T (in main.go) instead of a veyron2.Runtime.
+ runtime, err = rt.New(options.RuntimePrincipal{tsecurity.NewPrincipal("test-blessing")})
if err != nil {
t.Fatalf("Unexpected error initializing runtime: %s", err)
}
diff --git a/tools/mgmt/device/impl_test.go b/tools/mgmt/device/impl_test.go
index a72c411..1e38b25 100644
--- a/tools/mgmt/device/impl_test.go
+++ b/tools/mgmt/device/impl_test.go
@@ -8,6 +8,9 @@
"strings"
"testing"
+ tsecurity "v.io/core/veyron/lib/testutil/security"
+
+ "v.io/core/veyron2"
"v.io/core/veyron2/naming"
"v.io/core/veyron2/rt"
"v.io/core/veyron2/services/mgmt/device"
@@ -20,6 +23,9 @@
panic(err)
}
gctx = runtime.NewContext()
+ if gctx, err = veyron2.SetPrincipal(gctx, tsecurity.NewPrincipal("test-blessing")); err != nil {
+ panic(err)
+ }
}
func TestListCommand(t *testing.T) {
diff --git a/tools/mounttable/impl_test.go b/tools/mounttable/impl_test.go
index d5026d8..0e7efad 100644
--- a/tools/mounttable/impl_test.go
+++ b/tools/mounttable/impl_test.go
@@ -9,12 +9,14 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
+ "v.io/core/veyron2/options"
"v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/mounttable"
"v.io/core/veyron2/services/security/access"
"v.io/core/veyron2/vlog"
+ tsecurity "v.io/core/veyron/lib/testutil/security"
"v.io/core/veyron/profiles"
)
@@ -103,7 +105,10 @@
func TestMountTableClient(t *testing.T) {
var err error
- runtime, err = rt.New()
+ // TODO(ataly, mattr, suharshs): This is a HACK to ensure that the server and the
+ // client have the same freshly created principal. One way to avoid the RuntimePrincipal
+ // option is to have a global client context.T (in main.go) instead of a veyron2.Runtime.
+ runtime, err = rt.New(options.RuntimePrincipal{tsecurity.NewPrincipal("test-blessing")})
if err != nil {
t.Fatalf("Unexpected error initializing runtime: %s", err)
}
diff --git a/tools/profile/impl_test.go b/tools/profile/impl_test.go
index 30891d3..75e14d6 100644
--- a/tools/profile/impl_test.go
+++ b/tools/profile/impl_test.go
@@ -10,11 +10,13 @@
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
"v.io/core/veyron2/naming"
+ "v.io/core/veyron2/options"
"v.io/core/veyron2/rt"
"v.io/core/veyron2/security"
"v.io/core/veyron2/services/mgmt/build"
"v.io/core/veyron2/vlog"
+ tsecurity "v.io/core/veyron/lib/testutil/security"
"v.io/core/veyron/profiles"
"v.io/core/veyron/services/mgmt/profile"
"v.io/core/veyron/services/mgmt/repository"
@@ -110,7 +112,10 @@
func TestProfileClient(t *testing.T) {
var err error
- runtime, err = rt.New()
+ // TODO(ataly, mattr, suharshs): This is a HACK to ensure that the server and the
+ // client have the same freshly created principal. One way to avoid the RuntimePrincipal
+ // option is to have a global client context.T (in main.go) instead of a veyron2.Runtime.
+ runtime, err = rt.New(options.RuntimePrincipal{tsecurity.NewPrincipal("test-blessing")})
if err != nil {
t.Fatalf("Unexpected error initializing runtime: %s", err)
}
diff --git a/tools/servicerunner/servicerunner_test.go b/tools/servicerunner/servicerunner_test.go
index 524f277..9ab0a1e 100644
--- a/tools/servicerunner/servicerunner_test.go
+++ b/tools/servicerunner/servicerunner_test.go
@@ -11,9 +11,12 @@
"os/exec"
"path"
"testing"
+
+ "v.io/core/veyron/lib/testutil"
)
func TestMain(t *testing.T) {
+ testutil.UnsetPrincipalEnvVars()
tmpdir, err := ioutil.TempDir("", "servicerunner_test")
if err != nil {
t.Fatal(err)
diff --git a/tools/vrpc/vrpc_test.go b/tools/vrpc/vrpc_test.go
index 3b71012..f8fd359 100644
--- a/tools/vrpc/vrpc_test.go
+++ b/tools/vrpc/vrpc_test.go
@@ -7,9 +7,11 @@
"v.io/core/veyron2"
"v.io/core/veyron2/ipc"
+ "v.io/core/veyron2/options"
"v.io/core/veyron2/rt"
"v.io/core/veyron2/vlog"
+ tsecurity "v.io/core/veyron/lib/testutil/security"
"v.io/core/veyron/profiles"
"v.io/core/veyron/tools/vrpc/test_base"
)
@@ -121,11 +123,16 @@
}
}
var err error
- if runtime, err = rt.New(); err != nil {
+ // TODO(ataly, mattr, suharshs): This is a HACK to ensure that the server and the
+ // client have the same freshly created principal. One way to avoid the RuntimePrincipal
+ // option is to have a global client context.T (in main.go) instead of a veyron2.Runtime.
+ if runtime, err = rt.New(options.RuntimePrincipal{tsecurity.NewPrincipal("test-blessing")}); err != nil {
t.Fatalf("rt.New() failed: %v", err)
return
}
- if ipcServer, err = veyron2.NewServer(runtime.NewContext()); err != nil {
+ ctx := runtime.NewContext()
+
+ if ipcServer, err = veyron2.NewServer(ctx); err != nil {
t.Fatalf("NewServer failed: %v", err)
return
}