testing

package
v0.0.0-...-849b37b Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 21 Imported by: 0

README

Testing Package

This package provides test execution and coverage aggregation for multi-language projects.

Implementation Status

Phase 1: Core Infrastructure (COMPLETE ✅)

Completed:

  • ✅ Type definitions (types.go)

    • TestConfig - Global test configuration
    • ServiceTestConfig - Per-service test configuration
    • TestResult - Test execution results
    • CoverageData - Coverage metrics
    • AggregateResult - Combined results
    • AggregateCoverage - Aggregated coverage
  • ✅ Test command (commands/test.go)

    • All flags defined and working
    • Input validation (test type, threshold, output format)
    • Integration with command orchestrator
    • Dry-run mode
    • Full test execution workflow
  • ✅ Test orchestrator (orchestrator.go)

    • Loads services from azure.yaml
    • Framework auto-detection (Node.js, Python, .NET)
    • Test execution management
    • Result aggregation
    • Service filtering
  • ✅ Node.js test runner (node_runner.go)

    • Framework detection (Jest, Vitest, Mocha)
    • Test command generation
    • Test execution
    • Output parsing
    • Result extraction
  • ✅ Unit tests

    • Type definitions tested
    • Command structure tested
    • Validation logic tested
Phase 2: Language Runners (COMPLETE ✅)

Completed:

  • ✅ Node.js test runner with Jest/Vitest/Mocha support
  • ✅ Python test runner with pytest/unittest support
  • ✅ .NET test runner with xUnit/NUnit/MSTest support
  • ✅ Framework auto-detection for all languages
  • ✅ Test output parsing for all frameworks
Phases 3-5: Continued Implementation

Phase 3: Coverage Aggregation (COMPLETE ✅)

  • ✅ Coverage aggregator implementation
  • ✅ Multi-format report generation (JSON, Cobertura XML, HTML)
  • ✅ Threshold validation
  • ✅ Coverage tests

Phase 4-5: Future Enhancements

  • ⏳ Watch mode (optional)
  • ⏳ Setup/teardown commands (optional)
  • ⏳ Advanced output formats (JUnit, GitHub Actions) (optional)

See implementation plan for details.

Current Functionality

The test command is fully functional for Node.js, Python, and .NET projects. You can:

# View help and all available flags
azd app test --help

# Run tests for all services (requires azure.yaml)
azd app test

# Run specific test type
azd app test --type unit

# Run tests for specific service
azd app test --service web

# Dry-run to see what would be tested
azd app test --dry-run --type unit --coverage --threshold 80

# Validate parameters
azd app test --type unit        # ✓ Valid
azd app test --type invalid     # ✗ Error: invalid test type
azd app test --threshold 150    # ✗ Error: threshold must be 0-100

Usage Example

Create an azure.yaml with your services:

name: my-app
reqs:
  - id: node
    minVersion: "18.0.0"
  - id: python
    minVersion: "3.9.0"
  - id: dotnet
    minVersion: "8.0.0"
services:
  web:
    language: js
    project: ./web
  api:
    language: python
    project: ./api
  gateway:
    language: csharp
    project: ./gateway

Ensure your projects have test scripts:

Node.js (package.json):

{
  "scripts": {
    "test": "jest"
  }
}

Python (tests directory with pytest):

api/
  tests/
    test_api.py
  pyproject.toml

.NET (test project):

gateway/
  Gateway.Tests/
    Gateway.Tests.csproj

Then run:

azd app test

Architecture

TestOrchestrator ✅
     ↓
  ┌──┴──┬──────┬────────┐
  │     │      │        │
Node  Python  .NET   Coverage
Runner Runner Runner  Aggregator
  ✅     ✅      ✅       ✅

Framework Detection

Node.js ✅
  • Checks for jest.config.*, vitest.config.*, .mocharc.*
  • Falls back to checking package.json dependencies
  • Defaults to npm test
Python ✅
  • Checks for pytest.ini, pyproject.toml, setup.cfg
  • Detects package manager (uv, poetry, pip)
  • Supports pytest markers for test type filtering
  • Falls back to unittest if pytest not detected
