2021-09-14 19:35:45 +00:00
|
|
|
package envelope
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/xml"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestWriteRead(t *testing.T) {
|
|
|
|
type Args struct {
|
|
|
|
Foo string `xml:"foo"`
|
|
|
|
Bar string `xml:"bar"`
|
|
|
|
}
|
|
|
|
|
|
|
|
sendAction := &Action{
|
|
|
|
XMLName: xml.Name{Space: "http://example.com/namespace", Local: "MyAction"},
|
|
|
|
Args: &Args{
|
|
|
|
Foo: "foo-1",
|
|
|
|
Bar: "bar-2",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
buf := &bytes.Buffer{}
|
|
|
|
err := Write(buf, sendAction)
|
|
|
|
if err != nil {
|
2021-09-14 20:33:04 +00:00
|
|
|
t.Errorf("Write want success, got err=%v", err)
|
2021-09-14 19:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
recvAction := &Action{Args: &Args{}}
|
|
|
|
|
|
|
|
err = Read(buf, recvAction)
|
|
|
|
if err != nil {
|
2021-09-14 20:33:04 +00:00
|
|
|
t.Errorf("Read want success, got err=%v", err)
|
2021-09-14 19:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(sendAction, recvAction) {
|
|
|
|
t.Errorf("want recvAction=%+v, got %+v", sendAction, recvAction)
|
|
|
|
}
|
|
|
|
}
|