-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from RealImage/enhance/unmarhsal-error
Addresses issue - [Differentiate fault and response unmarshal error]
- Loading branch information
Showing
6 changed files
with
203 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
module github.com/tiaguinho/gosoap | ||
|
||
require ( | ||
github.com/google/go-cmp v0.5.0 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 | ||
golang.org/x/text v0.3.2 // indirect | ||
gotest.tools v2.2.0+incompatible | ||
) | ||
|
||
go 1.13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package gosoap | ||
|
||
import ( | ||
"encoding/xml" | ||
"fmt" | ||
"testing" | ||
|
||
"gotest.tools/assert" | ||
) | ||
|
||
func TestUnmarshal(t *testing.T) { | ||
var testCases = []struct { | ||
description string | ||
response *Response | ||
decodeStruct interface{} | ||
isFaultError bool | ||
}{ | ||
{ | ||
description: "case: fault error", | ||
response: &Response{ | ||
Body: []byte(` | ||
<soap:Fault> | ||
<faultcode>soap:Server</faultcode> | ||
<faultstring>Qube.Mama.SoapException: The remote server returned an error: (550) File unavailable (e.g., file not found, no access). | ||
The remote server returned an error: (550) File unavailable (e.g., file not found, no access). | ||
</faultstring> | ||
<detail> | ||
</detail> | ||
</soap:Fault> | ||
`), | ||
}, | ||
decodeStruct: &struct{}{}, | ||
isFaultError: true, | ||
}, | ||
{ | ||
description: "case: unmarshal error", | ||
response: &Response{ | ||
Body: []byte(` | ||
<GetJobsByIdsResponse | ||
xmlns="http://webservices.qubecinema.com/XP/Usher/2009-09-29/"> | ||
<GetJobsByIdsResult> | ||
<JobInfo> | ||
<ID>9e7d58d9-6f62-43e3-b189-5b1b58eea629</ID> | ||
<Status>Completed</Status> | ||
<Progress>0</Progress> | ||
<VerificationProgress>0</VerificationProgress> | ||
<EstimatedCompletionTime>0</EstimatedCompletionTime> | ||
</JobInfo> | ||
</GetJobsByIdsResult> | ||
</GetJobsByIdsResponse> | ||
`), | ||
}, | ||
decodeStruct: &struct { | ||
XMLName xml.Name `xml:"GetJobsByIsResponse"` | ||
GetJobsByIDsResult string | ||
}{}, | ||
isFaultError: false, | ||
}, | ||
{ | ||
description: "case: nil error", | ||
response: &Response{ | ||
Body: []byte(` | ||
<GetJobsByIdsResponse | ||
xmlns="http://webservices.qubecinema.com/XP/Usher/2009-09-29/"> | ||
<GetJobsByIdsResult> | ||
<JobInfo> | ||
<ID>9e7d58d9-6f62-43e3-b189-5b1b58eea629</ID> | ||
<Status>Completed</Status> | ||
<Progress>0</Progress> | ||
<VerificationProgress>0</VerificationProgress> | ||
<EstimatedCompletionTime>0</EstimatedCompletionTime> | ||
</JobInfo> | ||
</GetJobsByIdsResult> | ||
</GetJobsByIdsResponse> | ||
`), | ||
}, | ||
decodeStruct: &struct { | ||
XMLName xml.Name `xml:"GetJobsByIdsResponse"` | ||
GetJobsByIDsResult string | ||
}{}, | ||
isFaultError: false, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
t.Logf("running %v test case", testCase.description) | ||
|
||
err := testCase.response.Unmarshal(testCase.decodeStruct) | ||
assert.Equal(t, testCase.isFaultError, IsFault(err)) | ||
} | ||
} | ||
|
||
func TestIsFault(t *testing.T) { | ||
var testCases = []struct { | ||
description string | ||
err error | ||
expectedIsFaultError bool | ||
}{ | ||
{ | ||
description: "case: fault error", | ||
err: FaultError{ | ||
fault: &Fault{ | ||
Code: "SOAP-ENV:Client", | ||
}, | ||
}, | ||
expectedIsFaultError: true, | ||
}, | ||
{ | ||
description: "case: unmarshal error", | ||
err: fmt.Errorf("unmarshall err: .."), | ||
expectedIsFaultError: false, | ||
}, | ||
{ | ||
description: "case: nil error", | ||
err: nil, | ||
expectedIsFaultError: false, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
t.Logf("running %v test case", testCase.description) | ||
|
||
isFaultErr := IsFault(testCase.err) | ||
assert.Equal(t, testCase.expectedIsFaultError, isFaultErr) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters