mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-07-13 11:54:46 -04:00
Various changes
-we're dropping errors instead of trying to recover -revamp TestReadI2PStringErrWhenDataTooShort to reflect drops instead of recoveries
This commit is contained in:
@ -2,8 +2,6 @@ package data
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -162,7 +160,8 @@ func ReadI2PString(data []byte) (str I2PString, remainder []byte, err error) {
|
||||
}
|
||||
data_len := length.Int() + 1
|
||||
if data_len > len(data) {
|
||||
err = fmt.Errorf("I2PString length %d exceeds available data %d", data_len-1, len(data)-1)
|
||||
log.Errorf("I2PString length %d exceeds available data %d", data_len-1, len(data)-1)
|
||||
err = ErrDataTooShort
|
||||
log.WithError(err).Error("Failed to read I2PString")
|
||||
return
|
||||
}
|
||||
|
@ -140,10 +140,14 @@ func TestReadI2PStringErrWhenDataTooShort(t *testing.T) {
|
||||
str, remainder, err := ReadI2PString(short_str)
|
||||
|
||||
if assert.NotNil(err) {
|
||||
assert.Equal(err.Error(), "string parsing warning: string data is shorter than specified by length", "correct error message should be returned")
|
||||
assert.Equal(err.Error(), ErrDataTooShort.Error(), "correct error message should be returned")
|
||||
}
|
||||
assert.Equal(len(str), 2, "ReadI2PString() did not return the slice as string when too long")
|
||||
assert.Equal(3, int(str[0]), "ReadI2PString() did not return the correct partial string")
|
||||
assert.Equal(1, int(str[1]), "ReadI2PString() did not return the correct partial string")
|
||||
assert.Equal(len(remainder), 0, "ReadI2PString() returned a remainder when the string data was too short")
|
||||
/*
|
||||
assert.Equal(len(str), 2, "ReadI2PString() did not return the slice as string when too long")
|
||||
assert.Equal(3, int(str[0]), "ReadI2PString() did not return the correct partial string")
|
||||
assert.Equal(1, int(str[1]), "ReadI2PString() did not return the correct partial string")
|
||||
assert.Equal(len(remainder), 0, "ReadI2PString() returned a remainder when the string data was too short")
|
||||
*/
|
||||
assert.Equal(len(str), 0, "ReadI2PString() should not return any data when data is too short")
|
||||
assert.Equal(len(remainder), 0, "ReadI2PString() should not return any remainder when data is too short")
|
||||
}
|
||||
|
Reference in New Issue
Block a user