github.com/hamba/avro@v1.8.0/reader_skip_test.go (about) 1 package avro_test 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/hamba/avro" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestReader_SkipNBytes(t *testing.T) { 12 data := []byte{0x01, 0x01, 0x01, 0x36} 13 r := avro.NewReader(bytes.NewReader(data), 2) 14 15 r.SkipNBytes(3) 16 17 assert.NoError(t, r.Error) 18 assert.Equal(t, int32(27), r.ReadInt()) 19 } 20 21 func TestReader_SkipNBytesEOF(t *testing.T) { 22 data := []byte{0x01, 0x36} 23 r := avro.NewReader(bytes.NewReader(data), 2) 24 25 r.SkipNBytes(3) 26 27 assert.Error(t, r.Error) 28 } 29 30 func TestReader_SkipBool(t *testing.T) { 31 data := []byte{0x01, 0x36} 32 r := avro.NewReader(bytes.NewReader(data), 10) 33 34 r.SkipBool() 35 36 assert.NoError(t, r.Error) 37 assert.Equal(t, int32(27), r.ReadInt()) 38 } 39 40 func TestReader_SkipInt(t *testing.T) { 41 tests := []struct { 42 name string 43 data []byte 44 }{ 45 { 46 name: "Skipped", 47 data: []byte{0x38, 0x36}, 48 }, 49 { 50 51 name: "Overflow", 52 data: []byte{0xE2, 0xA2, 0xF3, 0xAD, 0xAD, 0x36}, 53 }, 54 } 55 56 for _, tt := range tests { 57 t.Run(tt.name, func(t *testing.T) { 58 r := avro.NewReader(bytes.NewReader(tt.data), 10) 59 60 r.SkipInt() 61 62 assert.NoError(t, r.Error) 63 assert.Equal(t, int32(27), r.ReadInt()) 64 }) 65 } 66 } 67 68 func TestReader_SkipLong(t *testing.T) { 69 tests := []struct { 70 name string 71 data []byte 72 }{ 73 { 74 name: "Skipped", 75 data: []byte{0x38, 0x36}, 76 }, 77 { 78 79 name: "Overflow", 80 data: []byte{0xE2, 0xA2, 0xF3, 0xAD, 0xAD, 0xAD, 0xE2, 0xA2, 0xF3, 0xAD, 0x36}, 81 }, 82 } 83 84 for _, tt := range tests { 85 t.Run(tt.name, func(t *testing.T) { 86 r := avro.NewReader(bytes.NewReader(tt.data), 10) 87 88 r.SkipLong() 89 90 assert.NoError(t, r.Error) 91 assert.Equal(t, int32(27), r.ReadInt()) 92 }) 93 } 94 } 95 96 func TestReader_SkipFloat(t *testing.T) { 97 data := []byte{0x00, 0x00, 0x00, 0x00, 0x36} 98 r := avro.NewReader(bytes.NewReader(data), 10) 99 100 r.SkipFloat() 101 102 assert.NoError(t, r.Error) 103 assert.Equal(t, int32(27), r.ReadInt()) 104 } 105 106 func TestReader_SkipDouble(t *testing.T) { 107 data := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36} 108 r := avro.NewReader(bytes.NewReader(data), 10) 109 110 r.SkipDouble() 111 112 assert.NoError(t, r.Error) 113 assert.Equal(t, int32(27), r.ReadInt()) 114 } 115 116 func TestReader_SkipString(t *testing.T) { 117 data := []byte{0x06, 0x66, 0x6F, 0x6F, 0x36} 118 r := avro.NewReader(bytes.NewReader(data), 10) 119 120 r.SkipString() 121 122 assert.NoError(t, r.Error) 123 assert.Equal(t, int32(27), r.ReadInt()) 124 } 125 126 func TestReader_SkipStringEmpty(t *testing.T) { 127 data := []byte{0x00, 0x36} 128 r := avro.NewReader(bytes.NewReader(data), 10) 129 130 r.SkipString() 131 132 assert.NoError(t, r.Error) 133 assert.Equal(t, int32(27), r.ReadInt()) 134 } 135 136 func TestReader_SkipBytes(t *testing.T) { 137 data := []byte{0x06, 0x66, 0x6F, 0x6F, 0x36} 138 r := avro.NewReader(bytes.NewReader(data), 10) 139 140 r.SkipBytes() 141 142 assert.NoError(t, r.Error) 143 assert.Equal(t, int32(27), r.ReadInt()) 144 } 145 146 func TestReader_SkipBytesEmpty(t *testing.T) { 147 data := []byte{0x00, 0x36} 148 r := avro.NewReader(bytes.NewReader(data), 10) 149 150 r.SkipBytes() 151 152 assert.NoError(t, r.Error) 153 assert.Equal(t, int32(27), r.ReadInt()) 154 }