Robin Thellend | 18205cf | 2014-10-21 13:53:59 -0700 | [diff] [blame] | 1 | package main |
Jiri Simsa | 9d22b7d | 2014-08-05 14:10:22 -0700 | [diff] [blame] | 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
Jiri Simsa | 764efb7 | 2014-12-25 20:57:03 -0800 | [diff] [blame] | 8 | "v.io/core/veyron2" |
Matt Rosencrantz | f541b77 | 2015-01-13 07:58:59 -0800 | [diff] [blame] | 9 | "v.io/core/veyron2/context" |
Jiri Simsa | 764efb7 | 2014-12-25 20:57:03 -0800 | [diff] [blame] | 10 | "v.io/core/veyron2/ipc" |
| 11 | "v.io/core/veyron2/naming" |
Jiri Simsa | 764efb7 | 2014-12-25 20:57:03 -0800 | [diff] [blame] | 12 | "v.io/core/veyron2/services/mgmt/binary" |
| 13 | "v.io/core/veyron2/services/mgmt/build" |
| 14 | verror "v.io/core/veyron2/verror2" |
| 15 | "v.io/core/veyron2/vlog" |
Cosmos Nicolaou | d6c3c9c | 2014-09-30 15:42:53 -0700 | [diff] [blame] | 16 | |
Ankur | 0003fdc | 2015-01-22 10:59:41 -0800 | [diff] [blame] | 17 | tsecurity "v.io/core/veyron/lib/testutil/security" |
Jiri Simsa | 764efb7 | 2014-12-25 20:57:03 -0800 | [diff] [blame] | 18 | "v.io/core/veyron/profiles" |
Jiri Simsa | 9d22b7d | 2014-08-05 14:10:22 -0700 | [diff] [blame] | 19 | ) |
| 20 | |
| 21 | type mock struct{} |
| 22 | |
Todd Wang | 702385a | 2014-11-07 01:54:08 -0800 | [diff] [blame] | 23 | func (mock) Build(ctx build.BuilderBuildContext, arch build.Architecture, opsys build.OperatingSystem) ([]byte, error) { |
Jiri Simsa | 9d22b7d | 2014-08-05 14:10:22 -0700 | [diff] [blame] | 24 | vlog.VI(2).Infof("Build(%v, %v) was called", arch, opsys) |
Todd Wang | 702385a | 2014-11-07 01:54:08 -0800 | [diff] [blame] | 25 | iterator := ctx.RecvStream() |
Jiri Simsa | 1bf5bd2 | 2014-08-16 13:18:45 -0700 | [diff] [blame] | 26 | for iterator.Advance() { |
| 27 | } |
| 28 | if err := iterator.Err(); err != nil { |
| 29 | vlog.Errorf("Advance() failed: %v", err) |
Matt Rosencrantz | 8f9fca1 | 2014-12-19 14:02:31 -0800 | [diff] [blame] | 30 | return nil, verror.Make(verror.Internal, ctx.Context()) |
Jiri Simsa | 1bf5bd2 | 2014-08-16 13:18:45 -0700 | [diff] [blame] | 31 | } |
Jiri Simsa | 9d22b7d | 2014-08-05 14:10:22 -0700 | [diff] [blame] | 32 | return nil, nil |
| 33 | } |
| 34 | |
| 35 | func (mock) Describe(_ ipc.ServerContext, name string) (binary.Description, error) { |
| 36 | vlog.VI(2).Infof("Describe(%v) was called", name) |
| 37 | return binary.Description{}, nil |
| 38 | } |
| 39 | |
| 40 | type dispatcher struct{} |
| 41 | |
Matt Rosencrantz | f541b77 | 2015-01-13 07:58:59 -0800 | [diff] [blame] | 42 | func startServer(ctx *context.T, t *testing.T) (ipc.Server, naming.Endpoint) { |
| 43 | server, err := veyron2.NewServer(ctx) |
Jiri Simsa | 9d22b7d | 2014-08-05 14:10:22 -0700 | [diff] [blame] | 44 | if err != nil { |
| 45 | t.Fatalf("NewServer failed: %v", err) |
| 46 | } |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 47 | endpoints, err := server.Listen(profiles.LocalListenSpec) |
Jiri Simsa | 9d22b7d | 2014-08-05 14:10:22 -0700 | [diff] [blame] | 48 | if err != nil { |
Cosmos Nicolaou | d6c3c9c | 2014-09-30 15:42:53 -0700 | [diff] [blame] | 49 | t.Fatalf("Listen(%s) failed: %v", profiles.LocalListenSpec, err) |
Jiri Simsa | 9d22b7d | 2014-08-05 14:10:22 -0700 | [diff] [blame] | 50 | } |
| 51 | unpublished := "" |
Todd Wang | 702385a | 2014-11-07 01:54:08 -0800 | [diff] [blame] | 52 | if err := server.Serve(unpublished, build.BuilderServer(&mock{}), nil); err != nil { |
Jiri Simsa | 9d22b7d | 2014-08-05 14:10:22 -0700 | [diff] [blame] | 53 | t.Fatalf("Serve(%v) failed: %v", unpublished, err) |
| 54 | } |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 55 | return server, endpoints[0] |
Jiri Simsa | 9d22b7d | 2014-08-05 14:10:22 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | func stopServer(t *testing.T, server ipc.Server) { |
| 59 | if err := server.Stop(); err != nil { |
| 60 | t.Errorf("Stop() failed: %v", err) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | func TestBuildClient(t *testing.T) { |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 65 | var shutdown veyron2.Shutdown |
| 66 | gctx, shutdown = veyron2.Init() |
| 67 | defer shutdown() |
Matt Rosencrantz | c2ed03e | 2014-11-25 15:40:48 -0800 | [diff] [blame] | 68 | var err error |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 69 | if gctx, err = veyron2.SetPrincipal(gctx, tsecurity.NewPrincipal("test-blessing")); err != nil { |
| 70 | panic(err) |
Matt Rosencrantz | c2ed03e | 2014-11-25 15:40:48 -0800 | [diff] [blame] | 71 | } |
Matt Rosencrantz | a5ad272 | 2015-01-22 11:17:47 -0800 | [diff] [blame] | 72 | |
| 73 | server, endpoint := startServer(gctx, t) |
Jiri Simsa | 9d22b7d | 2014-08-05 14:10:22 -0700 | [diff] [blame] | 74 | defer stopServer(t, server) |
| 75 | |
Robin Thellend | 18205cf | 2014-10-21 13:53:59 -0700 | [diff] [blame] | 76 | cmd := root() |
Jiri Simsa | 9d22b7d | 2014-08-05 14:10:22 -0700 | [diff] [blame] | 77 | var stdout, stderr bytes.Buffer |
| 78 | cmd.Init(nil, &stdout, &stderr) |
| 79 | |
| 80 | // Test the 'Build' command. |
Jiri Simsa | 764efb7 | 2014-12-25 20:57:03 -0800 | [diff] [blame] | 81 | if err := cmd.Execute([]string{"build", naming.JoinAddressName(endpoint.String(), ""), "v.io/core/veyron/tools/build"}); err != nil { |
Jiri Simsa | 9d22b7d | 2014-08-05 14:10:22 -0700 | [diff] [blame] | 82 | t.Fatalf("%v", err) |
| 83 | } |
| 84 | if expected, got := "", strings.TrimSpace(stdout.String()); got != expected { |
| 85 | t.Errorf("Unexpected output from build: got %q, expected %q", got, expected) |
| 86 | } |
| 87 | } |