.NET ✅
  • Scans for *.Tests.csproj files
  • Supports test filtering with --filter argument
  • Works with xUnit, NUnit, and MSTest frameworks
  • Supports code coverage with coverlet

Contributing

When adding functionality:

  1. Update type definitions as needed
  2. Add unit tests for all new functions
  3. Update this README with implementation status
  4. Follow existing code patterns

See implementation plan for the complete roadmap.

Documentation

Overview

Package testing provides test execution and coverage aggregation for multi-language projects.

Package testing provides test execution and coverage aggregation for multi-language projects.

Package testing provides test execution and coverage aggregation for multi-language projects.

Package testing provides test execution and coverage aggregation for multi-language projects.

Package testing provides test execution and coverage aggregation for multi-language projects.

Package testing provides test execution and coverage aggregation for multi-language projects.

Package testing provides test execution and coverage aggregation for multi-language projects.

Package testing provides test execution and coverage aggregation for multi-language projects.

Package testing provides test execution and coverage aggregation for multi-language projects.

Package testing provides test execution and coverage aggregation for multi-language projects.

Package testing provides test execution and coverage aggregation for multi-language projects.

Index

Constants

View Source
const (
	// CoverageThresholdHigh is the percentage above which coverage is considered high (green)
	CoverageThresholdHigh = 80.0
	// CoverageThresholdMedium is the percentage above which coverage is considered medium (yellow)
	CoverageThresholdMedium = 50.0
	// MinCoverageThreshold is the minimum valid coverage threshold (0%)
	MinCoverageThreshold = 0.0
	// MaxCoverageThreshold is the maximum valid coverage threshold (100%)
	MaxCoverageThreshold = 100.0
)

Coverage threshold constants for UI display.

View Source
const (
	// DefaultPollInterval is the default interval for file system polling
	DefaultPollInterval = 500 * time.Millisecond
	// DefaultDebounceDelay is the default delay for debouncing file change events
	DefaultDebounceDelay = 300 * time.Millisecond
)

File watcher timing constants.

View Source
const (
	// DirPermissions is the default permission mode for directories
	DirPermissions = 0o755
	// FilePermissions is the default permission mode for files
	FilePermissions = 0o644
)

File permission constants.

View Source
const DefaultTestTimeout = 10 * time.Minute

DefaultTestTimeout is the default timeout for test execution per service.

Variables

This section is empty.

Functions

func FindAzureYaml

func FindAzureYaml() (string, error)

FindAzureYaml finds the azure.yaml file in the current or parent directories.

func GenerateTestConfigYAML

func GenerateTestConfigYAML(validations []ServiceValidation, services []ServiceInfo) string

GenerateTestConfigYAML generates a YAML snippet for discovered test configurations. Only includes services that were auto-detected (had no config in azure.yaml). Returns an empty string if no auto-detected services are found.

func IsTTY

func IsTTY() bool

IsTTY checks if stdout is a terminal (TTY). This is used to determine if we can use interactive output like progress bars.

func ParseCommandString

func ParseCommandString(cmdStr string) []string

ParseCommandString parses a command string into command and args. Handles quoted strings to preserve arguments with spaces.

func SaveTestConfigToAzureYaml

func SaveTestConfigToAzureYaml(azureYamlPath string, validations []ServiceValidation, services []ServiceInfo) error

SaveTestConfigToAzureYaml merges discovered test config into azure.yaml. Only adds test config for services that don't already have it. Preserves existing content and formatting as much as possible.

Types

type AggregateCoverage

type AggregateCoverage struct {
	// Services maps service name to coverage data
	Services map[string]*CoverageData
	// Aggregate is the combined coverage across all services
	Aggregate *CoverageData
	// Threshold is the required coverage threshold
	Threshold float64
	// Met indicates whether the threshold was met
	Met bool
}

AggregateCoverage represents aggregated coverage across all services.

type AggregateResult

type AggregateResult struct {
	// Services contains results for each service
	Services []*TestResult
	// Passed is the total number of passed tests
	Passed int
	// Failed is the total number of failed tests
	Failed int
	// Skipped is the total number of skipped tests
	Skipped int
	// Total is the total number of tests
	Total int
	// Duration is the total test execution time
	Duration float64
	// Coverage is the aggregated coverage data
	Coverage *AggregateCoverage
	// Success indicates whether all tests passed
	Success bool
	// Error message if test execution failed
	Error string
}

AggregateResult represents aggregated test results from all services.

type CoberturaClass

type CoberturaClass struct {
	XMLName    xml.Name        `xml:"class"`
	Name       string          `xml:"name,attr"`
	Filename   string          `xml:"filename,attr"`
	LineRate   float64         `xml:"line-rate,attr"`
	BranchRate float64         `xml:"branch-rate,attr"`
	Complexity float64         `xml:"complexity,attr"`
	Lines      []CoberturaLine `xml:"lines>line,omitempty"`
}

CoberturaClass represents a class in Cobertura format

type CoberturaCoverage

type CoberturaCoverage struct {
	XMLName    xml.Name           `xml:"coverage"`
	LineRate   float64            `xml:"line-rate,attr"`
	BranchRate float64            `xml:"branch-rate,attr"`
	Version    string             `xml:"version,attr"`
	Timestamp  int64              `xml:"timestamp,attr"`
	Sources    []string           `xml:"sources>source,omitempty"`
	Packages   []CoberturaPackage `xml:"packages>package"`
}

CoberturaCoverage represents the root Cobertura XML structure

type CoberturaLine

type CoberturaLine struct {
	XMLName xml.Name `xml:"line"`
	Number  int      `xml:"number,attr"`
	Hits    int      `xml:"hits,attr"`
}

CoberturaLine represents a line in Cobertura format

type CoberturaPackage

type CoberturaPackage struct {
	XMLName    xml.Name         `xml:"package"`
	Name       string           `xml:"name,attr"`
	LineRate   float64          `xml:"line-rate,attr"`
	BranchRate float64          `xml:"branch-rate,attr"`
	Complexity float64          `xml:"complexity,attr"`
	Classes    []CoberturaClass `xml:"classes>class"`
}

CoberturaPackage represents a package in Cobertura format

type CoverageAggregator

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

CoverageAggregator collects and merges coverage data from multiple services

func NewCoverageAggregator

func NewCoverageAggregator(threshold float64, outputDir string) *CoverageAggregator

NewCoverageAggregator creates a new coverage aggregator

func (*CoverageAggregator) AddCoverage

func (a *CoverageAggregator) AddCoverage(service string, data *CoverageData) error

AddCoverage adds coverage data for a service

func (*CoverageAggregator) Aggregate

func (a *CoverageAggregator) Aggregate() *AggregateCoverage

Aggregate calculates aggregate coverage metrics across all services

func (*CoverageAggregator) CheckThreshold

func (a *CoverageAggregator) CheckThreshold() (bool, float64)

CheckThreshold checks if aggregate coverage meets the threshold

func (*CoverageAggregator) GenerateAllReports

func (a *CoverageAggregator) GenerateAllReports() error

GenerateAllReports generates all coverage report formats

func (*CoverageAggregator) GenerateReport

func (a *CoverageAggregator) GenerateReport(format string) error

GenerateReport generates coverage reports in various formats

func (*CoverageAggregator) SetSourceRoot

func (a *CoverageAggregator) SetSourceRoot(root string)

SetSourceRoot sets the root path for source file linking in reports

type CoverageConfig

type CoverageConfig struct {
	// Enabled indicates whether to collect coverage
	Enabled bool `yaml:"enabled" json:"enabled"`
	// Tool is the coverage tool name
	Tool string `yaml:"tool" json:"tool"`
	// Threshold is the minimum coverage percentage for this service
	Threshold float64 `yaml:"threshold" json:"threshold"`
	// Source is the source directory to measure coverage (Python)
	Source string `yaml:"source" json:"source"`
	// OutputFormat is the coverage output format
	OutputFormat string `yaml:"outputFormat" json:"outputFormat"`
	// Exclude are files/patterns to exclude from coverage
	Exclude []string `yaml:"exclude" json:"exclude"`
}

CoverageConfig represents coverage configuration.

type CoverageData

type CoverageData struct {
	// Lines coverage metric
	Lines CoverageMetric
	// Branches coverage metric
	Branches CoverageMetric
	// Functions coverage metric
	Functions CoverageMetric
	// Files contains per-file coverage data
	Files []*FileCoverage
}

CoverageData represents coverage data for a service.

type CoverageJSONReport

type CoverageJSONReport struct {
	Generated    string                      `json:"generated"`
	Threshold    float64                     `json:"threshold"`
	ThresholdMet bool                        `json:"threshold_met"`
	Summary      CoverageSummary             `json:"summary"`
	Services     map[string]*ServiceCoverage `json:"services"`
	Files        []*FileCoverageReport       `json:"files,omitempty"`
}

CoverageJSONReport is the JSON report structure

type CoverageMetric

type CoverageMetric struct {
	// Covered is the number of covered items
	Covered int
	// Total is the total number of items
	Total int
	// Percent is the coverage percentage
	Percent float64
}

CoverageMetric represents a coverage metric.

type CoverageSummary

type CoverageSummary struct {
	Lines         CoverageMetric `json:"lines"`
	TotalFiles    int            `json:"total_files"`
	TotalServices int            `json:"total_services"`
}

CoverageSummary contains overall coverage statistics

type DetectedTestTypes

type DetectedTestTypes struct {
	HasUnit          bool
	HasIntegration   bool
	HasE2E           bool
	UnitPaths        []string
	IntegrationPaths []string
	E2EPaths         []string
}

DetectedTestTypes represents the test types found in a directory.

func DetectServiceTestTypes

func DetectServiceTestTypes(dir, language string) *DetectedTestTypes

DetectServiceTestTypes detects test types for a service. This is a convenience function for use by the orchestrator.

type DotnetTestRunner

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

DotnetTestRunner runs tests for .NET projects.

func NewDotnetTestRunner

func NewDotnetTestRunner(projectDir string, config *ServiceTestConfig) *DotnetTestRunner

NewDotnetTestRunner creates a new .NET test runner.

func (*DotnetTestRunner) HasTests

func (r *DotnetTestRunner) HasTests() bool

HasTests checks if the project has test files.

func (*DotnetTestRunner) RunTests

func (r *DotnetTestRunner) RunTests(testType string, coverage bool) (*TestResult, error)

RunTests executes tests for the .NET project.

type FileCoverage

type FileCoverage struct {
	// Path is the file path
	Path string
	// Lines coverage metric
	Lines CoverageMetric
	// Branches coverage metric
	Branches CoverageMetric
	// Functions coverage metric
	Functions CoverageMetric
	// CoveredLines are the line numbers that are covered
	CoveredLines []int
	// LineHits maps line numbers to the number of times they were executed
	LineHits map[int]int
}

FileCoverage represents coverage for a single file.

type FileCoverageReport

type FileCoverageReport struct {
	Path           string         `json:"path"`
	Lines          CoverageMetric `json:"lines"`
	UncoveredLines []int          `json:"uncovered_lines,omitempty"`
}

FileCoverageReport contains coverage data for a single file

type FileWatcher

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

FileWatcher monitors files for changes and triggers test re-runs

func NewFileWatcher

func NewFileWatcher(paths []string, opts ...WatcherOption) *FileWatcher

NewFileWatcher creates a new file watcher for the given paths

func (*FileWatcher) AddIgnorePattern

func (w *FileWatcher) AddIgnorePattern(pattern string)

AddIgnorePattern adds a pattern to ignore during file watching

func (*FileWatcher) SetPollInterval

func (w *FileWatcher) SetPollInterval(interval time.Duration)

SetPollInterval sets the polling interval for file changes

func (*FileWatcher) SetServicePathMap

func (w *FileWatcher) SetServicePathMap(services map[string]string)

SetServicePathMap configures the mapping of service paths to names

func (*FileWatcher) Watch

func (w *FileWatcher) Watch(ctx context.Context, callback func() error) error

Watch monitors files for changes and calls the callback when changes are detected

func (*FileWatcher) WatchWithServiceFilter

func (w *FileWatcher) WatchWithServiceFilter(ctx context.Context, callback WatchCallback) error

