forked from tiaguinho/gosoap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoap_test.go
113 lines (94 loc) · 1.78 KB
/
soap_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package gosoap
import (
"testing"
)
var (
scts = []struct {
URL string
Err bool
}{
{
URL: "://www.server",
Err: false,
},
{
URL: "",
Err: false,
},
{
URL: "http://www.webservicex.net/geoipservice.asmx?WSDL",
Err: true,
},
}
)
func TestSoapClient(t *testing.T) {
for _, sct := range scts {
_, err := SoapClient(sct.URL)
if err != nil && sct.Err {
t.Errorf("URL: %s - error: %s", sct.URL, err)
}
}
}
type GetGeoIPResponse struct {
GetGeoIPResult GetGeoIPResult
}
type GetGeoIPResult struct {
ReturnCode string
IP string
ReturnCodeDetails string
CountryName string
CountryCode string
}
var (
r GetGeoIPResponse
params = Params{}
)
func TestClient_Call(t *testing.T) {
soap, err := SoapClient("http://www.webservicex.net/geoipservice.asmx?WSDL")
if err != nil {
t.Errorf("error not expected: %s", err)
}
err = soap.Call("GetGeoIP", params)
if err == nil {
t.Errorf("params is empty")
}
params["IPAddress"] = "8.8.8.8"
err = soap.Call("", params)
if err == nil {
t.Errorf("method is empty")
}
err = soap.Unmarshal(&r)
if err == nil {
t.Errorf("body is empty")
}
err = soap.Call("GetGeoIP", params)
if err != nil {
t.Errorf("error in soap call: %s", err)
}
soap.Unmarshal(&r)
if r.GetGeoIPResult.CountryCode != "USA" {
t.Errorf("error: %+v", r)
}
c := &Client{}
err = c.Call("", Params{})
if err == nil {
t.Errorf("error expected but nothing got.")
}
c.WSDL = "://test."
err = c.Call("GetGeoIP", params)
if err == nil {
t.Errorf("invalid WSDL")
}
}
func TestClient_doRequest(t *testing.T) {
c := &Client{}
_, err := c.doRequest()
if err == nil {
t.Errorf("body is empty")
}
c.WSDL = "://teste."
_, err = c.doRequest()
if err == nil {
t.Errorf("invalid WSDL")
}
}