-
Notifications
You must be signed in to change notification settings - Fork 12
Add Go test #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Add Go test #239
Conversation
Co-authored-by: Wataru Mishima <[email protected]> Co-authored-by: Copilot <[email protected]>
Co-authored-by: Wataru Mishima <[email protected]> Co-authored-by: Copilot <[email protected]>
…segments Co-authored-by: Copilot <[email protected]>
… follow Go naming conventions
… Go naming conventions
…-explicit-path` option
…eCapability Co-authored-by: Copilot <[email protected]>
…v4/IPv6 LSP Identifiers
…ate logic and tests
… to verify correct TLV structure instantiation
…mes and assertions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds Go test coverage for PCEP TLV functionality, refactoring existing tests to use common helper functions and adding comprehensive test cases for various TLV types. The refactoring improves test maintainability and consistency across different TLV implementations.
Key changes include:
- Introduced common test helper functions for TLV testing (decode, serialize, capability strings, length tests)
- Added comprehensive test coverage for all major TLV types including StatefulPCECapability, SymbolicPathName, IPv4/IPv6LSPIdentifiers, LSPDBVersion, SRPCECapability, PathSetupType, and ExtendedAssociationID
- Updated TLV implementation code with bug fixes and improvements, including proper flag handling and serialization methods
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
pkg/packet/pcep/tlv_test.go | Comprehensive refactoring of TLV tests with new helper functions and extensive test coverage |
pkg/packet/pcep/tlv.go | Bug fixes and improvements to TLV implementations including flag handling and serialization |
pkg/packet/pcep/pcep_util_test.go | Added test for Uint64ToByteSlice utility function |
pkg/packet/pcep/pcep_util.go | Added Uint64ToByteSlice utility function |
pkg/packet/pcep/capability_test.go | Added test case for LSPDBVersion capability filtering |
go.mod | Updated Go version and dependencies |
api/pola/v1/pola_grpc.pb.go | Minor import formatting change |
api/pola/v1/pola.pb.go | Minor import formatting change |
Comments suppressed due to low confidence (2)
pkg/packet/pcep/tlv_test.go:276
- The test case 'InvalidUTF8Sequence' expects an error but the DecodeFromBytes method for SymbolicPathName doesn't validate UTF-8. This test may not behave as expected unless UTF-8 validation is implemented in the DecodeFromBytes method.
"InvalidUTF8Sequence": {testSymbolicPathNameInvalidUTF8Bytes, nil, true},
pkg/packet/pcep/tlv_test.go:813
- The test case 'UnsupportedLength' creates an ExtendedAssociationID with only Color set, which may not properly test the unsupported length scenario. Consider creating a test case with an explicitly unsupported endpoint type.
"UnsupportedLength": {&ExtendedAssociationID{Color: 1}, 0},
// Serialized TLV bytes with an invalid UTF-8 sequence. | ||
testSymbolicPathNameInvalidUTF8Bytes = []byte{ | ||
byte(TLVSymbolicPathName >> 8), byte(TLVSymbolicPathName & 0xff), | ||
0x00, 0x01, 0xff, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 0xff should be documented or replaced with a named constant to clarify that this represents an invalid UTF-8 sequence.
0x00, 0x01, 0xff, | |
0x00, 0x01, InvalidUTF8Byte, |
Copilot uses AI. Check for mistakes.
tlv.IPv4TunnelSenderAddress, _ = netip.AddrFromSlice(data[:IPv4LSPIdentifiersLSPIDOffset]) | ||
tlv.LSPID = binary.BigEndian.Uint16(data[IPv4LSPIdentifiersLSPIDOffset:IPv4LSPIdentifiersTunnelIDOffset]) | ||
tlv.TunnelID = binary.BigEndian.Uint16(data[IPv4LSPIdentifiersTunnelIDOffset:IPv4LSPIdentifiersExtendedTunnelIDOffset]) | ||
tlv.ExtendedTunnelID = binary.BigEndian.Uint32(data[IPv4LSPIdentifiersExtendedTunnelIDOffset:IPv4LSPIdentifiersTunnelEndpointAddressOffset]) | ||
tlv.IPv4TunnelEndpointAddress, _ = netip.AddrFromSlice(data[IPv4LSPIdentifiersTunnelEndpointAddressOffset:TLVIPv4LSPIdentifiersValueLength]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error handling is ignored with the blank identifier. If netip.AddrFromSlice fails, it should return an error rather than silently continuing with an invalid address.
tlv.IPv4TunnelSenderAddress, _ = netip.AddrFromSlice(data[:IPv4LSPIdentifiersLSPIDOffset]) | |
tlv.LSPID = binary.BigEndian.Uint16(data[IPv4LSPIdentifiersLSPIDOffset:IPv4LSPIdentifiersTunnelIDOffset]) | |
tlv.TunnelID = binary.BigEndian.Uint16(data[IPv4LSPIdentifiersTunnelIDOffset:IPv4LSPIdentifiersExtendedTunnelIDOffset]) | |
tlv.ExtendedTunnelID = binary.BigEndian.Uint32(data[IPv4LSPIdentifiersExtendedTunnelIDOffset:IPv4LSPIdentifiersTunnelEndpointAddressOffset]) | |
tlv.IPv4TunnelEndpointAddress, _ = netip.AddrFromSlice(data[IPv4LSPIdentifiersTunnelEndpointAddressOffset:TLVIPv4LSPIdentifiersValueLength]) | |
var err error | |
tlv.IPv4TunnelSenderAddress, err = netip.AddrFromSlice(data[:IPv4LSPIdentifiersLSPIDOffset]) | |
if err != nil { | |
return fmt.Errorf("failed to parse IPv4TunnelSenderAddress: %w", err) | |
} | |
tlv.LSPID = binary.BigEndian.Uint16(data[IPv4LSPIdentifiersLSPIDOffset:IPv4LSPIdentifiersTunnelIDOffset]) | |
tlv.TunnelID = binary.BigEndian.Uint16(data[IPv4LSPIdentifiersTunnelIDOffset:IPv4LSPIdentifiersExtendedTunnelIDOffset]) | |
tlv.ExtendedTunnelID = binary.BigEndian.Uint32(data[IPv4LSPIdentifiersExtendedTunnelIDOffset:IPv4LSPIdentifiersTunnelEndpointAddressOffset]) | |
tlv.IPv4TunnelEndpointAddress, err = netip.AddrFromSlice(data[IPv4LSPIdentifiersTunnelEndpointAddressOffset:TLVIPv4LSPIdentifiersValueLength]) | |
if err != nil { | |
return fmt.Errorf("failed to parse IPv4TunnelEndpointAddress: %w", err) | |
} |
Copilot uses AI. Check for mistakes.
tlv.IPv6TunnelSenderAddress, _ = netip.AddrFromSlice(data[:IPv6LSPIdentifiersLSPIDOffset]) | ||
tlv.LSPID = binary.BigEndian.Uint16(data[IPv6LSPIdentifiersLSPIDOffset:IPv6LSPIdentifiersTunnelIDOffset]) | ||
tlv.TunnelID = binary.BigEndian.Uint16(data[IPv6LSPIdentifiersTunnelIDOffset:IPv6LSPIdentifiersExtendedTunnelIDOffset]) | ||
copy(tlv.ExtendedTunnelID[:], data[IPv6LSPIdentifiersExtendedTunnelIDOffset:IPv6LSPIdentifiersTunnelEndpointAddressOffset]) | ||
tlv.IPv6TunnelEndpointAddress, _ = netip.AddrFromSlice(data[IPv6LSPIdentifiersTunnelEndpointAddressOffset:TLVIPv6LSPIdentifiersValueLength]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error handling is ignored with the blank identifier. If netip.AddrFromSlice fails, it should return an error rather than silently continuing with an invalid address.
tlv.IPv6TunnelSenderAddress, _ = netip.AddrFromSlice(data[:IPv6LSPIdentifiersLSPIDOffset]) | |
tlv.LSPID = binary.BigEndian.Uint16(data[IPv6LSPIdentifiersLSPIDOffset:IPv6LSPIdentifiersTunnelIDOffset]) | |
tlv.TunnelID = binary.BigEndian.Uint16(data[IPv6LSPIdentifiersTunnelIDOffset:IPv6LSPIdentifiersExtendedTunnelIDOffset]) | |
copy(tlv.ExtendedTunnelID[:], data[IPv6LSPIdentifiersExtendedTunnelIDOffset:IPv6LSPIdentifiersTunnelEndpointAddressOffset]) | |
tlv.IPv6TunnelEndpointAddress, _ = netip.AddrFromSlice(data[IPv6LSPIdentifiersTunnelEndpointAddressOffset:TLVIPv6LSPIdentifiersValueLength]) | |
var err error | |
tlv.IPv6TunnelSenderAddress, err = netip.AddrFromSlice(data[:IPv6LSPIdentifiersLSPIDOffset]) | |
if err != nil { | |
return fmt.Errorf("failed to parse IPv6TunnelSenderAddress: %w", err) | |
} | |
tlv.LSPID = binary.BigEndian.Uint16(data[IPv6LSPIdentifiersLSPIDOffset:IPv6LSPIdentifiersTunnelIDOffset]) | |
tlv.TunnelID = binary.BigEndian.Uint16(data[IPv6LSPIdentifiersTunnelIDOffset:IPv6LSPIdentifiersExtendedTunnelIDOffset]) | |
copy(tlv.ExtendedTunnelID[:], data[IPv6LSPIdentifiersExtendedTunnelIDOffset:IPv6LSPIdentifiersTunnelEndpointAddressOffset]) | |
tlv.IPv6TunnelEndpointAddress, err = netip.AddrFromSlice(data[IPv6LSPIdentifiersTunnelEndpointAddressOffset:TLVIPv6LSPIdentifiersValueLength]) | |
if err != nil { | |
return fmt.Errorf("failed to parse IPv6TunnelEndpointAddress: %w", err) | |
} |
Copilot uses AI. Check for mistakes.
} | ||
|
||
tlv.Endpoint, _ = netip.AddrFromSlice(addrBytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error handling is ignored with the blank identifier. If netip.AddrFromSlice fails, it should return an error rather than silently continuing with an invalid endpoint address.
tlv.Endpoint, _ = netip.AddrFromSlice(addrBytes) | |
var err error | |
tlv.Endpoint, err = netip.AddrFromSlice(addrBytes) | |
if err != nil { | |
return fmt.Errorf("extended association ID: invalid endpoint address: %w", err) | |
} |
Copilot uses AI. Check for mistakes.
d420884
to
961c1c7
Compare
8c61705
to
008c478
Compare
Description
Add Go test
Type of change