Documentation
¶
Overview ¶
Package testing provides utilities for testing and benchmarking.
Index ¶
- type BenchmarkComparison
- type BenchmarkFunc
- type BenchmarkReport
- type BenchmarkResult
- type BenchmarkRunner
- func (br *BenchmarkRunner) Benchmark(name string, fn BenchmarkFunc) BenchmarkResult
- func (br *BenchmarkRunner) Clear()
- func (br *BenchmarkRunner) Compare(name1, name2 string) (BenchmarkComparison, error)
- func (br *BenchmarkRunner) ExportReport(filename string) error
- func (br *BenchmarkRunner) GenerateReport() BenchmarkReport
- func (br *BenchmarkRunner) GetResult(name string) (BenchmarkResult, bool)
- func (br *BenchmarkRunner) GetResults() []BenchmarkResult
- func (br *BenchmarkRunner) PrintResults()
- func (br *BenchmarkRunner) SetMaxIterations(n int)
- func (br *BenchmarkRunner) SetMinIterations(n int)
- func (br *BenchmarkRunner) SetMinTime(d time.Duration)
- func (br *BenchmarkRunner) SetWarmupIterations(n int)
- type BenchmarkSummary
- type MemoryFS
- type MemoryFile
- type MemoryProfile
- type MockDir
- type MockDirEntry
- type MockDirHandle
- type MockFS
- func (mfs *MockFS) AddDir(path string)
- func (mfs *MockFS) AddFile(path string, content string)
- func (mfs *MockFS) AddFileWithMode(path string, content string, mode fs.FileMode)
- func (mfs *MockFS) Open(name string) (fs.File, error)
- func (mfs *MockFS) ReadDir(name string) ([]fs.DirEntry, error)
- func (mfs *MockFS) ReadFile(name string) ([]byte, error)
- func (mfs *MockFS) RemoveDir(path string)
- func (mfs *MockFS) RemoveFile(path string)
- func (mfs *MockFS) Stat(name string) (fs.FileInfo, error)
- func (mfs *MockFS) WalkDir(root string, fn fs.WalkDirFunc) error
- type MockFile
- type MockFileHandle
- type MockFileInfo
- type MockLogEntry
- type MockLogger
- func (ml *MockLogger) Clear()
- func (ml *MockLogger) CountByLevel(level string) int
- func (ml *MockLogger) Debug(msg string, args ...any)
- func (ml *MockLogger) Error(msg string, args ...any)
- func (ml *MockLogger) GetLogs() []MockLogEntry
- func (ml *MockLogger) GetLogsByLevel(level string) []MockLogEntry
- func (ml *MockLogger) HasMessage(message string) bool
- func (ml *MockLogger) Info(msg string, args ...any)
- func (ml *MockLogger) Warn(msg string, args ...any)
- type MockRenderCall
- type MockRenderer
- func (mr *MockRenderer) Clear()
- func (mr *MockRenderer) GetCallCount() int
- func (mr *MockRenderer) GetCalls() []MockRenderCall
- func (mr *MockRenderer) GetCallsForTemplate(templatePath string) []MockRenderCall
- func (mr *MockRenderer) Render(templatePath string, data any) (string, error)
- func (mr *MockRenderer) SetRenderFunc(fn func(templatePath string, data any) (string, error))
- func (mr *MockRenderer) WasCalled(templatePath string) bool
- type OperationProfile
- type PerformanceProfile
- type PerformanceProfiler
- func (pp *PerformanceProfiler) Clear()
- func (pp *PerformanceProfiler) EndProfile(name string)
- func (pp *PerformanceProfiler) GetAllProfiles() map[string]PerformanceProfile
- func (pp *PerformanceProfiler) GetProfile(name string) (PerformanceProfile, bool)
- func (pp *PerformanceProfiler) StartProfile(name string)
- type SnapshotManager
- func (sm *SnapshotManager) AssertSnapshot(testName, actual string) error
- func (sm *SnapshotManager) CleanOrphanSnapshots(activeTests []string) error
- func (sm *SnapshotManager) Clear()
- func (sm *SnapshotManager) GetResults() map[string]SnapshotResult
- func (sm *SnapshotManager) GetSummary() SnapshotSummary
- func (sm *SnapshotManager) SetUpdateMode(update bool)
- type SnapshotReporter
- type SnapshotResult
- type SnapshotSummary
- type SnapshotTestCase
- type SnapshotTestSuite
- func (sts *SnapshotTestSuite) AddTestCase(name, template string, data map[string]any)
- func (sts *SnapshotTestSuite) GetManager() *SnapshotManager
- func (sts *SnapshotTestSuite) GetTestCases() []SnapshotTestCase
- func (sts *SnapshotTestSuite) LoadTestCases(testFile string) error
- func (sts *SnapshotTestSuite) SaveTestCases(testFile string) error
- type SystemInfo
- type SystemResourcesProfile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BenchmarkComparison ¶
type BenchmarkComparison struct {
Name1 string `json:"name1"`
Name2 string `json:"name2"`
SpeedRatio float64 `json:"speed_ratio"`
MemoryRatio float64 `json:"memory_ratio"`
AllocRatio float64 `json:"alloc_ratio"`
Result1Faster bool `json:"result1_faster"`
Result1MemEfficient bool `json:"result1_mem_efficient"`
}
func (BenchmarkComparison) String ¶
func (bc BenchmarkComparison) String() string
type BenchmarkFunc ¶
type BenchmarkFunc func() error
type BenchmarkReport ¶
type BenchmarkReport struct {
GeneratedAt time.Time `json:"generated_at"`
Results []BenchmarkResult `json:"results"`
Summary BenchmarkSummary `json:"summary"`
SystemInfo SystemInfo `json:"system_info"`
}
type BenchmarkResult ¶
type BenchmarkResult struct {
Name string `json:"name"`
Iterations int `json:"iterations"`
TotalDuration time.Duration `json:"total_duration"`
AvgDuration time.Duration `json:"avg_duration"`
MinDuration time.Duration `json:"min_duration"`
MaxDuration time.Duration `json:"max_duration"`
MemoryUsed int64 `json:"memory_used"`
AllocsPerOp int64 `json:"allocs_per_op"`
BytesPerOp int64 `json:"bytes_per_op"`
Timestamp time.Time `json:"timestamp"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
type BenchmarkRunner ¶
type BenchmarkRunner struct {
// contains filtered or unexported fields
}
func NewBenchmarkRunner ¶
func NewBenchmarkRunner() *BenchmarkRunner
func (*BenchmarkRunner) Benchmark ¶
func (br *BenchmarkRunner) Benchmark(name string, fn BenchmarkFunc) BenchmarkResult
func (*BenchmarkRunner) Clear ¶
func (br *BenchmarkRunner) Clear()
func (*BenchmarkRunner) Compare ¶
func (br *BenchmarkRunner) Compare(name1, name2 string) (BenchmarkComparison, error)
func (*BenchmarkRunner) ExportReport ¶
func (br *BenchmarkRunner) ExportReport(filename string) error
func (*BenchmarkRunner) GenerateReport ¶
func (br *BenchmarkRunner) GenerateReport() BenchmarkReport
func (*BenchmarkRunner) GetResult ¶
func (br *BenchmarkRunner) GetResult(name string) (BenchmarkResult, bool)
func (*BenchmarkRunner) GetResults ¶
func (br *BenchmarkRunner) GetResults() []BenchmarkResult
func (*BenchmarkRunner) PrintResults ¶
func (br *BenchmarkRunner) PrintResults()
func (*BenchmarkRunner) SetMaxIterations ¶
func (br *BenchmarkRunner) SetMaxIterations(n int)
func (*BenchmarkRunner) SetMinIterations ¶
func (br *BenchmarkRunner) SetMinIterations(n int)
func (*BenchmarkRunner) SetMinTime ¶
func (br *BenchmarkRunner) SetMinTime(d time.Duration)
func (*BenchmarkRunner) SetWarmupIterations ¶
func (br *BenchmarkRunner) SetWarmupIterations(n int)
type BenchmarkSummary ¶
type BenchmarkSummary struct {
TotalBenchmarks int `json:"total_benchmarks"`
SuccessfulRuns int `json:"successful_runs"`
FailedRuns int `json:"failed_runs"`
TotalDuration time.Duration `json:"total_duration"`
AvgDuration time.Duration `json:"avg_duration"`
FastestBench string `json:"fastest_bench"`
SlowestBench string `json:"slowest_bench"`
}
type MemoryFS ¶
type MemoryFS struct {
// contains filtered or unexported fields
}
func NewMemoryFS ¶
func NewMemoryFS() *MemoryFS
type MemoryFile ¶
type MemoryFile struct {
// contains filtered or unexported fields
}
func (*MemoryFile) IsDir ¶
func (f *MemoryFile) IsDir() bool
func (*MemoryFile) ModTime ¶
func (f *MemoryFile) ModTime() time.Time
func (*MemoryFile) Mode ¶
func (f *MemoryFile) Mode() fs.FileMode
func (*MemoryFile) Name ¶
func (f *MemoryFile) Name() string
func (*MemoryFile) Size ¶
func (f *MemoryFile) Size() int64
func (*MemoryFile) Sys ¶
func (f *MemoryFile) Sys() any
type MemoryProfile ¶
type MemoryProfile struct {
StartAllocs uint64 `json:"start_allocs"`
EndAllocs uint64 `json:"end_allocs"`
AllocsDelta uint64 `json:"allocs_delta"`
StartHeapAlloc uint64 `json:"start_heap_alloc"`
EndHeapAlloc uint64 `json:"end_heap_alloc"`
HeapAllocDelta int64 `json:"heap_alloc_delta"`
StartSys uint64 `json:"start_sys"`
EndSys uint64 `json:"end_sys"`
SysDelta int64 `json:"sys_delta"`
}
type MockDirEntry ¶
type MockDirEntry struct {
// contains filtered or unexported fields
}
func (MockDirEntry) IsDir ¶
func (mde MockDirEntry) IsDir() bool
func (MockDirEntry) Name ¶
func (mde MockDirEntry) Name() string
func (MockDirEntry) Type ¶
func (mde MockDirEntry) Type() fs.FileMode
type MockDirHandle ¶
type MockDirHandle struct {
// contains filtered or unexported fields
}
func (*MockDirHandle) Close ¶
func (mdh *MockDirHandle) Close() error
type MockFS ¶
type MockFS struct {
// contains filtered or unexported fields
}
func (*MockFS) AddFileWithMode ¶
func (*MockFS) RemoveFile ¶
type MockFileHandle ¶
type MockFileHandle struct {
// contains filtered or unexported fields
}
func (*MockFileHandle) Close ¶
func (mfh *MockFileHandle) Close() error
type MockFileInfo ¶
type MockFileInfo struct {
// contains filtered or unexported fields
}
func (MockFileInfo) IsDir ¶
func (mfi MockFileInfo) IsDir() bool
func (MockFileInfo) ModTime ¶
func (mfi MockFileInfo) ModTime() time.Time
func (MockFileInfo) Mode ¶
func (mfi MockFileInfo) Mode() fs.FileMode
func (MockFileInfo) Name ¶
func (mfi MockFileInfo) Name() string
func (MockFileInfo) Size ¶
func (mfi MockFileInfo) Size() int64
func (MockFileInfo) Sys ¶
func (mfi MockFileInfo) Sys() any
type MockLogEntry ¶
type MockLogger ¶
type MockLogger struct {
// contains filtered or unexported fields
}
func NewMockLogger ¶
func NewMockLogger() *MockLogger
func (*MockLogger) Clear ¶
func (ml *MockLogger) Clear()
func (*MockLogger) CountByLevel ¶
func (ml *MockLogger) CountByLevel(level string) int
func (*MockLogger) Debug ¶
func (ml *MockLogger) Debug(msg string, args ...any)
func (*MockLogger) Error ¶
func (ml *MockLogger) Error(msg string, args ...any)
func (*MockLogger) GetLogs ¶
func (ml *MockLogger) GetLogs() []MockLogEntry
func (*MockLogger) GetLogsByLevel ¶
func (ml *MockLogger) GetLogsByLevel(level string) []MockLogEntry
func (*MockLogger) HasMessage ¶
func (ml *MockLogger) HasMessage(message string) bool
func (*MockLogger) Info ¶
func (ml *MockLogger) Info(msg string, args ...any)
func (*MockLogger) Warn ¶
func (ml *MockLogger) Warn(msg string, args ...any)
type MockRenderCall ¶
type MockRenderer ¶
type MockRenderer struct {
// contains filtered or unexported fields
}
func NewMockRenderer ¶
func NewMockRenderer() *MockRenderer
func (*MockRenderer) Clear ¶
func (mr *MockRenderer) Clear()
func (*MockRenderer) GetCallCount ¶
func (mr *MockRenderer) GetCallCount() int
func (*MockRenderer) GetCalls ¶
func (mr *MockRenderer) GetCalls() []MockRenderCall
func (*MockRenderer) GetCallsForTemplate ¶
func (mr *MockRenderer) GetCallsForTemplate(templatePath string) []MockRenderCall
func (*MockRenderer) Render ¶
func (mr *MockRenderer) Render(templatePath string, data any) (string, error)
func (*MockRenderer) SetRenderFunc ¶
func (mr *MockRenderer) SetRenderFunc(fn func(templatePath string, data any) (string, error))
func (*MockRenderer) WasCalled ¶
func (mr *MockRenderer) WasCalled(templatePath string) bool
type OperationProfile ¶
type PerformanceProfile ¶
type PerformanceProfile struct {
Name string `json:"name"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Duration time.Duration `json:"duration"`
Operations []OperationProfile `json:"operations"`
MemoryProfile MemoryProfile `json:"memory_profile"`
SystemResources SystemResourcesProfile `json:"system_resources"`
}
type PerformanceProfiler ¶
type PerformanceProfiler struct {
// contains filtered or unexported fields
}
func NewPerformanceProfiler ¶
func NewPerformanceProfiler() *PerformanceProfiler
func (*PerformanceProfiler) Clear ¶
func (pp *PerformanceProfiler) Clear()
func (*PerformanceProfiler) EndProfile ¶
func (pp *PerformanceProfiler) EndProfile(name string)
func (*PerformanceProfiler) GetAllProfiles ¶
func (pp *PerformanceProfiler) GetAllProfiles() map[string]PerformanceProfile
func (*PerformanceProfiler) GetProfile ¶
func (pp *PerformanceProfiler) GetProfile(name string) (PerformanceProfile, bool)
func (*PerformanceProfiler) StartProfile ¶
func (pp *PerformanceProfiler) StartProfile(name string)
type SnapshotManager ¶
type SnapshotManager struct {
// contains filtered or unexported fields
}
func NewSnapshotManager ¶
func NewSnapshotManager(snapshotDir string, updateMode bool) *SnapshotManager
func (*SnapshotManager) AssertSnapshot ¶
func (sm *SnapshotManager) AssertSnapshot(testName, actual string) error
func (*SnapshotManager) CleanOrphanSnapshots ¶
func (sm *SnapshotManager) CleanOrphanSnapshots(activeTests []string) error
func (*SnapshotManager) Clear ¶
func (sm *SnapshotManager) Clear()
func (*SnapshotManager) GetResults ¶
func (sm *SnapshotManager) GetResults() map[string]SnapshotResult
func (*SnapshotManager) GetSummary ¶
func (sm *SnapshotManager) GetSummary() SnapshotSummary
func (*SnapshotManager) SetUpdateMode ¶
func (sm *SnapshotManager) SetUpdateMode(update bool)
type SnapshotReporter ¶
type SnapshotReporter struct {
// contains filtered or unexported fields
}
func NewSnapshotReporter ¶
func NewSnapshotReporter() *SnapshotReporter
func (*SnapshotReporter) AddResult ¶
func (sr *SnapshotReporter) AddResult(result SnapshotResult)
func (*SnapshotReporter) ExportJSON ¶
func (sr *SnapshotReporter) ExportJSON(filename string) error
func (*SnapshotReporter) GenerateReport ¶
func (sr *SnapshotReporter) GenerateReport() string
type SnapshotResult ¶
type SnapshotSummary ¶
type SnapshotSummary struct {
TotalTests int `json:"total_tests"`
PassedTests int `json:"passed_tests"`
FailedTests int `json:"failed_tests"`
UpdatedTests int `json:"updated_tests"`
UpdateMode bool `json:"update_mode"`
}
func (SnapshotSummary) String ¶
func (ss SnapshotSummary) String() string
type SnapshotTestCase ¶
type SnapshotTestSuite ¶
type SnapshotTestSuite struct {
// contains filtered or unexported fields
}
func NewSnapshotTestSuite ¶
func NewSnapshotTestSuite(snapshotDir string, updateMode bool) *SnapshotTestSuite
func (*SnapshotTestSuite) AddTestCase ¶
func (sts *SnapshotTestSuite) AddTestCase(name, template string, data map[string]any)
func (*SnapshotTestSuite) GetManager ¶
func (sts *SnapshotTestSuite) GetManager() *SnapshotManager
func (*SnapshotTestSuite) GetTestCases ¶
func (sts *SnapshotTestSuite) GetTestCases() []SnapshotTestCase
func (*SnapshotTestSuite) LoadTestCases ¶
func (sts *SnapshotTestSuite) LoadTestCases(testFile string) error
func (*SnapshotTestSuite) SaveTestCases ¶
func (sts *SnapshotTestSuite) SaveTestCases(testFile string) error
type SystemInfo ¶
Click to show internal directories.
Click to hide internal directories.