Skip to content

feat: add plural aliases for all get subcommands and alert e2e tests - #442

Merged
nieomylnieja merged 12 commits into
mainfrom
sloctl-alert-e2e-tests
Apr 17, 2026
Merged

feat: add plural aliases for all get subcommands and alert e2e tests#442
nieomylnieja merged 12 commits into
mainfrom
sloctl-alert-e2e-tests

Conversation

@nieomylnieja

@nieomylnieja nieomylnieja commented Mar 24, 2026

Copy link
Copy Markdown
Collaborator

Motivation

There were no e2e tests covering the sloctl get alert command and its
various filtering flags. This made it hard to verify alert retrieval
behavior after changes to the CLI or the backend API.

Additionally, sloctl get subcommands only accepted singular and
PascalCase forms as aliases (e.g. sloctl get alert, sloctl get Alert).
The PascalCase plural form (e.g. Alerts, Services, SLOs) was not
available as an alias for any kind except Agent.

Summary

The alias generation loop in internal/get.go now appends the PascalCase
plural form (e.g. Alerts, AlertPolicies, Services) as an alias for
every kind. Previously only KindAgent had an explicit "Agents" alias;
that redundant entry was removed since it is now auto-generated.

Each get subcommand now accepts these alias forms:

  • Command name (lowercase plural): alerts (this is the Use field)
  • Singular lowercase: alert
  • Singular PascalCase: Alert
  • New — Plural PascalCase: Alerts

Release notes

sloctl get subcommands now accept PascalCase plural aliases. For example,
sloctl get Alerts, sloctl get Services, sloctl get AlertPolicies now
work 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-project and
alert-test-project-2 projects.

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.
@nieomylnieja nieomylnieja changed the title test: add sloctl get alert e2e tests feat: add plural aliases for all get subcommands and alert e2e tests Apr 7, 2026
@n9-machine-user n9-machine-user added enhancement New feature or request minor labels Apr 7, 2026
nieomylnieja and others added 3 commits April 8, 2026 08:05
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.
nieomylnieja and others added 3 commits April 9, 2026 13:40
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.
@nieomylnieja
nieomylnieja merged commit 293205b into main Apr 17, 2026
7 checks passed
@nieomylnieja
nieomylnieja deleted the sloctl-alert-e2e-tests branch April 17, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants