MCPcopy Create free account
hub / github.com/datastax/cql-proxy / TestPartialBatchCodec_Decode

Function TestPartialBatchCodec_Decode

codecs/partial_codecs_test.go:301–344  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

299}
300
301func TestPartialBatchCodec_Decode(t *testing.T) {
302 localSerialConsistency := primitive.ConsistencyLevelLocalSerial
303 codec := &partialBatchCodec{}
304
305 msg := &message.Batch{
306 Type: primitive.BatchTypeLogged,
307 Children: []*message.BatchChild{
308 {
309 Query: "SELECT * FROM table WHERE id = ?",
310 Values: []*primitive.Value{
311 {Type: primitive.ValueTypeRegular, Contents: []byte{0x01, 0x02, 0x03}},
312 {Type: primitive.ValueTypeNull},
313 },
314 },
315 {Id: []byte{0x01, 0x02, 0x03}},
316 },
317 Consistency: primitive.ConsistencyLevelQuorum,
318 SerialConsistency: &localSerialConsistency,
319 }
320
321 var buf bytes.Buffer
322
323 err := builtinBatchCodec.Encode(msg, &buf, primitive.ProtocolVersion4)
324 require.NoError(t, err)
325
326 batch, err := codec.Decode(NewFrameBodyReader(buf.Bytes()), primitive.ProtocolVersion4)
327 require.NoError(t, err)
328
329 assert.False(t, batch.IsResponse())
330 assert.Equal(t, primitive.OpCodeBatch, batch.GetOpCode())
331 assert.Equal(t, fmt.Sprintf("BATCH (%d statements)", len(msg.Children)), batch.(*PartialBatch).String())
332
333 require.Len(t, batch.(*PartialBatch).Queries, 2)
334 assert.Equal(t, "SELECT * FROM table WHERE id = ?", batch.(*PartialBatch).Queries[0].QueryOrId)
335 assert.Equal(t, []byte{0x0, 0x2, 0x0, 0x0, 0x0, 0x3, 0x1, 0x2, 0x3, 0xff, 0xff, 0xff, 0xff},
336 batch.(*PartialBatch).Queries[0].Values)
337
338 assert.Equal(t, []byte{0x1, 0x2, 0x3}, batch.(*PartialBatch).Queries[1].QueryOrId)
339 assert.Equal(t, []byte{0x0, 0x0}, batch.(*PartialBatch).Queries[1].Values)
340
341 assert.Equal(t, msg.Type, batch.(*PartialBatch).Type)
342 assert.Equal(t, msg.Consistency, batch.(*PartialBatch).Consistency)
343 assert.Equal(t, []byte{0x10, 0x0, 0x9}, batch.(*PartialBatch).Parameters)
344}
345
346func TestPartialBatchCodec_Decode_Invalid(t *testing.T) {
347 tests := []struct {

Callers

nothing calls this directly

Calls 6

DecodeMethod · 0.95
NewFrameBodyReaderFunction · 0.85
EncodeMethod · 0.45
IsResponseMethod · 0.45
GetOpCodeMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected