MCPcopy
hub / github.com/TarsCloud/TarsGo / TestTarsProtocol_ResponseUnpack

Function TestTarsProtocol_ResponseUnpack

tars/protocol/tarsprotocol_test.go:124–155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

122}
123
124func TestTarsProtocol_ResponseUnpack(t *testing.T) {
125 resp := &requestf.ResponsePacket{
126 IVersion: basef.TARSVERSION,
127 CPacketType: 1,
128 IRequestId: 2,
129 IMessageType: 3,
130 IRet: 4,
131 SBuffer: []int8{1, 2, 3, 4, 5, 6, 7, 8},
132 Status: map[string]string{"hello": "tarser"},
133 SResultDesc: "succ",
134 Context: map[string]string{"hello": "tars"},
135 }
136 buf := codec.NewBuffer()
137 err := resp.WriteTo(buf)
138
139 // append package length to package header.
140 sbuf := bytes.NewBuffer(nil)
141 sbuf.Write(make([]byte, 4))
142 sbuf.Write(buf.ToBytes())
143 binary.BigEndian.PutUint32(sbuf.Bytes(), uint32(sbuf.Len()))
144 if err != nil {
145 t.Errorf("write buffer failed. got error:%v\n", err)
146 }
147 p := &TarsProtocol{}
148
149 got, err := p.ResponseUnpack(sbuf.Bytes())
150 if err != nil {
151 t.Errorf("unpack response failed. got error:%v\n", err)
152 }
153
154 assert.Equal(t, got, resp, "Failed to test ResponseUnpack")
155}

Callers

nothing calls this directly

Calls 7

WriteToMethod · 0.95
ToBytesMethod · 0.95
LenMethod · 0.95
ResponseUnpackMethod · 0.95
NewBufferFunction · 0.92
WriteMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected