MCPcopy Create free account
hub / github.com/IBM/sarama / TestRealFlexibleDecoderGetNullableInt32Array

Function TestRealFlexibleDecoderGetNullableInt32Array

real_decoder_test.go:143–189  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

141}
142
143func TestRealFlexibleDecoderGetNullableInt32Array(t *testing.T) {
144 tests := []struct {
145 name string
146 input []byte
147 want []int32
148 wantErr error
149 }{
150 {
151 name: "null array",
152 input: []byte{0x00},
153 },
154 {
155 name: "empty array",
156 input: []byte{0x01},
157 want: []int32{},
158 },
159 {
160 name: "valid array",
161 input: []byte{0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02},
162 want: []int32{1, 2},
163 },
164 {
165 name: "insufficient data",
166 input: []byte{0x03},
167 wantErr: ErrInsufficientData,
168 },
169 }
170
171 for _, tt := range tests {
172 t.Run(tt.name, func(t *testing.T) {
173 rd := &realFlexibleDecoder{&realDecoder{raw: tt.input}}
174 got, err := rd.getNullableInt32Array()
175 require.ErrorIs(t, err, tt.wantErr)
176 assert.Equal(t, tt.want, got)
177 })
178 }
179 t.Run("returns insufficient data for compact length exceeding int64", func(t *testing.T) {
180 var input [binary.MaxVarintLen64]byte
181 n := binary.PutUvarint(input[:], 1<<63)
182
183 rd := &realFlexibleDecoder{&realDecoder{raw: input[:n]}}
184 array, err := rd.getNullableInt32Array()
185
186 require.ErrorIs(t, err, ErrInsufficientData)
187 assert.Nil(t, array)
188 })
189}
190
191// getInt32Array only diverges from getNullableInt32Array on null input
192func TestRealFlexibleDecoderGetInt32Array(t *testing.T) {

Callers

nothing calls this directly

Calls 2

getNullableInt32ArrayMethod · 0.95
RunMethod · 0.80

Tested by

no test coverage detected