Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Commit 140d449

Browse files
committed
test(encode_decode_test): add test case for malformed JSON
1 parent 38883f0 commit 140d449

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/kafka/encode_decode_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,17 @@ func TestDecoder_JsonMessageToRecord(t *testing.T) {
3535
assert.Nil(t, err)
3636
assert.Equal(t, val, returnedVal)
3737
}
38+
39+
func TestDecoder_JsonMessageToRecord_MalformedJson(t *testing.T) {
40+
d := &Decoder{CodecCache: sync.Map{}}
41+
jsonBytes := []byte(`{"alo": 60"`)
42+
record, err := d.JsonMessageToRecord(context.Background(), &sarama.ConsumerMessage{
43+
Value: jsonBytes,
44+
Topic: "test",
45+
Partition: 1,
46+
Offset: 54,
47+
Timestamp: time.Now(),
48+
})
49+
assert.Nil(t, record)
50+
assert.NotNil(t, err)
51+
}

0 commit comments

Comments
 (0)