WatchWithServiceFilter monitors files and provides affected services to callback

type GoTestRunner

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

GoTestRunner runs tests for Go projects.

func NewGoTestRunner

func NewGoTestRunner(projectDir string, config *ServiceTestConfig) *GoTestRunner

NewGoTestRunner creates a new Go test runner.

func (*GoTestRunner) HasTests

func (r *GoTestRunner) HasTests() bool

HasTests checks if the project has test files.

func (*GoTestRunner) ParseCoverageProfile

func (r *GoTestRunner) ParseCoverageProfile(profilePath string) (*CoverageData, error)

ParseCoverageProfile parses a Go coverage profile file.

func (*GoTestRunner) RunTests

func (r *GoTestRunner) RunTests(testType string, coverage bool) (*TestResult, error)

RunTests executes tests for the Go project.

type JUnitError

type JUnitError struct {
	Message string `xml:"message,attr,omitempty"`
	Type    string `xml:"type,attr,omitempty"`
	Content string `xml:",chardata"`
}

JUnitError represents a test error in JUnit XML.

type JUnitFailure

type JUnitFailure struct {
	Message string `xml:"message,attr,omitempty"`
	Type    string `xml:"type,attr,omitempty"`
	Content string `xml:",chardata"`
}

JUnitFailure represents a test failure in JUnit XML.

type JUnitSkipped

type JUnitSkipped struct {
	Message string `xml:"message,attr,omitempty"`
}

JUnitSkipped represents a skipped test in JUnit XML.

type JUnitTestCase

type JUnitTestCase struct {
	XMLName   xml.Name      `xml:"testcase"`
	Name      string        `xml:"name,attr"`
	ClassName string        `xml:"classname,attr"`
	Time      float64       `xml:"time,attr"`
	Failure   *JUnitFailure `xml:"failure,omitempty"`
	Error     *JUnitError   `xml:"error,omitempty"`
	Skipped   *JUnitSkipped `xml:"skipped,omitempty"`
	SystemOut string        `xml:"system-out,omitempty"`
	SystemErr string        `xml:"system-err,omitempty"`
}

JUnitTestCase represents a test case in JUnit XML.

type JUnitTestSuite

type JUnitTestSuite struct {
	XMLName   xml.Name        `xml:"testsuite"`
	Name      string          `xml:"name,attr"`
	Tests     int             `xml:"tests,attr"`
	Failures  int             `xml:"failures,attr"`
	Errors    int             `xml:"errors,attr"`
	Skipped   int             `xml:"skipped,attr"`
	Time      float64         `xml:"time,attr"`
	Timestamp string          `xml:"timestamp,attr,omitempty"`
	TestCases []JUnitTestCase `xml:"testcase"`
}

JUnitTestSuite represents a test suite in JUnit XML.

type JUnitTestSuites

type JUnitTestSuites struct {
	XMLName    xml.Name         `xml:"testsuites"`
	Name       string           `xml:"name,attr,omitempty"`
	Tests      int              `xml:"tests,attr"`
	Failures   int              `xml:"failures,attr"`
	Errors     int              `xml:"errors,attr"`
	Skipped    int              `xml:"skipped,attr"`
	Time       float64          `xml:"time,attr"`
	Timestamp  string           `xml:"timestamp,attr,omitempty"`
	TestSuites []JUnitTestSuite `xml:"testsuite"`
}

JUnitTestSuites represents the root element of JUnit XML.

type NodeTestRunner

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

NodeTestRunner runs tests for Node.js projects.

func NewNodeTestRunner

func NewNodeTestRunner(projectDir string, config *ServiceTestConfig) *NodeTestRunner

NewNodeTestRunner creates a new Node.js test runner.

func (*NodeTestRunner) HasTests

func (r *NodeTestRunner) HasTests() bool

HasTests checks if the project has test files.

func (*NodeTestRunner) RunTests

func (r *NodeTestRunner) RunTests(testType string, coverage bool) (*TestResult, error)

RunTests executes tests for the Node.js project.

type OutputMode

type OutputMode int

OutputMode represents the output display mode for test results.

