feat: add plural aliases for all get subcommands and alert e2e tests - #442
Merged
Conversation
Add bats e2e tests for the 'sloctl get alert' command covering: - Listing all alerts in a project - Command aliases (alert, alerts, Alert, Alerts) - Filtering by --slo, --service, --alert-policy, --objective - Status filters (--triggered, --resolved) - Time range filters (--from, --to) - Combined filter combinations - Output formats (-o json, -o yaml) - JQ filtering (--jq, -q) - All-projects flag (-A) - Alert structure field validation - Get alert by name
Add verify_alerts, assert_alert_count, and assert_all_alerts_have_fields helpers. Each test now checks exact alert counts, all field values (severity, status, slo, service, alertPolicy, objective), and validates structural completeness of every alert in the response.
Replace inline yq assertions with expected output YAML files in test/outputs/get-alerts-e2e/, following the same pattern as get.bats. Each filter scenario now loads expected output via read_files and compares using verify_alert_output which checks all stable fields (name, project, severity, status, slo, service, alertPolicy, objective).
Updates alert test fixtures and comparison logic to validate all fields as static data from the API, only stripping environment-dependent fields (metadata.name UUID and organization). Moves configuration to setup_file() following BATS best practices, simplifies verify_alert_output to only strip env-dependent fields, and removes redundant field validation assertions. All alert YAML fixtures now include complete field definitions (displayName, project, timestamps, conditions, coolDown) that were previously stripped during comparison.
Refactor the get alerts tests to filter by alert-policy instead of SLO and service filters. Simplify test data by consolidating multiple SLOs, services, and objectives into single entities. Update alert fixture files with new project names and policy-based alert structure. Add secondary test project for multi-project testing. Improve command alias generation in get.go to support plural forms.
Replace placeholder metadata.name with static UUIDs in all alert output files and update verify_alert_output to compare them. Update all output files to match actual API response structure. Replace weak time-range tests (refute "No resources found") with proper subset verification against expected output files.
Implement new filtering options for the `get alert` command, allowing users to filter alerts by their associated SLO objective (e.g., `--objective default`). This includes new test cases for both single and combined alert filters. Expand test coverage for `get` commands by adding capitalized aliases (e.g., `AlertMethods`, `Agents`) for various resource kinds. Refactor internal `get` command definition by removing a redundant 'Agents' alias.
nobl9-adam-szymanski
approved these changes
Apr 8, 2026
The `get alert --resolved` command should also return canceled alerts. This commit updates the test to reflect this behavior and refactors the verification logic to handle canceled alerts by normalizing them to resolved status for comparison.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
There were no e2e tests covering the
sloctl get alertcommand and itsvarious filtering flags. This made it hard to verify alert retrieval
behavior after changes to the CLI or the backend API.
Additionally,
sloctl getsubcommands only accepted singular andPascalCase forms as aliases (e.g.
sloctl get alert,sloctl get Alert).The PascalCase plural form (e.g.
Alerts,Services,SLOs) was notavailable as an alias for any kind except Agent.
Summary
The alias generation loop in
internal/get.gonow appends the PascalCaseplural form (e.g.
Alerts,AlertPolicies,Services) as an alias forevery kind. Previously only
KindAgenthad an explicit"Agents"alias;that redundant entry was removed since it is now auto-generated.
Each
getsubcommand now accepts these alias forms:alerts(this is theUsefield)alertAlertAlertsRelease notes
sloctl getsubcommands now accept PascalCase plural aliases. For example,sloctl get Alerts,sloctl get Services,sloctl get AlertPoliciesnowwork in addition to the existing lowercase and singular forms.
Testing
Added a comprehensive bats e2e tests (
test/get-alerts-e2e.bats).The tests rely on alerts pre-populated in the
alert-test-projectandalert-test-project-2projects.