1package xmlrpc
2
3import (
4	"testing"
5	"time"
6)
7
8func Test_CallWithoutArgs(t *testing.T) {
9	client := newClient(t)
10	defer client.Close()
11
12	var result time.Time
13	if err := client.Call("service.time", nil, &result); err != nil {
14		t.Fatalf("service.time call error: %v", err)
15	}
16}
17
18func Test_CallWithOneArg(t *testing.T) {
19	client := newClient(t)
20	defer client.Close()
21
22	var result string
23	if err := client.Call("service.upcase", "xmlrpc", &result); err != nil {
24		t.Fatalf("service.upcase call error: %v", err)
25	}
26
27	if result != "XMLRPC" {
28		t.Fatalf("Unexpected result of service.upcase: %s != %s", "XMLRPC", result)
29	}
30}
31
32func Test_CallWithTwoArgs(t *testing.T) {
33	client := newClient(t)
34	defer client.Close()
35
36	var sum int
37	if err := client.Call("service.sum", []interface{}{2, 3}, &sum); err != nil {
38		t.Fatalf("service.sum call error: %v", err)
39	}
40
41	if sum != 5 {
42		t.Fatalf("Unexpected result of service.sum: %d != %d", 5, sum)
43	}
44}
45
46func Test_TwoCalls(t *testing.T) {
47	client := newClient(t)
48	defer client.Close()
49
50	var upcase string
51	if err := client.Call("service.upcase", "xmlrpc", &upcase); err != nil {
52		t.Fatalf("service.upcase call error: %v", err)
53	}
54
55	var sum int
56	if err := client.Call("service.sum", []interface{}{2, 3}, &sum); err != nil {
57		t.Fatalf("service.sum call error: %v", err)
58	}
59
60}
61
62func Test_FailedCall(t *testing.T) {
63	client := newClient(t)
64	defer client.Close()
65
66	var result int
67	if err := client.Call("service.error", nil, &result); err == nil {
68		t.Fatal("expected service.error returns error, but it didn't")
69	}
70}
71
72func newClient(t *testing.T) *Client {
73	client, err := NewClient("http://localhost:5001", nil)
74	if err != nil {
75		t.Fatalf("Can't create client: %v", err)
76	}
77
78	return client
79}
80