helpers

package
v0.7.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2025 License: BSD-3-Clause, GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package helpers provides utilities for testing Netcap components

Package helpers provides utilities for generating synthetic test PCAPs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareAuditRecords

func CompareAuditRecords(t *testing.T, got, want proto.Message)

CompareAuditRecords compares two audit records for equality

func CompareCSV

func CompareCSV(t *testing.T, got, want []byte)

CompareCSV compares two CSV outputs

func CompareJSON

func CompareJSON(t *testing.T, got, want []byte)

CompareJSON compares two JSON outputs

func GenerateDNSQuery

func GenerateDNSQuery(filename string, domain string) error

GenerateDNSQuery generates a DNS query/response pair

func GenerateHTTPRequest

func GenerateHTTPRequest(filename string, host string) error

GenerateHTTPRequest generates a simple HTTP GET request in a PCAP

func GenerateTCPHandshake

func GenerateTCPHandshake(filename string, srcIP, dstIP string, srcPort, dstPort uint16) error

GenerateTCPHandshake generates a complete TCP 3-way handshake

func ShouldUpdateGolden

func ShouldUpdateGolden() bool

ShouldUpdateGolden returns true if golden files should be updated

func TempOutputDir

func TempOutputDir(t *testing.T) string

TempOutputDir creates a temporary directory for test outputs

func TestDataPath

func TestDataPath() string

TestDataPath returns the path to test data directory

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) Close

func (pb *PacketBuilder) Close() error

Close closes the PCAP file

func (*PacketBuilder) WritePacket

func (pb *PacketBuilder) WritePacket(data []byte) error

WritePacket writes a packet to the PCAP file

type PcapConfig

type PcapConfig struct {
	Filename string
	LinkType layers.LinkType
	SnapLen  uint32
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL