End-to-End Testing Framework
Relevant source files
The following files were used as context for generating this wiki page:
The End-to-End (E2E) Testing Framework in 2ms is designed to verify the complete functionality of the CLI tool by building the executable, running real scan commands against various sources, and validating the resulting reports. These tests ensure that the integration between the CLI layer, the scanning engine, and the reporting modules works as expected in a production-like environment.
The framework is primarily located within the tests/ directory and is distinct from unit tests, as it interacts with the compiled binary and the filesystem. It can be skipped during quick development cycles using the go test -short flag.
Sources: CONTRIBUTING.md:10-14, tests/e2e_test.go:5-8
Framework Architecture
The framework operates by programmatically managing the lifecycle of the 2ms binary. It involves building the project from source, setting up isolated test environments (temporary directories), executing CLI commands with specific flags, and parsing the generated output files to assert correctness.
Core Components
The E2E system is built around several key functional areas:
| Component | Description |
|---|---|
| CLI Wrapper | A Go struct (cli) that encapsulates the path to the compiled binary and the path where results should be stored. |
| Build System | Logic that uses go build to create a fresh binary for the current OS and Architecture before running tests. |
| Environment Setup | Utility functions to create temporary directories and populate them with sample data containing secrets. |
| Report Parser | Logic to unmarshal JSON reports generated by the CLI into Report objects for assertion. |
Sources: tests/e2e.go:17-20, tests/e2e.go:22-42, tests/e2e.go:68-81
Data Flow Execution
The following diagram illustrates the sequence of events when an E2E test case is executed:
Sources: tests/e2e.go:22-66, tests/e2e_test.go:12-32
Testing Operations
Binary Management and Execution
The framework uses the createCLI function to locate the project root and compile the binary. This ensures tests always run against the latest local changes. The run method on the cli struct automatically appends the --report-path flag to every command to ensure an artifact is produced for verification.
func (c *cli) run(command string, args ...string) error {
argsWithDefault := append([]string{command}, args...)
argsWithDefault = append(argsWithDefault, "--report-path", c.resultsPath)
cmd := exec.Command(c.executable, argsWithDefault...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
Sources: tests/e2e.go:57-66
Test Scenarios
The framework currently supports and validates several critical paths:
- Filesystem Scanning: Validates that the
filesystemcommand correctly identifies secrets in local files and populates theResultsmap in the report. - Validation Logic: Tests the
--validateflag, specifically checking if theValidationStatusfield in the report is correctly populated when scanning platforms like Confluence. - Ignore Patterns: Ensures that specific files (e.g.,
go.sum) are ignored by default and do not produce false positives, even if they contain strings that match secret patterns.
Sources: tests/e2e_test.go:12-70
Reporting and Assertions
The E2E tests rely on the reporting.Report structure to verify the engine's findings. After a CLI execution, the framework reads the JSON output and checks the TotalSecretsFound and the contents of the Results map.
Summary
The End-to-End Testing Framework provides the final layer of defense in the 2ms CI pipeline. By treating the tool as a black box and interacting through its CLI and filesystem artifacts, it guarantees that the core promise of the tool—detecting secrets and generating accurate reports—is met across different environments and scan types. Significant focus is placed on the accuracy of the JSON reports, as they serve as the primary interface for both the E2E framework and end-users.