Documentation
¶
Overview ¶
Package testing provides error simulation tools for testing download scenarios.
Index ¶
- func CreateErrorServer(statusCode int, responseBody string) *httptest.Server
- func CreatePartialResponseServer(totalSize, sendSize int64) *httptest.Server
- func CreateTimeoutServer(delay time.Duration) *httptest.Server
- type DiskSpaceSimulator
- type ErrorSimulator
- type HTTPErrorSimulator
- type NetworkFailureSimulator
- type SimulationConfig
- type SimulatorSuite
- type TestScenario
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateErrorServer ¶
CreateErrorServer creates a server that returns a specific HTTP error.
func CreatePartialResponseServer ¶
CreatePartialResponseServer creates a server that sends partial responses.
Types ¶
type DiskSpaceSimulator ¶
type DiskSpaceSimulator struct {
// contains filtered or unexported fields
}
DiskSpaceSimulator simulates disk space exhaustion scenarios.
func NewDiskSpaceSimulator ¶
func NewDiskSpaceSimulator(spaceLimit int64) *DiskSpaceSimulator
NewDiskSpaceSimulator creates a disk space simulator.
func (*DiskSpaceSimulator) CreateLimitedWriter ¶
func (dss *DiskSpaceSimulator) CreateLimitedWriter(w io.Writer) io.Writer
CreateLimitedWriter returns a writer that simulates disk space exhaustion.
func (*DiskSpaceSimulator) GetBytesWritten ¶
func (dss *DiskSpaceSimulator) GetBytesWritten() int64
GetBytesWritten returns the total bytes written.
func (*DiskSpaceSimulator) Reset ¶
func (dss *DiskSpaceSimulator) Reset()
Reset resets the bytes written counter.
type ErrorSimulator ¶
type ErrorSimulator struct {
// contains filtered or unexported fields
}
ErrorSimulator provides comprehensive error simulation capabilities for testing download scenarios including network failures, disk space issues, HTTP errors, and timeout conditions.
func NewErrorSimulator ¶
func NewErrorSimulator(config *SimulationConfig) *ErrorSimulator
NewErrorSimulator creates a new error simulator with the given configuration.
func (*ErrorSimulator) Close ¶
func (es *ErrorSimulator) Close()
Close shuts down the error simulator.
func (*ErrorSimulator) GetEndpoint ¶
func (es *ErrorSimulator) GetEndpoint(path string) string
GetEndpoint returns a specific endpoint URL.
func (*ErrorSimulator) GetURL ¶
func (es *ErrorSimulator) GetURL() string
GetURL returns the base URL of the test server.
type HTTPErrorSimulator ¶
type HTTPErrorSimulator struct {
// contains filtered or unexported fields
}
HTTPErrorSimulator provides utilities for testing HTTP error responses.
func NewHTTPErrorSimulator ¶
func NewHTTPErrorSimulator() *HTTPErrorSimulator
NewHTTPErrorSimulator creates an HTTP error simulator.
func (*HTTPErrorSimulator) Close ¶
func (hes *HTTPErrorSimulator) Close()
Close shuts down the HTTP error simulator.
func (*HTTPErrorSimulator) GetURL ¶
func (hes *HTTPErrorSimulator) GetURL() string
GetURL returns the server URL.
type NetworkFailureSimulator ¶
type NetworkFailureSimulator struct {
// contains filtered or unexported fields
}
NetworkFailureSimulator simulates various network failure scenarios.
func NewNetworkFailureSimulator ¶
func NewNetworkFailureSimulator() *NetworkFailureSimulator
NewNetworkFailureSimulator creates a network failure simulator.
type SimulationConfig ¶
type SimulationConfig struct {
// NetworkLatency adds artificial latency to responses
NetworkLatency time.Duration
// FailureRate determines the probability of failures (0.0 to 1.0)
FailureRate float64
// MaxResponseSize limits response body size
MaxResponseSize int64
// ChunkDelay adds delay between response chunks
ChunkDelay time.Duration
// TimeoutAfter causes requests to timeout after this duration
TimeoutAfter time.Duration
// HTTPStatusCode overrides the HTTP status code to return
HTTPStatusCode int
// FailAfterBytes causes failure after reading a certain number of bytes
FailAfterBytes int64
// DiskSpaceLimit simulates insufficient disk space
DiskSpaceLimit uint64
// EnableConnectionReset simulates connection resets
EnableConnectionReset bool
// EnableDNSFailure simulates DNS resolution failures
EnableDNSFailure bool
// SlowResponseRate limits response byte rate (bytes per second)
SlowResponseRate int64
}
SimulationConfig configures the error simulation behavior.
func DefaultSimulationConfig ¶
func DefaultSimulationConfig() *SimulationConfig
DefaultSimulationConfig returns a basic simulation configuration.
type SimulatorSuite ¶
type SimulatorSuite struct {
ErrorSim *ErrorSimulator
NetworkSim *NetworkFailureSimulator
DiskSpaceSim *DiskSpaceSimulator
HTTPSim *HTTPErrorSimulator
}
SimulatorSuite combines all simulators for comprehensive testing.
func NewSimulatorSuite ¶
func NewSimulatorSuite() *SimulatorSuite
NewSimulatorSuite creates a complete simulator suite.
func (*SimulatorSuite) Close ¶
func (ss *SimulatorSuite) Close()
Close shuts down all simulators in the suite.
type TestScenario ¶
type TestScenario struct {
Name string
NetworkFailure string // Type of network failure to simulate
HTTPStatusCode int // HTTP status code to return
DiskSpaceLimit int64 // Disk space limit in bytes
TimeoutAfter time.Duration // Timeout duration
PartialFailureAt int64 // Bytes after which to fail
ExpectedErrorCode errors.ErrorCode // Expected error code
ExpectedRetryable bool // Whether error should be retryable
}
TestScenario represents a complete test scenario with multiple error conditions.
func GetCommonTestScenarios ¶
func GetCommonTestScenarios() []TestScenario
GetCommonTestScenarios returns a set of common error scenarios for testing.