mock

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StandardProfiles = map[string]ThrottlingProfile{
	"slow-3g": {
		Name:        "slow-3g",
		DownloadBps: 50 * 1024,
		UploadBps:   50 * 1024,
		LatencyMs:   400,
		JitterMs:    50,
		Offline:     false,
	},
	"fast-3g": {
		Name:        "fast-3g",
		DownloadBps: 200 * 1024,
		UploadBps:   90 * 1024,
		LatencyMs:   150,
		JitterMs:    20,
		Offline:     false,
	},
	"lte": {
		Name:        "lte",
		DownloadBps: 1250 * 1024,
		UploadBps:   625 * 1024,
		LatencyMs:   40,
		JitterMs:    10,
		Offline:     false,
	},
	"offline": {
		Name:    "offline",
		Offline: true,
	},
}

Functions

This section is empty.

Types

type ChaosRule

type ChaosRule struct {
	ID      string `json:"id"`
	Enabled bool   `json:"enabled"`
	Pattern string `json:"pattern"` // regex matching target URLs (or ".*" for all)

	DelayMs     int     `json:"delay_ms"`     // delay in milliseconds
	JitterMs    int     `json:"jitter_ms"`    // random variance +/- jitter
	ErrorRate   float64 `json:"error_rate"`   // probability (0.0 to 1.0) of simulated failure
	ErrorStatus int     `json:"error_status"` // e.g. 500, 502, 503
	ErrorBody   string  `json:"error_body"`
	// contains filtered or unexported fields
}

ChaosRule injects latency, jitter, or simulated errors to test client resilience.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine coordinates Map Local, Map Remote, Chaos injection, and Network Throttling.

func NewEngine

func NewEngine() *Engine

NewEngine initializes an empty mock & chaos engine.

func (*Engine) AddChaosRule

func (e *Engine) AddChaosRule(rule *ChaosRule) error

AddChaosRule registers a new Chaos / Latency injection rule.

func (*Engine) AddMapLocal

func (e *Engine) AddMapLocal(rule *MapLocalRule) error

AddMapLocal registers a new Map Local rule.

func (*Engine) AddMapRemote

func (e *Engine) AddMapRemote(rule *MapRemoteRule) error

AddMapRemote registers a new Map Remote rule.

func (*Engine) ApplyChaos

func (e *Engine) ApplyChaos(rawURL string) (injectedError bool, status int, body string)

ApplyChaos checks if network throttling, latency, or error simulation applies to the given URL.

func (*Engine) ClearAll

func (e *Engine) ClearAll()

ClearAll removes all registered rules.

func (*Engine) DeleteRule

func (e *Engine) DeleteRule(id string) bool

DeleteRule removes a rule with the specified ID across all rule types.

func (*Engine) GetRulesSummary

func (e *Engine) GetRulesSummary() map[string]interface{}

GetRulesSummary returns current configuration for the dashboard.

func (*Engine) GetThrottlingProfile

func (e *Engine) GetThrottlingProfile() string

GetThrottlingProfile returns the name of the currently active profile.

func (*Engine) MatchMapLocal

func (e *Engine) MatchMapLocal(rawURL string) (*MapLocalRule, []byte, error)

MatchMapLocal checks if a URL matches any active Map Local rules.

func (*Engine) MatchMapRemote

func (e *Engine) MatchMapRemote(rawURL, host string) (newURL string, newHost string, matched bool)

MatchMapRemote rewrites host/URL if matching any active Map Remote rules.

func (*Engine) SetThrottlingProfile

func (e *Engine) SetThrottlingProfile(name string) error

SetThrottlingProfile configures the active global network condition preset.

type MapLocalRule

type MapLocalRule struct {
	ID      string `json:"id"`
	Enabled bool   `json:"enabled"`
	Pattern string `json:"pattern"` // regex matching URL or path

	FilePath    string            `json:"file_path,omitempty"` // local file to serve
	InlineBody  string            `json:"inline_body,omitempty"`
	StatusCode  int               `json:"status_code"`
	ContentType string            `json:"content_type"`
	Headers     map[string]string `json:"headers,omitempty"`
	// contains filtered or unexported fields
}

MapLocalRule serves a local file or inline payload instead of hitting the upstream server.

type MapRemoteRule

type MapRemoteRule struct {
	ID      string `json:"id"`
	Enabled bool   `json:"enabled"`
	Pattern string `json:"pattern"` // regex matching source URL

	TargetHost string `json:"target_host"` // target host/base (e.g. localhost:3000)
	TargetURL  string `json:"target_url,omitempty"`
	// contains filtered or unexported fields
}

MapRemoteRule redirects requests matching a pattern to a different remote or local destination.

type ThrottlingProfile

type ThrottlingProfile struct {
	Name        string `json:"name"`
	DownloadBps int64  `json:"download_bps"`
	UploadBps   int64  `json:"upload_bps"`
	LatencyMs   int    `json:"latency_ms"`
	JitterMs    int    `json:"jitter_ms"`
	Offline     bool   `json:"offline"`
}

ThrottlingProfile defines network condition simulation parameters.

Jump to

Keyboard shortcuts

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