diff --git a/response.go b/response.go index 070fc9d..e11682a 100644 --- a/response.go +++ b/response.go @@ -26,8 +26,9 @@ func (e FaultError) Error() string { } // IsFault returns whether the given error is a fault error or not. -// NOTE: IsFault will return false when the error could not be typecasted to FaultError, because -// every fault error will have it's dynamic type as FaultError. +// +// IsFault will return false when the error could not be typecasted to FaultError, because +// every fault error should have it's dynamic type as FaultError. func IsFault(err error) bool { if _, ok := err.(FaultError); !ok { return false diff --git a/wsdl.go b/wsdl.go index e0fae5f..ef98794 100644 --- a/wsdl.go +++ b/wsdl.go @@ -212,6 +212,7 @@ func (wsdl *wsdlDefinitions) GetSoapActionFromWsdlOperation(operation string) st } // Fault response +// Fault implements Stringer interface type Fault struct { Code string `xml:"faultcode"` Description string `xml:"faultstring"` diff --git a/wsdl_test.go b/wsdl_test.go index d230b6a..7780f90 100644 --- a/wsdl_test.go +++ b/wsdl_test.go @@ -6,6 +6,8 @@ import ( "runtime" "strings" "testing" + + "gotest.tools/assert" ) func Test_getWsdlBody(t *testing.T) { @@ -66,3 +68,27 @@ func Test_getWsdlBody(t *testing.T) { }) } } + +func TestFaultString(t *testing.T) { + var testCases = []struct { + description string + fault *Fault + expectedFaultStr string + }{ + { + description: "success case: fault string", + fault: &Fault{ + Code: "soap:SERVER", + Description: "soap exception", + }, + expectedFaultStr: "[soap:SERVER]: soap exception", + }, + } + + for _, testCase := range testCases { + t.Logf("running %v testCase", testCase.description) + + faultStr := testCase.fault.String() + assert.Equal(t, testCase.expectedFaultStr, faultStr) + } +}