diff options
| author | Shulhan <ms@kilabit.info> | 2021-05-19 13:41:13 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2021-05-19 13:41:13 +0700 |
| commit | bd51133fbda340542ec29ec1035b028ea112e028 (patch) | |
| tree | 0e1c63bec6a061baafddc2edcd710ab2d291f157 /lib/xmlrpc/response_test.go | |
| parent | 0f2059b07661265439a20d895a7a4481ef12b4c8 (diff) | |
| download | pakakeh.go-bd51133fbda340542ec29ec1035b028ea112e028.tar.xz | |
xmlrpc: add method to marshal Response
Diffstat (limited to 'lib/xmlrpc/response_test.go')
| -rw-r--r-- | lib/xmlrpc/response_test.go | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/lib/xmlrpc/response_test.go b/lib/xmlrpc/response_test.go index 6a6f9e0f..23c61312 100644 --- a/lib/xmlrpc/response_test.go +++ b/lib/xmlrpc/response_test.go @@ -5,12 +5,60 @@ package xmlrpc import ( + "encoding/xml" "testing" "github.com/shuLhan/share/lib/test" ) -func TestResponse(t *testing.T) { +func TestResponse_MarshalText(t *testing.T) { + cases := []struct { + desc string + resp *Response + exp string + }{{ + desc: "With param", + resp: &Response{ + Param: &Value{ + Kind: Boolean, + In: true, + }, + }, + exp: xml.Header + `<methodResponse><params><param><value><boolean>true</boolean></value></param></params></methodResponse>`, + }, { + desc: "With fault", + resp: &Response{ + FaultCode: 404, + FaultMessage: "Not found", + IsFault: true, + }, + exp: xml.Header + `<methodResponse>` + + `<fault><value><struct>` + + `<member>` + + `<name>faultCode</name>` + + `<value><int>404</int></value>` + + `</member>` + + `<member>` + + `<name>faultString</name>` + + `<value><string>Not found</string></value>` + + `</member>` + + `</struct></value></fault>` + + `</methodResponse>`, + }} + + for _, c := range cases { + t.Logf(c.desc) + + got, err := c.resp.MarshalText() + if err != nil { + t.Fatal(err) + } + + test.Assert(t, "MarshalText", c.exp, string(got)) + } +} + +func TestResponse_UnmarshalText(t *testing.T) { cases := []struct { desc string text string @@ -91,6 +139,8 @@ func TestResponse(t *testing.T) { }} for _, c := range cases { + t.Logf(c.desc) + var got Response err := got.UnmarshalText([]byte(c.text)) |