const (
	// OutputModeStream shows direct streaming output without prefixes.
	// Best for single service or when user wants raw output.
	OutputModeStream OutputMode = iota

	// OutputModeStreamPrefixed shows streaming output with [service] prefix.
	// Best for multiple services running sequentially to distinguish output.
	OutputModeStreamPrefixed

	// OutputModeProgress shows progress bars for test execution.
	// Best for multiple services running in parallel.
	OutputModeProgress
)

func SelectOutputMode

func SelectOutputMode(opts OutputModeOptions, serviceCount int, isTTY bool) OutputMode

SelectOutputMode determines the best output mode based on options and environment. Selection logic:

  • --stream flag → OutputModeStream (explicit user preference)
  • --no-stream flag → OutputModeProgress (explicit user preference)
  • CI/non-TTY → always OutputModeStream (with prefix if multiple services)
  • Single service → OutputModeStream (no prefix)
  • Multiple + sequential (parallel=false) → OutputModeStreamPrefixed
  • Multiple + parallel → OutputModeProgress

func (OutputMode) String

func (m OutputMode) String() string

String returns the string representation of the OutputMode.

type OutputModeOptions

type OutputModeOptions struct {
	// ForceStream forces streaming output mode (--stream flag).
	ForceStream bool
	// ForceProgress forces progress bar mode (--no-stream flag).
	ForceProgress bool
	// Parallel indicates if tests run in parallel.
	Parallel bool
}

OutputModeOptions contains options for selecting output mode.

type ProgressCallback

type ProgressCallback func(event ProgressEvent)

ProgressCallback is a function that gets called during test execution to report progress.

type ProgressEvent

type ProgressEvent struct {
	// Type indicates the type of progress event
	Type ProgressEventType
	// Service is the name of the service (if applicable)
	Service string
	// Framework is the test framework being used (if applicable)
	Framework string
	// Message is an optional message for the event
	Message string
}

ProgressEvent represents a progress update during test execution.

type ProgressEventType

type ProgressEventType int

ProgressEventType represents the type of progress event.

const (
	// ProgressEventValidationStart indicates validation is starting
	ProgressEventValidationStart ProgressEventType = iota
	// ProgressEventServiceValidated indicates a service has been validated
	ProgressEventServiceValidated
	// ProgressEventValidationComplete indicates validation is complete
	ProgressEventValidationComplete
	// ProgressEventTestStart indicates tests are starting for a service
	ProgressEventTestStart
	// ProgressEventTestComplete indicates tests have completed for a service
	ProgressEventTestComplete
	// ProgressEventServiceSkipped indicates a service was skipped
	ProgressEventServiceSkipped
)

type PythonTestRunner

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

PythonTestRunner runs tests for Python projects.

func NewPythonTestRunner

func NewPythonTestRunner(projectDir string, config *ServiceTestConfig) *PythonTestRunner

NewPythonTestRunner creates a new Python test runner.

func (*PythonTestRunner) HasTests

func (r *PythonTestRunner) HasTests() bool

HasTests checks if the project has test files.

func (*PythonTestRunner) RunTests

func (r *PythonTestRunner) RunTests(testType string, coverage bool) (*TestResult, error)

RunTests executes tests for the Python project.

type ReportGenerator

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

ReportGenerator generates test reports in various formats.

func NewReportGenerator

func NewReportGenerator(format, outputDir string) *ReportGenerator

NewReportGenerator creates a new report generator.

func (*ReportGenerator) GenerateTestReport

func (g *ReportGenerator) GenerateTestReport(results *AggregateResult) error

GenerateTestReport generates a test report based on the configured format.

type ServiceCoverage

type ServiceCoverage struct {
	Lines CoverageMetric        `json:"lines"`
	Files []*FileCoverageReport `json:"files,omitempty"`
}

ServiceCoverage contains coverage data for a single service

type ServiceInfo

type ServiceInfo struct {
	Name     string
	Language string
	Dir      string
	Config   *ServiceTestConfig
}

ServiceInfo represents a service with its test configuration.

type ServiceTestConfig

type ServiceTestConfig struct {
	// Framework is the test framework name (jest, pytest, xunit, etc.)
	Framework string `yaml:"framework" json:"framework"`
	// Unit test configuration
	Unit *TestTypeConfig `yaml:"unit" json:"unit"`
	// Integration test configuration
	Integration *TestTypeConfig `yaml:"integration" json:"integration"`
	// E2E test configuration
	E2E *TestTypeConfig `yaml:"e2e" json:"e2e"`
	// Coverage configuration
	Coverage *CoverageConfig `yaml:"coverage" json:"coverage"`
}

ServiceTestConfig represents test configuration for a service.

func SuggestTestTypeConfig

func SuggestTestTypeConfig(dir, language string) *ServiceTestConfig

SuggestTestTypeConfig generates a suggested TestTypeConfig based on detection.

type ServiceValidation

type ServiceValidation struct {
	// Name is the service name
	Name string
	// Language is the programming language
	Language string
	// Framework is the detected test framework
	Framework string
	// TestFiles is the count of test files found
	TestFiles int
	// CanTest indicates if the service can be tested
	CanTest bool
	// SkipReason explains why a service cannot be tested (if CanTest is false)
	SkipReason string
}

ServiceValidation represents the validation result for a service's testability.

func GetAutoDetectedServices

func GetAutoDetectedServices(validations []ServiceValidation, services []ServiceInfo) []ServiceValidation

GetAutoDetectedServices returns services that were auto-detected (had no config in azure.yaml).

func GetSkippedServices

func GetSkippedServices(validations []ServiceValidation) []ServiceValidation

GetSkippedServices returns only the services that cannot be tested.

func GetTestableServices

func GetTestableServices(validations []ServiceValidation) []ServiceValidation

GetTestableServices returns only the services that can be tested.

func ValidateService

func ValidateService(service ServiceInfo) ServiceValidation

ValidateService checks if a service is testable and returns validation details.

func ValidateServices

func ValidateServices(services []ServiceInfo) []ServiceValidation

ValidateServices validates all services and returns validation results.

type TestConfig

type TestConfig struct {
	// Parallel indicates whether to run tests for services in parallel
	Parallel bool
	// FailFast indicates whether to stop on first test failure
	FailFast bool
	// CoverageThreshold is the minimum coverage percentage required (0-100)
	CoverageThreshold float64
	// OutputDir is the directory for test reports and coverage
	OutputDir string
	// Verbose enables verbose test output
	Verbose bool
	// Timeout is the per-service test timeout duration
	// Default is 10 minutes if not set
	Timeout time.Duration
}

TestConfig represents the global test configuration.

type TestFailure

type TestFailure struct {
	// Name is the test name
	Name string
	// Message is the failure message
	Message string
	// StackTrace is the failure stack trace
	StackTrace string
	// File is the file where the test failed
	File string
	// Line is the line number where the test failed
	Line int
}

TestFailure represents a single test failure.

type TestOrchestrator

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

TestOrchestrator manages test execution across services.

func NewTestOrchestrator

func NewTestOrchestrator(config *TestConfig) *TestOrchestrator

NewTestOrchestrator creates a new test orchestrator.

func (*TestOrchestrator) DetectTestConfig

func (o *TestOrchestrator) DetectTestConfig(service ServiceInfo) (*ServiceTestConfig, error)

DetectTestConfig auto-detects test configuration for a service.

func (*TestOrchestrator) ExecuteTests

func (o *TestOrchestrator) ExecuteTests(testType string, serviceFilter []string) (*AggregateResult, error)

ExecuteTests runs tests for all services.

func (*TestOrchestrator) ExecuteTestsWithValidation

func (o *TestOrchestrator) ExecuteTestsWithValidation(testType string, serviceFilter []string) (*AggregateResult, []ServiceValidation, error)

ExecuteTestsWithValidation validates services and runs tests only for testable services. Returns validation results along with test results.

func (*TestOrchestrator) GetAvailableTestTypes

func (o *TestOrchestrator) GetAvailableTestTypes() map[string][]string

GetAvailableTestTypes returns a map of available test types per service.

func (*TestOrchestrator) GetAvailableTestTypesForService

func (o *TestOrchestrator) GetAvailableTestTypesForService(service ServiceInfo) []string

