From 2e6f0d60302a41c9dad486caab5d3b90434396d5 Mon Sep 17 00:00:00 2001 From: Jordan Weschler Date: Mon, 8 Jul 2024 12:06:29 -0400 Subject: [PATCH 1/7] fix failing test and added testing artifact to ignore --- .gitignore | 3 ++- fixtures/epcis/epcisquery.src | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index aa20ee5c..d3a218dc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ myservice build .DS_Store dist -.idea/ \ No newline at end of file +.idea/ +fixtures/epcis/epcisquery_gen.src diff --git a/fixtures/epcis/epcisquery.src b/fixtures/epcis/epcisquery.src index 0cd5f78c..fc9fa234 100644 --- a/fixtures/epcis/epcisquery.src +++ b/fixtures/epcis/epcisquery.src @@ -59,9 +59,11 @@ type Partner struct { } type PartnerIdentification struct { + XMLName xml.Name `xml:"http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader Identifier"` + Value string `xml:",chardata" json:"-,"` - Authority string `xml:"Authority,attr,omitempty" json:"Authority,omitempty"` + Authority string `xml:"http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader Authority,attr,omitempty" json:"Authority,omitempty"` } type ContactInformation struct { From 22b5a0cc120220e9b3e4d07251fe42c6ebbf28c3 Mon Sep 17 00:00:00 2001 From: Jordan Weschler Date: Mon, 8 Jul 2024 12:15:18 -0400 Subject: [PATCH 2/7] modified file location validation for platform independance --- location_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/location_test.go b/location_test.go index 6ce1b7a4..81be8689 100644 --- a/location_test.go +++ b/location_test.go @@ -5,6 +5,7 @@ package gowsdl import ( + "fmt" "os" "path/filepath" "testing" @@ -88,9 +89,9 @@ func TestLocation_Parse_File(t *testing.T) { ref string expected string }{ - {"fixtures/test.wsdl", "some.xsd", "fixtures/some.xsd"}, - {"fixtures/test.wsdl", "../xsd/some.xsd", "xsd/some.xsd"}, - {"fixtures/test.wsdl", "xsd/some.xsd", "fixtures/xsd/some.xsd"}, + {"fixtures/test.wsdl", "some.xsd", fmt.Sprintf("fixtures%csome.xsd", os.PathSeparator)}, + {"fixtures/test.wsdl", "../xsd/some.xsd", fmt.Sprintf("xsd%csome.xsd", os.PathSeparator)}, + {"fixtures/test.wsdl", "xsd/some.xsd", fmt.Sprintf("fixtures%cxsd%csome.xsd", os.PathSeparator, os.PathSeparator)}, } for _, test := range tests { r, err := ParseLocation(test.name) From 686642b9f7748d2336f2430801891278087dd4a7 Mon Sep 17 00:00:00 2001 From: Jordan Weschler Date: Mon, 8 Jul 2024 12:58:10 -0400 Subject: [PATCH 3/7] added cover for testing coverage --- .gitignore | 2 ++ go.mod | 5 ++++- go.sum | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d3a218dc..e866f70b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ build dist .idea/ fixtures/epcis/epcisquery_gen.src +**/cover.out +**/cover.html diff --git a/go.mod b/go.mod index b869588a..72fbd773 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module github.com/hooklift/gowsdl go 1.15 -require github.com/stretchr/testify v1.6.1 +require ( + github.com/stretchr/testify v1.6.1 + golang.org/x/tools/cmd/cover v0.1.0-deprecated // indirect +) diff --git a/go.sum b/go.sum index afe7890c..3f50daa7 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,40 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= +golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.5.1-0.20230111220935-a7f7db3f17fc h1:zRn9MzwG18RZhyanShCfUwJTcobvqw8fOjjROFN9jtM= +golang.org/x/tools v0.5.1-0.20230111220935-a7f7db3f17fc/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k= +golang.org/x/tools/cmd/cover v0.1.0-deprecated h1:Rwy+mWYz6loAF+LnG1jHG/JWMHRMMC2/1XX3Ejkx9lA= +golang.org/x/tools/cmd/cover v0.1.0-deprecated/go.mod h1:hMDiIvlpN1NoVgmjLjUJE9tMHyxHjFX7RuQ+rW12mSA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= From 1ddcf77f9ebf68366724ac4a8fbd0708ed4f3eef Mon Sep 17 00:00:00 2001 From: Jordan Weschler Date: Mon, 8 Jul 2024 14:22:36 -0400 Subject: [PATCH 4/7] added option for logger funcion pointer to enable logging the xml generated for the request --- soap/soap.go | 13 +++++++++++++ soap/soap_test.go | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/soap/soap.go b/soap/soap.go index 838a7032..6e76dc64 100644 --- a/soap/soap.go +++ b/soap/soap.go @@ -248,6 +248,7 @@ type options struct { httpHeaders map[string]string mtom bool mma bool + reqLogger func(s string) () } var defaultOptions = options{ @@ -329,6 +330,12 @@ func WithMIMEMultipartAttachments() Option { } } +func WithReqLogger(logger func (s string) ()) Option { + return func(o *options) { + o.reqLogger = logger + } +} + // Client is soap client type Client struct { url string @@ -447,6 +454,12 @@ func (s *Client) call(ctx context.Context, soapAction string, request, response return err } + if s.opts.reqLogger != nil { + buf := buffer.String() + buffer.WriteString(buf) + s.opts.reqLogger(buf) + } + req, err := http.NewRequest("POST", s.url, buffer) if err != nil { return err diff --git a/soap/soap_test.go b/soap/soap_test.go index b436df54..db7bc87a 100644 --- a/soap/soap_test.go +++ b/soap/soap_test.go @@ -66,7 +66,14 @@ func TestClient_Call(t *testing.T) { })) defer ts.Close() - client := NewClient(ts.URL) + logger := func (s string) { + wantedReq := `Hi` + if s != wantedReq { + t.Errorf("created req %s expected %s", s, wantedReq) + } + } + + client := NewClient(ts.URL, WithReqLogger(logger)) req := &Ping{Request: &PingRequest{Message: "Hi"}} reply := &PingResponse{} if err := client.Call("GetData", req, reply); err != nil { From 82817e3d6dc2ddb3c705320a6be6620ca62a8974 Mon Sep 17 00:00:00 2001 From: Jordan Weschler Date: Tue, 9 Jul 2024 09:37:20 -0400 Subject: [PATCH 5/7] modified package name --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 72fbd773..b0475bdc 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/hooklift/gowsdl +module github.com/jordanweschler/gowsdl go 1.15 From 1bf43c8f8b89553610527d5d3dc62660556c403f Mon Sep 17 00:00:00 2001 From: Jordan Weschler Date: Tue, 9 Jul 2024 10:50:33 -0400 Subject: [PATCH 6/7] logger mod --- soap/soap.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/soap/soap.go b/soap/soap.go index 6e76dc64..18f3017b 100644 --- a/soap/soap.go +++ b/soap/soap.go @@ -455,9 +455,7 @@ func (s *Client) call(ctx context.Context, soapAction string, request, response } if s.opts.reqLogger != nil { - buf := buffer.String() - buffer.WriteString(buf) - s.opts.reqLogger(buf) + s.opts.reqLogger(buffer.String()) } req, err := http.NewRequest("POST", s.url, buffer) From 0adc740cc3f3f26c366ab7db48e9258095437c0e Mon Sep 17 00:00:00 2001 From: Jordan Weschler Date: Mon, 15 Jul 2024 13:54:48 -0400 Subject: [PATCH 7/7] marshal xsddate json --- soap/xsdDateTime.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/soap/xsdDateTime.go b/soap/xsdDateTime.go index 375bdae1..f2d6506f 100644 --- a/soap/xsdDateTime.go +++ b/soap/xsdDateTime.go @@ -5,6 +5,7 @@ package soap import ( + "encoding/json" "encoding/xml" "strings" "time" @@ -185,6 +186,11 @@ func (xd XSDDate) MarshalXMLAttr(name xml.Name) (xml.Attr, error) { return attr, nil } +func (xd XSDDate) MarshalJSON() ([]byte, error) { + xdString := xd.string() + return json.Marshal(xdString) +} + // returns string representation and skips "zero" time values func (xd XSDDate) string() string { if !xd.innerDate.IsZero() {