From 0e9601511421ffb8781087e5bc8bf9075fc29f55 Mon Sep 17 00:00:00 2001 From: Sergio Marin Date: Mon, 9 Dec 2019 09:20:29 -0300 Subject: [PATCH 01/14] Add http client to sopa initialization --- encode_test.go | 2 +- go.mod | 2 ++ request.go | 5 ++++- response.go | 2 +- soap.go | 23 +++++++++++++++-------- soap_test.go | 45 +++++++++++++++++++++++++++++++++++---------- wsdl.go | 11 +++++++---- wsdl_test.go | 2 +- 8 files changed, 66 insertions(+), 26 deletions(-) diff --git a/encode_test.go b/encode_test.go index 3479a14..dd373cb 100644 --- a/encode_test.go +++ b/encode_test.go @@ -17,7 +17,7 @@ var ( ) func TestClient_MarshalXML(t *testing.T) { - soap, err := SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl") + soap, err := SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl", nil) if err != nil { t.Errorf("error not expected: %s", err) } diff --git a/go.mod b/go.mod index 9feb501..beaff6c 100644 --- a/go.mod +++ b/go.mod @@ -4,3 +4,5 @@ require ( golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3 golang.org/x/text v0.3.0 // indirect ) + +go 1.13 diff --git a/request.go b/request.go index f4d894c..f159560 100644 --- a/request.go +++ b/request.go @@ -4,12 +4,13 @@ import ( "fmt" ) -// Soap Request +// Request Soap Request type Request struct { Method string Params Params } +// NewRequest creates a new soap request func NewRequest(m string, p Params) *Request { return &Request{ Method: m, @@ -17,10 +18,12 @@ func NewRequest(m string, p Params) *Request { } } +// RequestStruct soap request interface type RequestStruct interface { SoapBuildRequest() *Request } +// NewRequestByStruct create a new request using builder func NewRequestByStruct(s RequestStruct) (*Request, error) { if s == nil { return nil, fmt.Errorf("'s' cannot be 'nil'") diff --git a/response.go b/response.go index 6f5adca..e68a15e 100644 --- a/response.go +++ b/response.go @@ -5,7 +5,7 @@ import ( "fmt" ) -// Soap Response +// Response Soap Response type Response struct { Body []byte Header []byte diff --git a/soap.go b/soap.go index ab4932f..432b96b 100644 --- a/soap.go +++ b/soap.go @@ -22,15 +22,19 @@ type HeaderParams map[string]interface{} type Params map[string]interface{} // SoapClient return new *Client to handle the requests with the WSDL -func SoapClient(wsdl string) (*Client, error) { +func SoapClient(wsdl string, httpClient *http.Client) (*Client, error) { _, err := url.Parse(wsdl) if err != nil { return nil, err } + if httpClient == nil { + httpClient = &http.Client{} + } + c := &Client{ wsdl: wsdl, - HttpClient: &http.Client{}, + HTTPClient: httpClient, } return c, nil @@ -39,7 +43,7 @@ func SoapClient(wsdl string) (*Client, error) { // Client struct hold all the informations about WSDL, // request and response of the server type Client struct { - HttpClient *http.Client + HTTPClient *http.Client URL string HeaderName string HeaderParams HeaderParams @@ -61,7 +65,7 @@ func (c *Client) Call(m string, p Params) (res *Response, err error) { return c.Do(NewRequest(m, p)) } -// Call call's by struct +// CallByStruct call's by struct func (c *Client) CallByStruct(s RequestStruct) (res *Response, err error) { req, err := NewRequestByStruct(s) if err != nil { @@ -82,12 +86,13 @@ func (c *Client) waitAndRefreshDefinitions(d time.Duration) { } func (c *Client) initWsdl() { - c.Definitions, c.definitionsErr = getWsdlDefinitions(c.wsdl) + c.Definitions, c.definitionsErr = getWsdlDefinitions(c.wsdl, c.HTTPClient) if c.definitionsErr == nil { c.URL = strings.TrimSuffix(c.Definitions.TargetNamespace, "/") } } +// SetWSDL set WSDL url func (c *Client) SetWSDL(wsdl string) { c.onRequest.Wait() c.onDefinitionsRefresh.Wait() @@ -99,7 +104,7 @@ func (c *Client) SetWSDL(wsdl string) { c.initWsdl() } -// Process Soap Request +// Do Process Soap Request func (c *Client) Do(req *Request) (res *Response, err error) { c.onDefinitionsRefresh.Wait() c.onRequest.Add(1) @@ -202,17 +207,19 @@ func (p *process) doRequest(url string) ([]byte, error) { } func (p *process) httpClient() *http.Client { - if p.Client.HttpClient != nil { - return p.Client.HttpClient + if p.Client.HTTPClient != nil { + return p.Client.HTTPClient } return http.DefaultClient } +// ErrorWithPayload error payload schema type ErrorWithPayload struct { error Payload []byte } +// GetPayloadFromError returns the payload of a ErrorWithPayload func GetPayloadFromError(err error) []byte { if err, ok := err.(ErrorWithPayload); ok { return err.Payload diff --git a/soap_test.go b/soap_test.go index 0664fe5..3361db6 100644 --- a/soap_test.go +++ b/soap_test.go @@ -1,14 +1,16 @@ package gosoap import ( + "crypto/tls" "net/http" "testing" ) var ( scts = []struct { - URL string - Err bool + URL string + Err bool + Client *http.Client }{ { URL: "://www.server", @@ -22,18 +24,41 @@ var ( URL: "http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl", Err: true, }, + { + URL: "http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl", + Err: true, + Client: &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + }, + }, + }, } ) func TestSoapClient(t *testing.T) { for _, sct := range scts { - _, err := SoapClient(sct.URL) + _, err := SoapClient(sct.URL, nil) if err != nil && sct.Err { t.Errorf("URL: %s - error: %s", sct.URL, err) } } } +func TestSoapClienWithClient(t *testing.T) { + client, err := SoapClient(scts[3].URL, scts[3].Client) + + if client.HTTPClient != scts[3].Client { + t.Errorf("HTTP client is not the same as in initialization: - error: %s", err) + } + + if err != nil { + t.Errorf("URL: %s - error: %s", scts[3].URL, err) + } +} + type CheckVatRequest struct { CountryCode string VatNumber string @@ -77,7 +102,7 @@ var ( ) func TestClient_Call(t *testing.T) { - soap, err := SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl") + soap, err := SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl", nil) if err != nil { t.Errorf("error not expected: %s", err) } @@ -105,7 +130,7 @@ func TestClient_Call(t *testing.T) { t.Errorf("error: %+v", rv) } - soap, err = SoapClient("http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL") + soap, err = SoapClient("http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL", nil) if err != nil { t.Errorf("error not expected: %s", err) } @@ -121,7 +146,7 @@ func TestClient_Call(t *testing.T) { t.Errorf("error: %+v", rc) } - soap, err = SoapClient("http://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL") + soap, err = SoapClient("http://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL", nil) if err != nil { t.Errorf("error not expected: %s", err) } @@ -137,7 +162,7 @@ func TestClient_Call(t *testing.T) { t.Errorf("error: %+v", rn) } - soap, err = SoapClient("https://domains.livedns.co.il/API/DomainsAPI.asmx?WSDL") + soap, err = SoapClient("https://domains.livedns.co.il/API/DomainsAPI.asmx?WSDL", nil) if err != nil { t.Errorf("error not expected: %s", err) } @@ -168,7 +193,7 @@ func TestClient_Call(t *testing.T) { } func TestClient_CallByStruct(t *testing.T) { - soap, err := SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl") + soap, err := SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl", nil) if err != nil { t.Errorf("error not expected: %s", err) } @@ -190,7 +215,7 @@ func TestClient_CallByStruct(t *testing.T) { } func TestClient_Call_NonUtf8(t *testing.T) { - soap, err := SoapClient("https://demo.ilias.de/webservice/soap/server.php?wsdl") + soap, err := SoapClient("https://demo.ilias.de/webservice/soap/server.php?wsdl", nil) if err != nil { t.Errorf("error not expected: %s", err) } @@ -204,7 +229,7 @@ func TestClient_Call_NonUtf8(t *testing.T) { func TestProcess_doRequest(t *testing.T) { c := &process{ Client: &Client{ - HttpClient: &http.Client{}, + HTTPClient: &http.Client{}, }, } diff --git a/wsdl.go b/wsdl.go index 3e7bc85..2f2dbf7 100644 --- a/wsdl.go +++ b/wsdl.go @@ -155,7 +155,7 @@ type xsdMaxInclusive struct { Value string `xml:"value,attr"` } -func getWsdlBody(u string) (reader io.ReadCloser, err error) { +func getWsdlBody(u string, httpClient *http.Client) (reader io.ReadCloser, err error) { parse, err := url.Parse(u) if err != nil { return nil, err @@ -167,7 +167,10 @@ func getWsdlBody(u string) (reader io.ReadCloser, err error) { } return outFile, nil } - r, err := http.Get(u) + if httpClient == nil { + httpClient = &http.Client{} + } + r, err := httpClient.Get(u) if err != nil { return nil, err } @@ -175,8 +178,8 @@ func getWsdlBody(u string) (reader io.ReadCloser, err error) { } // getWsdlDefinitions sent request to the wsdl url and set definitions on struct -func getWsdlDefinitions(u string) (wsdl *wsdlDefinitions, err error) { - reader, err := getWsdlBody(u) +func getWsdlDefinitions(u string, httpClient *http.Client) (wsdl *wsdlDefinitions, err error) { + reader, err := getWsdlBody(u, httpClient) if err != nil { return nil, err } diff --git a/wsdl_test.go b/wsdl_test.go index c826592..7d411f2 100644 --- a/wsdl_test.go +++ b/wsdl_test.go @@ -49,7 +49,7 @@ func Test_getWsdlBody(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - _, err := getWsdlBody(tt.args.u) + _, err := getWsdlBody(tt.args.u, nil) if (err != nil) != tt.wantErr { t.Errorf("getwsdlBody() error = %v, wantErr %v", err, tt.wantErr) return From eb866f88065e111c620101599818433a5d8e5a8d Mon Sep 17 00:00:00 2001 From: Sergio Marin Date: Wed, 11 Dec 2019 12:37:55 -0300 Subject: [PATCH 02/14] Correct Soap Action to add service name to the url --- soap.go | 2 +- wsdl.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/soap.go b/soap.go index 432b96b..dd67a1e 100644 --- a/soap.go +++ b/soap.go @@ -137,7 +137,7 @@ func (c *Client) Do(req *Request) (res *Response, err error) { } if p.SoapAction == "" { - p.SoapAction = fmt.Sprintf("%s/%s", c.URL, req.Method) + p.SoapAction = fmt.Sprintf("%s/%s/%s", c.URL, c.Definitions.Services[0].Name, req.Method) } p.Payload, err = xml.MarshalIndent(p, "", " ") diff --git a/wsdl.go b/wsdl.go index 2f2dbf7..888b8d8 100644 --- a/wsdl.go +++ b/wsdl.go @@ -2,11 +2,12 @@ package gosoap import ( "encoding/xml" - "golang.org/x/net/html/charset" "io" "net/http" "net/url" "os" + + "golang.org/x/net/html/charset" ) type wsdlDefinitions struct { From e59976287ccac163d81ef155a24a99cde3ccc1f6 Mon Sep 17 00:00:00 2001 From: Sergio Marin Date: Wed, 11 Dec 2019 12:42:51 -0300 Subject: [PATCH 03/14] Update dependencies --- go.mod | 4 ++-- go.sum | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index beaff6c..716cd3d 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,8 @@ module github.com/tiaguinho/gosoap require ( - golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3 - golang.org/x/text v0.3.0 // indirect + golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 + golang.org/x/text v0.3.2 // indirect ) go 1.13 diff --git a/go.sum b/go.sum index d586547..9943afc 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,11 @@ +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3 h1:ulvT7fqt0yHWzpJwI57MezWnYDVpCAYBVuYst/L+fAY= golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= From 2b21227191843ba58b0019956b4f34c496625963 Mon Sep 17 00:00:00 2001 From: Sergio Marin Date: Wed, 11 Dec 2019 13:01:32 -0300 Subject: [PATCH 04/14] WS name space to operation --- encode.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/encode.go b/encode.go index 19ff2d6..1e0269a 100644 --- a/encode.go +++ b/encode.go @@ -170,10 +170,10 @@ func (tokens *tokenData) startBody(m, n string) error { r := xml.StartElement{ Name: xml.Name{ Space: "", - Local: m, + Local: "ws:" + m, }, Attr: []xml.Attr{ - {Name: xml.Name{Space: "", Local: "xmlns"}, Value: n}, + {Name: xml.Name{Space: "", Local: "xmlns:ws"}, Value: n}, }, } @@ -194,7 +194,7 @@ func (tokens *tokenData) endBody(m string) { r := xml.EndElement{ Name: xml.Name{ Space: "", - Local: m, + Local: "ws:" + m, }, } From b5821b8977bd0390e3d3d312307d2a50616fbd8e Mon Sep 17 00:00:00 2001 From: Sergio Marin Date: Wed, 11 Dec 2019 13:18:22 -0300 Subject: [PATCH 05/14] Remove SOAPAction header --- soap.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/soap.go b/soap.go index dd67a1e..b4aa959 100644 --- a/soap.go +++ b/soap.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/xml" "errors" - "fmt" "io/ioutil" "net/http" "net/url" @@ -136,9 +135,9 @@ func (c *Client) Do(req *Request) (res *Response, err error) { SoapAction: c.Definitions.GetSoapActionFromWsdlOperation(req.Method), } - if p.SoapAction == "" { - p.SoapAction = fmt.Sprintf("%s/%s/%s", c.URL, c.Definitions.Services[0].Name, req.Method) - } + // if p.SoapAction == "" { + // p.SoapAction = fmt.Sprintf("%s/%s/%s", c.URL, c.Definitions.Services[0].Name, req.Method) + // } p.Payload, err = xml.MarshalIndent(p, "", " ") if err != nil { From a7474541305ebe6d288abea026074ebaed6b9b86 Mon Sep 17 00:00:00 2001 From: Sergio Marin Date: Wed, 11 Dec 2019 13:25:38 -0300 Subject: [PATCH 06/14] SoapAction header auto generate configuration --- soap.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/soap.go b/soap.go index b4aa959..8f4b728 100644 --- a/soap.go +++ b/soap.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/xml" "errors" + "fmt" "io/ioutil" "net/http" "net/url" @@ -34,6 +35,7 @@ func SoapClient(wsdl string, httpClient *http.Client) (*Client, error) { c := &Client{ wsdl: wsdl, HTTPClient: httpClient, + AutoAction: false, } return c, nil @@ -43,6 +45,7 @@ func SoapClient(wsdl string, httpClient *http.Client) (*Client, error) { // request and response of the server type Client struct { HTTPClient *http.Client + AutoAction bool URL string HeaderName string HeaderParams HeaderParams @@ -135,9 +138,9 @@ func (c *Client) Do(req *Request) (res *Response, err error) { SoapAction: c.Definitions.GetSoapActionFromWsdlOperation(req.Method), } - // if p.SoapAction == "" { - // p.SoapAction = fmt.Sprintf("%s/%s/%s", c.URL, c.Definitions.Services[0].Name, req.Method) - // } + if p.SoapAction == "" && c.AutoAction { + p.SoapAction = fmt.Sprintf("%s/%s/%s", c.URL, c.Definitions.Services[0].Name, req.Method) + } p.Payload, err = xml.MarshalIndent(p, "", " ") if err != nil { From 2102ad958938dce6220682eda236d5f406e7b350 Mon Sep 17 00:00:00 2001 From: Sergio Marin Date: Wed, 18 Dec 2019 20:46:06 -0300 Subject: [PATCH 07/14] Remove unnecesary namespacing --- encode.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/encode.go b/encode.go index 1e0269a..48ca70e 100644 --- a/encode.go +++ b/encode.go @@ -154,7 +154,6 @@ func (tokens *tokenData) endHeader(m string) { tokens.data = append(tokens.data, r, h) } -// startToken initiate body of the envelope func (tokens *tokenData) startBody(m, n string) error { b := xml.StartElement{ Name: xml.Name{ @@ -170,10 +169,10 @@ func (tokens *tokenData) startBody(m, n string) error { r := xml.StartElement{ Name: xml.Name{ Space: "", - Local: "ws:" + m, + Local: m, }, Attr: []xml.Attr{ - {Name: xml.Name{Space: "", Local: "xmlns:ws"}, Value: n}, + {Name: xml.Name{Space: "", Local: "xmlns"}, Value: n}, }, } @@ -194,7 +193,7 @@ func (tokens *tokenData) endBody(m string) { r := xml.EndElement{ Name: xml.Name{ Space: "", - Local: "ws:" + m, + Local: m, }, } From 91f31675f1bf199087ad999ad6f9a18974e59508 Mon Sep 17 00:00:00 2001 From: WeizhongTu Date: Thu, 16 Apr 2020 13:27:15 +0800 Subject: [PATCH 08/14] support array --- encode.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/encode.go b/encode.go index 19ff2d6..3004db1 100644 --- a/encode.go +++ b/encode.go @@ -70,6 +70,20 @@ func (tokens *tokenData) recursiveEncode(hm interface{}) { for i := 0; i < v.Len(); i++ { tokens.recursiveEncode(v.Index(i).Interface()) } + case reflect.Array: + if v.Len() == 2 { + label:=v.Index(0).Interface() + t := xml.StartElement{ + Name: xml.Name{ + Space: "", + Local: label.(string), + }, + } + + tokens.data = append(tokens.data, t) + tokens.recursiveEncode(v.Index(1).Interface()) + tokens.data = append(tokens.data, xml.EndElement{Name: t.Name}) + } case reflect.String: content := xml.CharData(v.String()) tokens.data = append(tokens.data, content) From aed9af2fbfed56aff9bc69bc064552915f66e367 Mon Sep 17 00:00:00 2001 From: WeizhongTu Date: Thu, 16 Apr 2020 13:30:49 +0800 Subject: [PATCH 09/14] soap param interface --- soap.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/soap.go b/soap.go index ab4932f..20a5d71 100644 --- a/soap.go +++ b/soap.go @@ -19,7 +19,9 @@ import ( type HeaderParams map[string]interface{} // Params type is used to set the params in soap request +type SoapParams interface {} type Params map[string]interface{} +type ArrayParams [][2]interface{} // SoapClient return new *Client to handle the requests with the WSDL func SoapClient(wsdl string) (*Client, error) { @@ -57,7 +59,7 @@ type Client struct { } // Call call's the method m with Params p -func (c *Client) Call(m string, p Params) (res *Response, err error) { +func (c *Client) Call(m string, p SoapParams) (res *Response, err error) { return c.Do(NewRequest(m, p)) } From b962894bc9198f7383e9d732351e3eebb1665e91 Mon Sep 17 00:00:00 2001 From: WeizhongTu Date: Thu, 16 Apr 2020 13:31:27 +0800 Subject: [PATCH 10/14] soap param interface --- request.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/request.go b/request.go index f4d894c..9f6d2c1 100644 --- a/request.go +++ b/request.go @@ -7,10 +7,10 @@ import ( // Soap Request type Request struct { Method string - Params Params + Params SoapParams } -func NewRequest(m string, p Params) *Request { +func NewRequest(m string, p SoapParams) *Request { return &Request{ Method: m, Params: p, From 465a3c6677c0a1ba9c42ae5809ab07480bae0d74 Mon Sep 17 00:00:00 2001 From: WeizhongTu Date: Thu, 16 Apr 2020 13:35:44 +0800 Subject: [PATCH 11/14] update doc --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7aeed98..b33af5c 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,8 @@ func main() { if err != nil { log.Fatalf("SoapClient error: %s", err) } - + + // Use gosoap.ArrayParams to support fixed position params params := gosoap.Params{ "sIp": "8.8.8.8", } From 6948ffaee027cd3921218149dcb4eceac211edcc Mon Sep 17 00:00:00 2001 From: WeizhongTu Date: Thu, 16 Apr 2020 19:02:49 +0800 Subject: [PATCH 12/14] add array params encode test --- encode_test.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/encode_test.go b/encode_test.go index 3479a14..fd1b592 100644 --- a/encode_test.go +++ b/encode_test.go @@ -5,7 +5,7 @@ import ( ) var ( - tests = []struct { + mapParamsTests = []struct { Params Params Err string }{ @@ -14,6 +14,16 @@ var ( Err: "error expected: xml: start tag with no name", }, } + + arrayParamsTests = []struct { + Params ArrayParams + Err string + }{ + { + Params: ArrayParams{{"", ""}}, + Err: "error expected: xml: start tag with no name", + }, + } ) func TestClient_MarshalXML(t *testing.T) { @@ -22,7 +32,21 @@ func TestClient_MarshalXML(t *testing.T) { t.Errorf("error not expected: %s", err) } - for _, test := range tests { + for _, test := range mapParamsTests { + _, err = soap.Call("checkVat", test.Params) + if err == nil { + t.Errorf(test.Err) + } + } +} + +func TestClient_MarshalXML2(t *testing.T) { + soap, err := SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl") + if err != nil { + t.Errorf("error not expected: %s", err) + } + + for _, test := range arrayParamsTests { _, err = soap.Call("checkVat", test.Params) if err == nil { t.Errorf(test.Err) From 5885597e085ef7eab9b344461321cc10dec9443a Mon Sep 17 00:00:00 2001 From: WeizhongTu Date: Tue, 21 Apr 2020 11:57:05 +0800 Subject: [PATCH 13/14] format --- encode.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/encode.go b/encode.go index 3004db1..671ee54 100644 --- a/encode.go +++ b/encode.go @@ -72,7 +72,7 @@ func (tokens *tokenData) recursiveEncode(hm interface{}) { } case reflect.Array: if v.Len() == 2 { - label:=v.Index(0).Interface() + label := v.Index(0).Interface() t := xml.StartElement{ Name: xml.Name{ Space: "", From 02a2bdbf2bcea09d356abca764e7891b35250cf6 Mon Sep 17 00:00:00 2001 From: Santiago De la Cruz <51337247+xhit@users.noreply.github.com> Date: Fri, 1 May 2020 10:58:23 -0400 Subject: [PATCH 14/14] Make test happy on Windows on windows, os.Getwd() returns backslash (\) instead slash (/) for path separator, replacing the backslash for slash make the test happy on windows --- wsdl_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/wsdl_test.go b/wsdl_test.go index c826592..55e4f6e 100644 --- a/wsdl_test.go +++ b/wsdl_test.go @@ -3,6 +3,8 @@ package gosoap import ( "fmt" "os" + "runtime" + "strings" "testing" ) @@ -11,6 +13,13 @@ func Test_getWsdlBody(t *testing.T) { u string } dir, _ := os.Getwd() + + // in windows, os.Getwd() returns backslash (\) instead slash (/) for path separator + // replacing the backslash for slash make the test happy on Windows + if runtime.GOOS == "windows" { + dir = strings.ReplaceAll(dir, `\`, "/") + } + tests := []struct { name string args args