Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 1 | package app |
| 2 | |
| 3 | import ( |
Matt Rosencrantz | 786f727 | 2015-02-11 15:18:07 -0800 | [diff] [blame] | 4 | "bytes" |
| 5 | "encoding/hex" |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 6 | "fmt" |
| 7 | "reflect" |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 8 | "sync" |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 9 | "testing" |
| 10 | |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 11 | "v.io/core/veyron/lib/testutil" |
| 12 | tsecurity "v.io/core/veyron/lib/testutil/security" |
| 13 | _ "v.io/core/veyron/profiles" |
| 14 | "v.io/core/veyron/runtimes/google/ipc/stream/proxy" |
| 15 | vsecurity "v.io/core/veyron/security" |
| 16 | mounttable "v.io/core/veyron/services/mounttable/lib" |
Jiri Simsa | 1f1302c | 2015-02-23 16:18:34 -0800 | [diff] [blame] | 17 | "v.io/v23" |
| 18 | "v.io/v23/context" |
| 19 | "v.io/v23/ipc" |
| 20 | "v.io/v23/naming" |
| 21 | "v.io/v23/options" |
| 22 | "v.io/v23/security" |
| 23 | "v.io/v23/vdl" |
Todd Wang | ac9e190 | 2015-02-25 01:58:01 -0800 | [diff] [blame] | 24 | "v.io/v23/vdlroot/signature" |
Jiri Simsa | 1f1302c | 2015-02-23 16:18:34 -0800 | [diff] [blame] | 25 | "v.io/v23/verror" |
| 26 | "v.io/v23/vom" |
| 27 | "v.io/v23/vtrace" |
Jiri Simsa | 350ed9b | 2015-02-26 14:02:52 -0800 | [diff] [blame^] | 28 | "v.io/core/veyron/services/wsprd/ipc/server" |
| 29 | "v.io/core/veyron/services/wsprd/lib" |
| 30 | "v.io/core/veyron/services/wsprd/lib/testwriter" |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 31 | ) |
| 32 | |
Ankur | e788924 | 2014-10-20 18:37:29 -0700 | [diff] [blame] | 33 | var ( |
| 34 | testPrincipalBlessing = "test" |
| 35 | testPrincipal = newPrincipal(testPrincipalBlessing) |
Ankur | e788924 | 2014-10-20 18:37:29 -0700 | [diff] [blame] | 36 | ) |
| 37 | |
| 38 | // newBlessedPrincipal returns a new principal that has a blessing from the |
| 39 | // provided runtime's principal which is set on its BlessingStore such |
| 40 | // that it is revealed to all clients and servers. |
Matt Rosencrantz | 306d990 | 2015-01-10 17:46:07 -0800 | [diff] [blame] | 41 | func newBlessedPrincipal(ctx *context.T) security.Principal { |
Ankur | e788924 | 2014-10-20 18:37:29 -0700 | [diff] [blame] | 42 | p, err := vsecurity.NewPrincipal() |
| 43 | if err != nil { |
| 44 | panic(err) |
| 45 | } |
Matt Rosencrantz | 306d990 | 2015-01-10 17:46:07 -0800 | [diff] [blame] | 46 | |
Jiri Simsa | 1f1302c | 2015-02-23 16:18:34 -0800 | [diff] [blame] | 47 | principal := v23.GetPrincipal(ctx) |
Matt Rosencrantz | 306d990 | 2015-01-10 17:46:07 -0800 | [diff] [blame] | 48 | b, err := principal.Bless(p.PublicKey(), principal.BlessingStore().Default(), "delegate", security.UnconstrainedUse()) |
Ankur | e788924 | 2014-10-20 18:37:29 -0700 | [diff] [blame] | 49 | if err != nil { |
| 50 | panic(err) |
| 51 | } |
| 52 | tsecurity.SetDefaultBlessings(p, b) |
| 53 | return p |
| 54 | } |
| 55 | |
| 56 | // newPrincipal returns a new principal that has a self-blessing with |
| 57 | // the provided extension 'selfBlessing' which is set on its BlessingStore |
| 58 | // such that it is revealed to all clients and servers. |
| 59 | func newPrincipal(selfBlessing string) security.Principal { |
| 60 | p, err := vsecurity.NewPrincipal() |
| 61 | if err != nil { |
| 62 | panic(err) |
| 63 | } |
| 64 | b, err := p.BlessSelf(selfBlessing) |
| 65 | if err != nil { |
| 66 | panic(err) |
| 67 | } |
| 68 | tsecurity.SetDefaultBlessings(p, b) |
| 69 | return p |
| 70 | } |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 71 | |
| 72 | type simpleAdder struct{} |
| 73 | |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 74 | func (s simpleAdder) Add(_ ipc.ServerContext, a, b int32) (int32, error) { |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 75 | return a + b, nil |
| 76 | } |
| 77 | |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 78 | func (s simpleAdder) Divide(_ ipc.ServerContext, a, b int32) (int32, error) { |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 79 | if b == 0 { |
Jiri Simsa | 94f68d0 | 2015-02-17 10:22:08 -0800 | [diff] [blame] | 80 | return 0, verror.New(verror.ErrBadArg, nil, "div 0") |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 81 | } |
| 82 | return a / b, nil |
| 83 | } |
| 84 | |
| 85 | func (s simpleAdder) StreamingAdd(call ipc.ServerCall) (int32, error) { |
| 86 | total := int32(0) |
| 87 | var value int32 |
| 88 | for err := call.Recv(&value); err == nil; err = call.Recv(&value) { |
| 89 | total += value |
| 90 | call.Send(total) |
| 91 | } |
| 92 | return total, nil |
| 93 | } |
| 94 | |
Todd Wang | 72ef57b | 2015-01-08 10:23:21 -0800 | [diff] [blame] | 95 | var simpleAddrSig = signature.Interface{ |
| 96 | Doc: "The empty interface contains methods not attached to any interface.", |
| 97 | Methods: []signature.Method{ |
| 98 | { |
| 99 | Name: "Add", |
| 100 | InArgs: []signature.Arg{{Type: vdl.Int32Type}, {Type: vdl.Int32Type}}, |
Benjamin Prosnitz | 518af1e | 2015-01-20 14:20:10 -0800 | [diff] [blame] | 101 | OutArgs: []signature.Arg{{Type: vdl.Int32Type}}, |
Todd Wang | 72ef57b | 2015-01-08 10:23:21 -0800 | [diff] [blame] | 102 | }, |
| 103 | { |
| 104 | Name: "Divide", |
| 105 | InArgs: []signature.Arg{{Type: vdl.Int32Type}, {Type: vdl.Int32Type}}, |
Benjamin Prosnitz | 518af1e | 2015-01-20 14:20:10 -0800 | [diff] [blame] | 106 | OutArgs: []signature.Arg{{Type: vdl.Int32Type}}, |
Todd Wang | 72ef57b | 2015-01-08 10:23:21 -0800 | [diff] [blame] | 107 | }, |
| 108 | { |
| 109 | Name: "StreamingAdd", |
Benjamin Prosnitz | 518af1e | 2015-01-20 14:20:10 -0800 | [diff] [blame] | 110 | OutArgs: []signature.Arg{{Type: vdl.Int32Type}}, |
Todd Wang | 72ef57b | 2015-01-08 10:23:21 -0800 | [diff] [blame] | 111 | InStream: &signature.Arg{Type: vdl.AnyType}, |
| 112 | OutStream: &signature.Arg{Type: vdl.AnyType}, |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 113 | }, |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 114 | }, |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Suharsh Sivakumar | 94d0066 | 2015-01-21 14:31:30 -0800 | [diff] [blame] | 117 | func startAnyServer(ctx *context.T, servesMT bool, dispatcher ipc.Dispatcher) (ipc.Server, naming.Endpoint, error) { |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 118 | // Create a new server instance. |
Jiri Simsa | 1f1302c | 2015-02-23 16:18:34 -0800 | [diff] [blame] | 119 | s, err := v23.NewServer(ctx, options.ServesMountTable(servesMT)) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 120 | if err != nil { |
| 121 | return nil, nil, err |
| 122 | } |
| 123 | |
Jiri Simsa | 1f1302c | 2015-02-23 16:18:34 -0800 | [diff] [blame] | 124 | endpoints, err := s.Listen(v23.GetListenSpec(ctx)) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 125 | if err != nil { |
| 126 | return nil, nil, err |
| 127 | } |
| 128 | |
Cosmos Nicolaou | 4619b1f | 2014-11-05 07:23:13 -0800 | [diff] [blame] | 129 | if err := s.ServeDispatcher("", dispatcher); err != nil { |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 130 | return nil, nil, err |
| 131 | } |
Cosmos Nicolaou | d48178c | 2014-12-15 22:51:52 -0800 | [diff] [blame] | 132 | return s, endpoints[0], nil |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Suharsh Sivakumar | 94d0066 | 2015-01-21 14:31:30 -0800 | [diff] [blame] | 135 | func startAdderServer(ctx *context.T) (ipc.Server, naming.Endpoint, error) { |
| 136 | return startAnyServer(ctx, false, testutil.LeafDispatcher(simpleAdder{}, nil)) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Suharsh Sivakumar | 94d0066 | 2015-01-21 14:31:30 -0800 | [diff] [blame] | 139 | func startProxy(ctx *context.T) (*proxy.Proxy, error) { |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 140 | rid, err := naming.NewRoutingID() |
| 141 | if err != nil { |
| 142 | return nil, err |
| 143 | } |
| 144 | return proxy.New(rid, nil, "tcp", "127.0.0.1:0", "") |
| 145 | } |
| 146 | |
Suharsh Sivakumar | 94d0066 | 2015-01-21 14:31:30 -0800 | [diff] [blame] | 147 | func startMountTableServer(ctx *context.T) (ipc.Server, naming.Endpoint, error) { |
Bogdan Caprita | a25b6c2 | 2015-02-03 17:30:21 -0800 | [diff] [blame] | 148 | mt, err := mounttable.NewMountTableDispatcher("") |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 149 | if err != nil { |
| 150 | return nil, nil, err |
| 151 | } |
Suharsh Sivakumar | 94d0066 | 2015-01-21 14:31:30 -0800 | [diff] [blame] | 152 | return startAnyServer(ctx, true, mt) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 155 | func TestGetGoServerSignature(t *testing.T) { |
Ankur | 9dec6d6 | 2015-01-30 15:07:01 -0800 | [diff] [blame] | 156 | ctx, shutdown := testutil.InitForTest() |
Suharsh Sivakumar | 94d0066 | 2015-01-21 14:31:30 -0800 | [diff] [blame] | 157 | defer shutdown() |
| 158 | |
| 159 | s, endpoint, err := startAdderServer(ctx) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 160 | if err != nil { |
| 161 | t.Errorf("unable to start server: %v", err) |
| 162 | t.Fail() |
| 163 | return |
| 164 | } |
| 165 | defer s.Stop() |
Suharsh Sivakumar | 94d0066 | 2015-01-21 14:31:30 -0800 | [diff] [blame] | 166 | |
Jiri Simsa | 1f1302c | 2015-02-23 16:18:34 -0800 | [diff] [blame] | 167 | spec := v23.GetListenSpec(ctx) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 168 | spec.Proxy = "mockVeyronProxyEP" |
Suharsh Sivakumar | 94d0066 | 2015-01-21 14:31:30 -0800 | [diff] [blame] | 169 | controller, err := NewController(ctx, nil, &spec, nil, newBlessedPrincipal(ctx)) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 170 | |
| 171 | if err != nil { |
Ankur | e788924 | 2014-10-20 18:37:29 -0700 | [diff] [blame] | 172 | t.Fatalf("Failed to create controller: %v", err) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 173 | } |
Suharsh Sivakumar | 94d0066 | 2015-01-21 14:31:30 -0800 | [diff] [blame] | 174 | sig, err := controller.getSignature(ctx, "/"+endpoint.String()) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 175 | if err != nil { |
Ankur | e788924 | 2014-10-20 18:37:29 -0700 | [diff] [blame] | 176 | t.Fatalf("Failed to get signature: %v", err) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 177 | } |
Todd Wang | 72ef57b | 2015-01-08 10:23:21 -0800 | [diff] [blame] | 178 | if got, want := len(sig), 2; got != want { |
| 179 | t.Fatalf("got signature %#v len %d, want %d", sig, got, want) |
| 180 | } |
| 181 | if got, want := sig[0], simpleAddrSig; !reflect.DeepEqual(got, want) { |
| 182 | t.Errorf("got sig[0] %#v, want: %#v", got, want) |
| 183 | } |
| 184 | if got, want := sig[1].Name, "__Reserved"; got != want { |
| 185 | t.Errorf("got sig[1].Name %#v, want: %#v", got, want) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
| 189 | type goServerTestCase struct { |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 190 | method string |
Matt Rosencrantz | 786f727 | 2015-02-11 15:18:07 -0800 | [diff] [blame] | 191 | inArgs []interface{} |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 192 | numOutArgs int32 |
| 193 | streamingInputs []interface{} |
| 194 | expectedStream []lib.Response |
| 195 | expectedError error |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | func runGoServerTestCase(t *testing.T, test goServerTestCase) { |
Ankur | 9dec6d6 | 2015-01-30 15:07:01 -0800 | [diff] [blame] | 199 | ctx, shutdown := testutil.InitForTest() |
Suharsh Sivakumar | 94d0066 | 2015-01-21 14:31:30 -0800 | [diff] [blame] | 200 | defer shutdown() |
| 201 | |
| 202 | s, endpoint, err := startAdderServer(ctx) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 203 | if err != nil { |
| 204 | t.Errorf("unable to start server: %v", err) |
| 205 | t.Fail() |
| 206 | return |
| 207 | } |
| 208 | defer s.Stop() |
Cosmos Nicolaou | 408de0f | 2014-10-24 13:32:29 -0700 | [diff] [blame] | 209 | |
Jiri Simsa | 1f1302c | 2015-02-23 16:18:34 -0800 | [diff] [blame] | 210 | spec := v23.GetListenSpec(ctx) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 211 | spec.Proxy = "mockVeyronProxyEP" |
Suharsh Sivakumar | 94d0066 | 2015-01-21 14:31:30 -0800 | [diff] [blame] | 212 | controller, err := NewController(ctx, nil, &spec, nil, newBlessedPrincipal(ctx)) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 213 | |
| 214 | if err != nil { |
| 215 | t.Errorf("unable to create controller: %v", err) |
| 216 | t.Fail() |
| 217 | return |
| 218 | } |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 219 | writer := testwriter.Writer{} |
| 220 | var stream *outstandingStream |
| 221 | if len(test.streamingInputs) > 0 { |
| 222 | stream = newStream() |
Matt Rosencrantz | 4aabe57 | 2014-10-22 09:25:50 -0700 | [diff] [blame] | 223 | controller.outstandingRequests[0] = &outstandingRequest{ |
| 224 | stream: stream, |
| 225 | } |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 226 | go func() { |
| 227 | for _, value := range test.streamingInputs { |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 228 | controller.SendOnStream(0, lib.VomEncodeOrDie(value), &writer) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 229 | } |
| 230 | controller.CloseStream(0) |
| 231 | }() |
| 232 | } |
| 233 | |
Matt Rosencrantz | ac1e3a8 | 2015-02-12 16:04:28 -0800 | [diff] [blame] | 234 | request := VeyronRPCRequest{ |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 235 | Name: "/" + endpoint.String(), |
| 236 | Method: test.method, |
Matt Rosencrantz | 786f727 | 2015-02-11 15:18:07 -0800 | [diff] [blame] | 237 | NumInArgs: int32(len(test.inArgs)), |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 238 | NumOutArgs: test.numOutArgs, |
| 239 | IsStreaming: stream != nil, |
| 240 | } |
Matt Rosencrantz | ac1e3a8 | 2015-02-12 16:04:28 -0800 | [diff] [blame] | 241 | controller.sendVeyronRequest(ctx, 0, &request, test.inArgs, &writer, stream, vtrace.GetSpan(ctx)) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 242 | |
Matt Rosencrantz | 4aabe57 | 2014-10-22 09:25:50 -0700 | [diff] [blame] | 243 | if err := testwriter.CheckResponses(&writer, test.expectedStream, test.expectedError); err != nil { |
| 244 | t.Error(err) |
| 245 | } |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Todd Wang | 5ab0366 | 2015-02-19 21:03:01 -0800 | [diff] [blame] | 248 | func makeRPCResponse(outArgs ...*vdl.Value) string { |
Matt Rosencrantz | ac1e3a8 | 2015-02-12 16:04:28 -0800 | [diff] [blame] | 249 | return lib.VomEncodeOrDie(VeyronRPCResponse{ |
Matt Rosencrantz | 8fa0ea1 | 2015-02-24 14:17:50 -0800 | [diff] [blame] | 250 | OutArgs: outArgs, |
| 251 | TraceResponse: vtrace.Response{}, |
Matt Rosencrantz | ac1e3a8 | 2015-02-12 16:04:28 -0800 | [diff] [blame] | 252 | }) |
| 253 | } |
| 254 | |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 255 | func TestCallingGoServer(t *testing.T) { |
| 256 | runGoServerTestCase(t, goServerTestCase{ |
| 257 | method: "Add", |
Matt Rosencrantz | 786f727 | 2015-02-11 15:18:07 -0800 | [diff] [blame] | 258 | inArgs: []interface{}{2, 3}, |
Benjamin Prosnitz | 518af1e | 2015-01-20 14:20:10 -0800 | [diff] [blame] | 259 | numOutArgs: 1, |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 260 | expectedStream: []lib.Response{ |
| 261 | lib.Response{ |
Todd Wang | 5ab0366 | 2015-02-19 21:03:01 -0800 | [diff] [blame] | 262 | Message: makeRPCResponse(vdl.Int32Value(5)), |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 263 | Type: lib.ResponseFinal, |
| 264 | }, |
| 265 | }, |
| 266 | }) |
| 267 | } |
| 268 | |
| 269 | func TestCallingGoServerWithError(t *testing.T) { |
| 270 | runGoServerTestCase(t, goServerTestCase{ |
| 271 | method: "Divide", |
Matt Rosencrantz | 786f727 | 2015-02-11 15:18:07 -0800 | [diff] [blame] | 272 | inArgs: []interface{}{1, 0}, |
Benjamin Prosnitz | 518af1e | 2015-01-20 14:20:10 -0800 | [diff] [blame] | 273 | numOutArgs: 1, |
Jiri Simsa | 94f68d0 | 2015-02-17 10:22:08 -0800 | [diff] [blame] | 274 | expectedError: verror.New(verror.ErrBadArg, nil, "div 0"), |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 275 | }) |
| 276 | } |
| 277 | |
| 278 | func TestCallingGoWithStreaming(t *testing.T) { |
| 279 | runGoServerTestCase(t, goServerTestCase{ |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 280 | method: "StreamingAdd", |
| 281 | streamingInputs: []interface{}{1, 2, 3, 4}, |
Benjamin Prosnitz | 518af1e | 2015-01-20 14:20:10 -0800 | [diff] [blame] | 282 | numOutArgs: 1, |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 283 | expectedStream: []lib.Response{ |
| 284 | lib.Response{ |
| 285 | Message: lib.VomEncodeOrDie(int32(1)), |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 286 | Type: lib.ResponseStream, |
| 287 | }, |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 288 | lib.Response{ |
| 289 | Message: lib.VomEncodeOrDie(int32(3)), |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 290 | Type: lib.ResponseStream, |
| 291 | }, |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 292 | lib.Response{ |
| 293 | Message: lib.VomEncodeOrDie(int32(6)), |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 294 | Type: lib.ResponseStream, |
| 295 | }, |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 296 | lib.Response{ |
| 297 | Message: lib.VomEncodeOrDie(int32(10)), |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 298 | Type: lib.ResponseStream, |
| 299 | }, |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 300 | lib.Response{ |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 301 | Message: nil, |
| 302 | Type: lib.ResponseStreamClose, |
| 303 | }, |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 304 | lib.Response{ |
Todd Wang | 5ab0366 | 2015-02-19 21:03:01 -0800 | [diff] [blame] | 305 | Message: makeRPCResponse(vdl.Int32Value(10)), |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 306 | Type: lib.ResponseFinal, |
| 307 | }, |
| 308 | }, |
| 309 | }) |
| 310 | } |
| 311 | |
| 312 | type runningTest struct { |
| 313 | controller *Controller |
| 314 | writer *testwriter.Writer |
| 315 | mounttableServer ipc.Server |
| 316 | proxyServer *proxy.Proxy |
| 317 | } |
| 318 | |
Matt Rosencrantz | ac1e3a8 | 2015-02-12 16:04:28 -0800 | [diff] [blame] | 319 | func makeRequest(rpc VeyronRPCRequest, args ...interface{}) (string, error) { |
Matt Rosencrantz | 786f727 | 2015-02-11 15:18:07 -0800 | [diff] [blame] | 320 | var buf bytes.Buffer |
Todd Wang | f619d43 | 2015-02-18 11:19:27 -0800 | [diff] [blame] | 321 | encoder, err := vom.NewEncoder(&buf) |
Matt Rosencrantz | 786f727 | 2015-02-11 15:18:07 -0800 | [diff] [blame] | 322 | if err != nil { |
| 323 | return "", err |
| 324 | } |
| 325 | if err := encoder.Encode(rpc); err != nil { |
| 326 | return "", err |
| 327 | } |
| 328 | for _, arg := range args { |
| 329 | if err := encoder.Encode(arg); err != nil { |
| 330 | return "", err |
| 331 | } |
| 332 | } |
| 333 | return hex.EncodeToString(buf.Bytes()), nil |
| 334 | } |
| 335 | |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 336 | func serveServer(ctx *context.T, writer lib.ClientWriter, setController func(*Controller)) (*runningTest, error) { |
Suharsh Sivakumar | 94d0066 | 2015-01-21 14:31:30 -0800 | [diff] [blame] | 337 | mounttableServer, endpoint, err := startMountTableServer(ctx) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 338 | if err != nil { |
| 339 | return nil, fmt.Errorf("unable to start mounttable: %v", err) |
| 340 | } |
| 341 | |
Suharsh Sivakumar | 94d0066 | 2015-01-21 14:31:30 -0800 | [diff] [blame] | 342 | proxyServer, err := startProxy(ctx) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 343 | if err != nil { |
| 344 | return nil, fmt.Errorf("unable to start proxy: %v", err) |
| 345 | } |
| 346 | |
| 347 | proxyEndpoint := proxyServer.Endpoint().String() |
| 348 | |
Benjamin Prosnitz | 86d5228 | 2014-12-19 15:48:38 -0800 | [diff] [blame] | 349 | writerCreator := func(int32) lib.ClientWriter { |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 350 | return writer |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 351 | } |
Jiri Simsa | 1f1302c | 2015-02-23 16:18:34 -0800 | [diff] [blame] | 352 | spec := v23.GetListenSpec(ctx) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 353 | spec.Proxy = "/" + proxyEndpoint |
Suharsh Sivakumar | 94d0066 | 2015-01-21 14:31:30 -0800 | [diff] [blame] | 354 | controller, err := NewController(ctx, writerCreator, &spec, nil, testPrincipal) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 355 | if err != nil { |
| 356 | return nil, err |
| 357 | } |
Suharsh Sivakumar | 94d0066 | 2015-01-21 14:31:30 -0800 | [diff] [blame] | 358 | |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 359 | if setController != nil { |
| 360 | setController(controller) |
| 361 | } |
| 362 | |
Jiri Simsa | 1f1302c | 2015-02-23 16:18:34 -0800 | [diff] [blame] | 363 | v23.GetNamespace(controller.Context()).SetRoots("/" + endpoint.String()) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 364 | |
Matt Rosencrantz | ac1e3a8 | 2015-02-12 16:04:28 -0800 | [diff] [blame] | 365 | req, err := makeRequest(VeyronRPCRequest{ |
Matt Rosencrantz | 9d2170b | 2015-02-21 16:19:53 -0800 | [diff] [blame] | 366 | Name: "__controller", |
Matt Rosencrantz | 786f727 | 2015-02-11 15:18:07 -0800 | [diff] [blame] | 367 | Method: "Serve", |
| 368 | NumInArgs: 2, |
| 369 | NumOutArgs: 1, |
| 370 | Timeout: 20000000000, |
| 371 | }, "adder", 0) |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 372 | controller.HandleVeyronRequest(ctx, 0, req, writer) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 373 | |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 374 | testWriter, _ := writer.(*testwriter.Writer) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 375 | return &runningTest{ |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 376 | controller, testWriter, mounttableServer, proxyServer, |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 377 | }, nil |
| 378 | } |
| 379 | |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 380 | // A test case to simulate a Javascript server talking to the App. All the |
| 381 | // responses from Javascript are mocked and sent back through the method calls. |
| 382 | // All messages from the client are sent using a go client. |
| 383 | type jsServerTestCase struct { |
| 384 | method string |
| 385 | inArgs []interface{} |
| 386 | // The set of streaming inputs from the client to the server. |
| 387 | // This is passed to the client, which then passes it to the app. |
| 388 | clientStream []interface{} |
| 389 | // The set of JSON streaming messages sent from Javascript to the |
| 390 | // app. |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 391 | serverStream []interface{} |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 392 | // The final response sent by the Javascript server to the |
| 393 | // app. |
Todd Wang | 5ab0366 | 2015-02-19 21:03:01 -0800 | [diff] [blame] | 394 | finalResponse *vdl.Value |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 395 | // The final error sent by the Javascript server to the app. |
Mike Burrows | a727df7 | 2015-02-04 17:26:46 -0800 | [diff] [blame] | 396 | err error |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 397 | |
| 398 | // Whether or not the Javascript server has an authorizer or not. |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 399 | // If it does have an authorizer, then err is sent back from the server |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 400 | // to the app. |
| 401 | hasAuthorizer bool |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 404 | func runJsServerTestCase(t *testing.T, test jsServerTestCase) { |
Ankur | 9dec6d6 | 2015-01-30 15:07:01 -0800 | [diff] [blame] | 405 | ctx, shutdown := testutil.InitForTest() |
Suharsh Sivakumar | 94d0066 | 2015-01-21 14:31:30 -0800 | [diff] [blame] | 406 | defer shutdown() |
| 407 | |
Shyam Jayaraman | e56df9a | 2014-11-20 17:38:54 -0800 | [diff] [blame] | 408 | vomClientStream := []string{} |
| 409 | for _, m := range test.clientStream { |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 410 | vomClientStream = append(vomClientStream, lib.VomEncodeOrDie(m)) |
Shyam Jayaraman | e56df9a | 2014-11-20 17:38:54 -0800 | [diff] [blame] | 411 | } |
| 412 | mock := &mockJSServer{ |
Shyam Jayaraman | e56df9a | 2014-11-20 17:38:54 -0800 | [diff] [blame] | 413 | t: t, |
| 414 | method: test.method, |
Todd Wang | 72ef57b | 2015-01-08 10:23:21 -0800 | [diff] [blame] | 415 | serviceSignature: []signature.Interface{simpleAddrSig}, |
Shyam Jayaraman | e56df9a | 2014-11-20 17:38:54 -0800 | [diff] [blame] | 416 | expectedClientStream: vomClientStream, |
| 417 | serverStream: test.serverStream, |
| 418 | hasAuthorizer: test.hasAuthorizer, |
Shyam Jayaraman | 907219d | 2014-11-26 12:14:37 -0800 | [diff] [blame] | 419 | inArgs: test.inArgs, |
Shyam Jayaraman | e56df9a | 2014-11-20 17:38:54 -0800 | [diff] [blame] | 420 | finalResponse: test.finalResponse, |
| 421 | finalError: test.err, |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 422 | controllerReady: sync.RWMutex{}, |
Shyam Jayaraman | e56df9a | 2014-11-20 17:38:54 -0800 | [diff] [blame] | 423 | } |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 424 | rt, err := serveServer(ctx, mock, func(controller *Controller) { |
| 425 | mock.controller = controller |
| 426 | }) |
| 427 | defer rt.mounttableServer.Stop() |
| 428 | defer rt.proxyServer.Shutdown() |
| 429 | defer rt.controller.Cleanup() |
| 430 | |
| 431 | if err != nil { |
| 432 | t.Fatalf("could not serve server %v", err) |
Shyam Jayaraman | e56df9a | 2014-11-20 17:38:54 -0800 | [diff] [blame] | 433 | } |
| 434 | |
Matt Rosencrantz | c90eb7b | 2015-01-09 08:32:01 -0800 | [diff] [blame] | 435 | // Get the client that is relevant to the controller so it talks |
| 436 | // to the right mounttable. |
Jiri Simsa | 1f1302c | 2015-02-23 16:18:34 -0800 | [diff] [blame] | 437 | client := v23.GetClient(rt.controller.Context()) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 438 | |
| 439 | if err != nil { |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 440 | t.Fatalf("unable to create client: %v", err) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Matt Rosencrantz | c90eb7b | 2015-01-09 08:32:01 -0800 | [diff] [blame] | 443 | call, err := client.StartCall(rt.controller.Context(), "adder/adder", test.method, test.inArgs) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 444 | if err != nil { |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 445 | t.Fatalf("failed to start call: %v", err) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 448 | for _, msg := range test.clientStream { |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 449 | if err := call.Send(msg); err != nil { |
| 450 | t.Errorf("unexpected error while sending %v: %v", msg, err) |
| 451 | } |
| 452 | } |
Shyam Jayaraman | e56df9a | 2014-11-20 17:38:54 -0800 | [diff] [blame] | 453 | if err := call.CloseSend(); err != nil { |
| 454 | t.Errorf("unexpected error on close: %v", err) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 457 | expectedStream := test.serverStream |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 458 | for { |
| 459 | var data interface{} |
| 460 | if err := call.Recv(&data); err != nil { |
| 461 | break |
| 462 | } |
| 463 | if len(expectedStream) == 0 { |
| 464 | t.Errorf("unexpected stream value: %v", data) |
| 465 | continue |
| 466 | } |
| 467 | if !reflect.DeepEqual(data, expectedStream[0]) { |
| 468 | t.Errorf("unexpected stream value: got %v, expected %v", data, expectedStream[0]) |
| 469 | } |
| 470 | expectedStream = expectedStream[1:] |
| 471 | } |
Shyam Jayaraman | e56df9a | 2014-11-20 17:38:54 -0800 | [diff] [blame] | 472 | |
Todd Wang | 5ab0366 | 2015-02-19 21:03:01 -0800 | [diff] [blame] | 473 | var result *vdl.Value |
Todd Wang | f21e155 | 2015-02-18 13:21:52 -0800 | [diff] [blame] | 474 | err = call.Finish(&result) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 475 | |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 476 | // If err is nil and test.err is nil reflect.DeepEqual will return |
| 477 | // false because the types are different. Because of this, we only use |
| 478 | // reflect.DeepEqual if one of the values is non-nil. If both values |
| 479 | // are nil, then we consider them equal. |
| 480 | if (err != nil || test.err != nil) && !verror.Equal(err, test.err) { |
| 481 | t.Errorf("unexpected err: got %#v, expected %#v", err, test.err) |
| 482 | } |
| 483 | |
| 484 | if err != nil { |
| 485 | return |
Shyam Jayaraman | e56df9a | 2014-11-20 17:38:54 -0800 | [diff] [blame] | 486 | } |
Nicolas LaCasse | d7ab8a1 | 2015-02-03 11:46:29 -0800 | [diff] [blame] | 487 | |
Todd Wang | 5ab0366 | 2015-02-19 21:03:01 -0800 | [diff] [blame] | 488 | if got, want := result, test.finalResponse; !vdl.EqualValue(got, want) { |
| 489 | t.Errorf("unexected final response: got %v, want %v", got, want) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 490 | } |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 491 | |
| 492 | // ensure there is only one server and then stop the server |
| 493 | if len(rt.controller.servers) != 1 { |
| 494 | t.Errorf("expected only one server but got: %d", len(rt.controller.servers)) |
| 495 | return |
| 496 | } |
| 497 | for serverId := range rt.controller.servers { |
| 498 | rt.controller.Stop(nil, serverId) |
| 499 | } |
| 500 | |
| 501 | // ensure there is no more servers now |
| 502 | if len(rt.controller.servers) != 0 { |
| 503 | t.Errorf("expected no server after stopping the only one but got: %d", len(rt.controller.servers)) |
| 504 | return |
| 505 | } |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | func TestSimpleJSServer(t *testing.T) { |
| 509 | runJsServerTestCase(t, jsServerTestCase{ |
| 510 | method: "Add", |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 511 | inArgs: []interface{}{int32(1), int32(2)}, |
Todd Wang | 5ab0366 | 2015-02-19 21:03:01 -0800 | [diff] [blame] | 512 | finalResponse: vdl.Int32Value(3), |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 513 | }) |
| 514 | } |
| 515 | |
| 516 | func TestJSServerWithAuthorizer(t *testing.T) { |
| 517 | runJsServerTestCase(t, jsServerTestCase{ |
| 518 | method: "Add", |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 519 | inArgs: []interface{}{int32(1), int32(2)}, |
Todd Wang | 5ab0366 | 2015-02-19 21:03:01 -0800 | [diff] [blame] | 520 | finalResponse: vdl.Int32Value(3), |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 521 | hasAuthorizer: true, |
| 522 | }) |
| 523 | } |
| 524 | |
| 525 | func TestJSServerWithError(t *testing.T) { |
Jiri Simsa | 94f68d0 | 2015-02-17 10:22:08 -0800 | [diff] [blame] | 526 | err := verror.New(verror.ErrInternal, nil) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 527 | runJsServerTestCase(t, jsServerTestCase{ |
Nicolas LaCasse | d7ab8a1 | 2015-02-03 11:46:29 -0800 | [diff] [blame] | 528 | method: "Divide", |
| 529 | inArgs: []interface{}{int32(1), int32(0)}, |
| 530 | err: err, |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 531 | }) |
| 532 | } |
| 533 | |
| 534 | func TestJSServerWithAuthorizerAndAuthError(t *testing.T) { |
Jiri Simsa | 94f68d0 | 2015-02-17 10:22:08 -0800 | [diff] [blame] | 535 | err := verror.New(verror.ErrNoAccess, nil) |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 536 | runJsServerTestCase(t, jsServerTestCase{ |
| 537 | method: "Add", |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 538 | inArgs: []interface{}{int32(1), int32(2)}, |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 539 | hasAuthorizer: true, |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 540 | finalResponse: vdl.Int32Value(3), |
| 541 | err: err, |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 542 | }) |
| 543 | } |
| 544 | func TestJSServerWihStreamingInputs(t *testing.T) { |
| 545 | runJsServerTestCase(t, jsServerTestCase{ |
| 546 | method: "StreamingAdd", |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 547 | clientStream: []interface{}{int32(3), int32(4)}, |
Todd Wang | 5ab0366 | 2015-02-19 21:03:01 -0800 | [diff] [blame] | 548 | finalResponse: vdl.Int32Value(10), |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 549 | }) |
| 550 | } |
| 551 | |
| 552 | func TestJSServerWihStreamingOutputs(t *testing.T) { |
| 553 | runJsServerTestCase(t, jsServerTestCase{ |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 554 | method: "StreamingAdd", |
| 555 | serverStream: []interface{}{int32(3), int32(4)}, |
Todd Wang | 5ab0366 | 2015-02-19 21:03:01 -0800 | [diff] [blame] | 556 | finalResponse: vdl.Int32Value(10), |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 557 | }) |
| 558 | } |
| 559 | |
| 560 | func TestJSServerWihStreamingInputsAndOutputs(t *testing.T) { |
| 561 | runJsServerTestCase(t, jsServerTestCase{ |
Benjamin Prosnitz | a2ac3b3 | 2014-12-12 11:40:31 -0800 | [diff] [blame] | 562 | method: "StreamingAdd", |
| 563 | clientStream: []interface{}{int32(1), int32(2)}, |
| 564 | serverStream: []interface{}{int32(3), int32(4)}, |
Todd Wang | 5ab0366 | 2015-02-19 21:03:01 -0800 | [diff] [blame] | 565 | finalResponse: vdl.Int32Value(10), |
Jiri Simsa | 78b646f | 2014-10-08 10:23:05 -0700 | [diff] [blame] | 566 | }) |
| 567 | } |
Nicolas LaCasse | d7ab8a1 | 2015-02-03 11:46:29 -0800 | [diff] [blame] | 568 | |
| 569 | func TestJSServerWithWrongNumberOfArgs(t *testing.T) { |
Todd Wang | b63e9eb | 2015-02-10 19:57:39 -0800 | [diff] [blame] | 570 | err := verror.New(server.ErrWrongNumberOfArgs, nil, "Add", 3, 2) |
Nicolas LaCasse | d7ab8a1 | 2015-02-03 11:46:29 -0800 | [diff] [blame] | 571 | runJsServerTestCase(t, jsServerTestCase{ |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 572 | method: "Add", |
| 573 | inArgs: []interface{}{int32(1), int32(2), int32(3)}, |
| 574 | err: err, |
Nicolas LaCasse | d7ab8a1 | 2015-02-03 11:46:29 -0800 | [diff] [blame] | 575 | }) |
| 576 | } |
| 577 | |
| 578 | func TestJSServerWithMethodNotFound(t *testing.T) { |
| 579 | methodName := "UnknownMethod" |
Todd Wang | b63e9eb | 2015-02-10 19:57:39 -0800 | [diff] [blame] | 580 | err := verror.New(server.ErrMethodNotFoundInSignature, nil, methodName) |
Nicolas LaCasse | d7ab8a1 | 2015-02-03 11:46:29 -0800 | [diff] [blame] | 581 | runJsServerTestCase(t, jsServerTestCase{ |
Benjamin Prosnitz | e8e2b9b | 2015-02-24 12:55:25 -0800 | [diff] [blame] | 582 | method: methodName, |
| 583 | inArgs: []interface{}{int32(1), int32(2)}, |
| 584 | err: err, |
Nicolas LaCasse | d7ab8a1 | 2015-02-03 11:46:29 -0800 | [diff] [blame] | 585 | }) |
| 586 | } |