コード例 #1
0
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())
	}
}
コード例 #2
0
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)
	}
}
コード例 #3
0
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)
	}
}