Fix some tests

This commit is contained in:
eyedeekay
2025-03-02 16:43:47 -05:00
parent 393263294e
commit bd6edf446d
5 changed files with 14 additions and 12 deletions

View File

@ -43,7 +43,9 @@ The I2P community maintains up-to-date [specifications](https://geti2p.net/spec)
#### Errors #### Errors
We use oops to provide context to the errors we return. Do not use `errors.New` or `fmt.Errorf`. Wrap raw errors in oops errors. When an error is recieved, used oops to supplement the log output. We use oops to provide context to the errors we return. Do not use `errors.New` or `fmt.Errorf` when returning errors from functions. Instead, wrap raw errors in oops errors. When an error is recieved, used oops to supplement the log output.
It is OK to use `fmt.Errorf` for declaring custom error types.
#### Logging #### Logging

View File

@ -7,11 +7,11 @@ import (
) )
var ( var (
ErrZeroLength = oops.Errorf("error parsing string: zero length") ErrZeroLength = fmt.Errorf("error parsing string: zero length")
ErrDataTooShort = oops.Errorf("string parsing warning: string data is shorter than specified by length") ErrDataTooShort = fmt.Errorf("string parsing warning: string data is shorter than specified by length")
ErrDataTooLong = oops.Errorf("string parsing warning: string contains data beyond length") ErrDataTooLong = fmt.Errorf("string parsing warning: string contains data beyond length")
ErrLengthMismatch = oops.Errorf("error reading I2P string, length does not match data") ErrLengthMismatch = fmt.Errorf("error reading I2P string, length does not match data")
ErrMappingLengthMismatch = oops.Errorf("warning parsing mapping: mapping length exceeds provided data") ErrMappingLengthMismatch = fmt.Errorf("warning parsing mapping: mapping length exceeds provided data")
) )
// WrapErrors compiles a slice of errors and returns them wrapped together as a single error. // WrapErrors compiles a slice of errors and returns them wrapped together as a single error.

View File

@ -14,7 +14,7 @@ func TestSigningPublicKeyTypeReturnsCorrectInteger(t *testing.T) {
assert.Nil(err) assert.Nil(err)
pk_type := key_cert.SigningPublicKeyType() pk_type := key_cert.SigningPublicKeyType()
assert.Equal(KEYCERT_SIGN_ED25519, pk_type, "SigningPublicKeyType() did not return correct type") assert.Equal(KEYCERT_SIGN_P521, pk_type, "SigningPublicKeyType() did not return correct type")
} }
func TestSigningPublicKeyTypeWithInvalidData(t *testing.T) { func TestSigningPublicKeyTypeWithInvalidData(t *testing.T) {

View File

@ -34,7 +34,7 @@ type RouterIdentity struct {
// ReadRouterIdentity returns RouterIdentity from a []byte. // ReadRouterIdentity returns RouterIdentity from a []byte.
// The remaining bytes after the specified length are also returned. // The remaining bytes after the specified length are also returned.
// Returns a list of errors that occurred during parsing. // Returns a list of errors that occurred during parsing.
func ReadRouterIdentity(data []byte) (router_identity RouterIdentity, remainder []byte, err error) { func ReadRouterIdentity(data []byte) (router_identity *RouterIdentity, remainder []byte, err error) {
log.WithFields(logrus.Fields{ log.WithFields(logrus.Fields{
"input_length": len(data), "input_length": len(data),
}).Debug("Reading RouterIdentity from data") }).Debug("Reading RouterIdentity from data")
@ -43,7 +43,7 @@ func ReadRouterIdentity(data []byte) (router_identity RouterIdentity, remainder
log.WithError(err).Error("Failed to read KeysAndCert for RouterIdentity") log.WithError(err).Error("Failed to read KeysAndCert for RouterIdentity")
return return
} }
router_identity = RouterIdentity{ router_identity = &RouterIdentity{
keys_and_cert, keys_and_cert,
} }
log.WithFields(logrus.Fields{ log.WithFields(logrus.Fields{

View File

@ -114,7 +114,7 @@ signature :: Signature
// //
// https://geti2p.net/spec/common-structures#routerinfo // https://geti2p.net/spec/common-structures#routerinfo
type RouterInfo struct { type RouterInfo struct {
router_identity RouterIdentity router_identity *RouterIdentity
published *Date published *Date
size *Integer size *Integer
addresses []*RouterAddress addresses []*RouterAddress
@ -169,7 +169,7 @@ func (router_info RouterInfo) String() string {
// RouterIdentity returns the router identity as *RouterIdentity. // RouterIdentity returns the router identity as *RouterIdentity.
func (router_info *RouterInfo) RouterIdentity() *RouterIdentity { func (router_info *RouterInfo) RouterIdentity() *RouterIdentity {
return &router_info.router_identity return router_info.router_identity
} }
// IndentHash returns the identity hash (sha256 sum) for this RouterInfo. // IndentHash returns the identity hash (sha256 sum) for this RouterInfo.
@ -410,7 +410,7 @@ func NewRouterInfo(
// 5. Assemble RouterInfo without signature // 5. Assemble RouterInfo without signature
routerInfo := &RouterInfo{ routerInfo := &RouterInfo{
router_identity: *routerIdentity, router_identity: routerIdentity,
published: &publishedDate, published: &publishedDate,
size: sizeInt, size: sizeInt,
addresses: addresses, addresses: addresses,