Documentation
¶
Overview ¶
Package helpers provides utilities for testing Netcap components
Package helpers provides utilities for generating synthetic test PCAPs
Index ¶
- func CompareAuditRecords(t *testing.T, got, want proto.Message)
- func CompareCSV(t *testing.T, got, want []byte)
- func CompareJSON(t *testing.T, got, want []byte)
- func GenerateDNSQuery(filename string, domain string) error
- func GenerateHTTPRequest(filename string, host string) error
- func GenerateTCPHandshake(filename string, srcIP, dstIP string, srcPort, dstPort uint16) error
- func ShouldUpdateGolden() bool
- func TempOutputDir(t *testing.T) string
- func TestDataPath() string
- type FixtureLoader
- func (fl *FixtureLoader) LoadFixture(name string) (*TestFixture, error)
- func (fl *FixtureLoader) LoadGoldenFile(protocol, format, scenario string) ([]byte, error)
- func (fl *FixtureLoader) LoadPCAP(name string) (string, error)
- func (fl *FixtureLoader) SaveGoldenFile(protocol, format, scenario string, data []byte) error
- type GoldenFiles
- type PacketBuilder
- type PcapConfig
- type TestFixture
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareAuditRecords ¶
CompareAuditRecords compares two audit records for equality
func CompareCSV ¶
CompareCSV compares two CSV outputs
func CompareJSON ¶
CompareJSON compares two JSON outputs
func GenerateDNSQuery ¶
GenerateDNSQuery generates a DNS query/response pair
func GenerateHTTPRequest ¶
GenerateHTTPRequest generates a simple HTTP GET request in a PCAP
func GenerateTCPHandshake ¶
GenerateTCPHandshake generates a complete TCP 3-way handshake
func ShouldUpdateGolden ¶
func ShouldUpdateGolden() bool
ShouldUpdateGolden returns true if golden files should be updated
func TempOutputDir ¶
TempOutputDir creates a temporary directory for test outputs
Types ¶
type FixtureLoader ¶
type FixtureLoader struct {
BaseDir string
}
FixtureLoader handles loading test fixtures and golden files
func NewFixtureLoader ¶
func NewFixtureLoader(baseDir string) *FixtureLoader
NewFixtureLoader creates a new fixture loader
func (*FixtureLoader) LoadFixture ¶
func (fl *FixtureLoader) LoadFixture(name string) (*TestFixture, error)
LoadFixture loads a test fixture by name
func (*FixtureLoader) LoadGoldenFile ¶
func (fl *FixtureLoader) LoadGoldenFile(protocol, format, scenario string) ([]byte, error)
LoadGoldenFile loads a golden file for comparison
func (*FixtureLoader) LoadPCAP ¶
func (fl *FixtureLoader) LoadPCAP(name string) (string, error)
LoadPCAP loads a test PCAP file
func (*FixtureLoader) SaveGoldenFile ¶
func (fl *FixtureLoader) SaveGoldenFile(protocol, format, scenario string, data []byte) error
SaveGoldenFile saves a golden file (for updating baselines)
type GoldenFiles ¶
type GoldenFiles struct {
CSV map[string]string // protocol -> csv file path
JSON map[string]string
Protobuf map[string]string
}
GoldenFiles contains paths to expected output files
type PacketBuilder ¶
type PacketBuilder struct {
// contains filtered or unexported fields
}
PacketBuilder helps build test packets
func NewPacketBuilder ¶
func NewPacketBuilder(config PcapConfig) (*PacketBuilder, error)
NewPacketBuilder creates a new packet builder
func (*PacketBuilder) BuildEthernetIPv4TCPPacket ¶
func (pb *PacketBuilder) BuildEthernetIPv4TCPPacket( srcMAC, dstMAC string, srcIP, dstIP string, srcPort, dstPort uint16, seq, ack uint32, flags layers.TCPFlag, payload []byte, ) ([]byte, error)
BuildEthernetIPv4TCPPacket builds a simple Ethernet/IPv4/TCP packet
func (*PacketBuilder) WritePacket ¶
func (pb *PacketBuilder) WritePacket(data []byte) error
WritePacket writes a packet to the PCAP file
type PcapConfig ¶
PcapConfig contains configuration for PCAP generation
type TestFixture ¶
type TestFixture struct {
Name string
PcapPath string
ExpectedType string
PacketCount int
Golden GoldenFiles
Config map[string]interface{}
}
TestFixture represents a test case with input PCAP and expected outputs