GetAvailableTestTypesForService returns available test types for a service.

func (*TestOrchestrator) GetServicePaths

func (o *TestOrchestrator) GetServicePaths() ([]string, error)

GetServicePaths returns the paths of all services for file watching.

func (*TestOrchestrator) GetServices

func (o *TestOrchestrator) GetServices() []ServiceInfo

GetServices returns the loaded services.

func (*TestOrchestrator) LoadServicesFromAzureYaml

func (o *TestOrchestrator) LoadServicesFromAzureYaml(azureYamlPath string) error

LoadServicesFromAzureYaml loads service information from azure.yaml.

func (*TestOrchestrator) SetProgressCallback

func (o *TestOrchestrator) SetProgressCallback(callback ProgressCallback)

SetProgressCallback sets the callback function for progress updates.

func (*TestOrchestrator) ValidateAllServices

func (o *TestOrchestrator) ValidateAllServices() []ServiceValidation

ValidateAllServices validates all loaded services for testability.

type TestResult

type TestResult struct {
	// Service name
	Service string
	// TestType is the type of test (unit, integration, e2e)
	TestType string
	// Passed is the number of passed tests
	Passed int
	// Failed is the number of failed tests
	Failed int
	// Skipped is the number of skipped tests
	Skipped int
	// Total is the total number of tests
	Total int
	// Duration is the test execution time in seconds
	Duration float64
	// Failures contains details of failed tests
	Failures []TestFailure
	// Coverage data (if coverage was enabled)
	Coverage *CoverageData
	// Success indicates whether all tests passed
	Success bool
	// Error message if test execution failed
	Error string
}

TestResult represents the result of running tests for a service.

type TestRunner

type TestRunner interface {
	RunTests(testType string, coverage bool) (*TestResult, error)
}

TestRunner interface for language-specific test runners.

type TestTypeConfig

type TestTypeConfig struct {
	// Command is the command to run tests
	Command string `yaml:"command" json:"command"`
	// Pattern is the test file pattern (Node.js)
	Pattern string `yaml:"pattern" json:"pattern"`
	// Markers are pytest markers to filter tests (Python)
	Markers []string `yaml:"markers" json:"markers"`
	// Filter is the test filter expression (.NET)
	Filter string `yaml:"filter" json:"filter"`
	// Projects are test project paths (.NET)
	Projects []string `yaml:"projects" json:"projects"`
	// Setup commands to run before tests
	Setup []string `yaml:"setup" json:"setup"`
	// Teardown commands to run after tests
	Teardown []string `yaml:"teardown" json:"teardown"`
}

TestTypeConfig represents configuration for a specific test type.

type TestTypeDetector

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

TestTypeDetector detects available test types in a service directory.

func NewTestTypeDetector

func NewTestTypeDetector(dir, language string) *TestTypeDetector

NewTestTypeDetector creates a new test type detector.

func (*TestTypeDetector) Detect

func (d *TestTypeDetector) Detect() *DetectedTestTypes

Detect detects all available test types in the service directory.

func (*TestTypeDetector) GetAvailableTestTypes

func (d *TestTypeDetector) GetAvailableTestTypes() []string

GetAvailableTestTypes returns a list of available test types.

type WatchCallback

type WatchCallback func(changedServices []string) error

WatchCallback is called when changes are detected changedServices is the list of services with changes (empty means run all)

type WatcherOption

type WatcherOption func(*FileWatcher)

WatcherOption configures the file watcher

func WithClearConsole

func WithClearConsole(clear bool) WatcherOption

WithClearConsole enables clearing the console between runs

func WithDebounceDelay

func WithDebounceDelay(delay time.Duration) WatcherOption

WithDebounceDelay sets the debounce delay for file changes

func WithServicePathMap

func WithServicePathMap(mapping map[string]string) WatcherOption

WithServicePathMap sets the mapping from file paths to service names

func WithShowElapsedTime

func WithShowElapsedTime(show bool) WatcherOption

WithShowElapsedTime enables showing elapsed time since last run

Directories

Path Synopsis
Package testports provides shared port constants for testing.
Package testports provides shared port constants for testing.

Jump to

Keyboard shortcuts

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