func TestContext(t *testing.T) { ctx := context.WithValue(context.Background(), "context", "value") l := startListeningWithContext(ctx) defer l.Close() params := &Request{ A: 7, B: 8, } var r int err := jsonrpc.NewHTTPClient(createAddr(l)).Call("Arith.Context", params, &r) if err != nil { t.Fatal(err.Error()) } }
func TestSuccess(t *testing.T) { l := startListening() defer l.Close() params := &Request{ A: 7, B: 8, } var r int err := jsonrpc.NewHTTPClient(createAddr(l)).Call("Arith.Success", params, &r) if err != nil { t.Fatal(err.Error()) } if r != 56 { t.Fatalf("Expected: 56, but got: %d", r) } }
func TestFail(t *testing.T) { l := startListening() defer l.Close() params := &Request{ A: 7, B: 8, } var r int err := jsonrpc.NewHTTPClient(createAddr(l)).Call("Arith.Fail", params, &r) if err == nil { t.Fatal("Expected a non-nil err") } if err.Error() != "fail" { t.Fatalf("Expected \"fail\" as err message, but got %s", err.Error()) } if r != 0 { t.Fatalf("Expected: 0, but got: %d", r) } }