diff --git a/internal/get.go b/internal/get.go index 1b77b9f..39547f3 100644 --- a/internal/get.go +++ b/internal/get.go @@ -328,21 +328,7 @@ func (g *GetCmd) newGetAgentCommand(cmd *cobra.Command) *cobra.Command { } func (g *GetCmd) newGetSLOCommand(cmd *cobra.Command) *cobra.Command { - cmd.Flags().StringVarP(&g.service, "service", "s", "", "Filter SLOs by service") - - cmd.RunE = func(cmd *cobra.Command, args []string) error { - objects, err := g.getObjects(cmd.Context(), args, manifest.KindSLO) - if err != nil { - return err - } - if objects == nil { - return nil - } - if err = g.printObjects(objects); err != nil { - return err - } - return nil - } + cmd.Flags().StringVarP(&g.service, "service", "s", "", "Filter SLOs by service name.") return cmd } diff --git a/test/get.bats b/test/get.bats index a56ff45..55fcb87 100644 --- a/test/get.bats +++ b/test/get.bats @@ -80,14 +80,36 @@ setup() { test_get "SLO" "$aliases" "${TEST_INPUTS}/slos.yaml" "$output" } +@test "slos filtered by service name" { + # Default project, no matches. + run_sloctl get slo -s deputy-office + assert_success_joined_output + assert_output "No resources found." + + # Wrong name, no matches. + run_sloctl get slo -s deputy-office -p death-star newrelic-rolling-timeslices-threshold-deputy-home + assert_success_joined_output + assert_output "No resources found." + + want=$(read_files "${TEST_OUTPUTS}/slo-by-service-name.yaml") + for flag_alias in "-s" "--service"; do + run_sloctl get slo "$flag_alias" deputy-office -p death-star + verify_get_success "$output" "$want" + done + + # Combine all filters. + run_sloctl get slo -s deputy-office -p death-star newrelic-rolling-timeslices-threshold-deputy-office + verify_get_success "$output" "$want" +} + @test "budget adjustments" { aliases="budgetadjustment budgetadjustments" test_get "BudgetAdjustment" "$aliases" "${TEST_INPUTS}/budgetadjustments.yaml" "$output" } @test "reports" { - aliases="report reports" - test_get "Report" "$aliases" "${TEST_INPUTS}/reports.yaml" "$output" + aliases="report reports" + test_get "Report" "$aliases" "${TEST_INPUTS}/reports.yaml" "$output" } @test "agent" { diff --git a/test/outputs/get/slo-by-service-name.yaml b/test/outputs/get/slo-by-service-name.yaml new file mode 100644 index 0000000..0dca9cd --- /dev/null +++ b/test/outputs/get/slo-by-service-name.yaml @@ -0,0 +1,32 @@ +- apiVersion: n9/v1alpha + kind: SLO + metadata: + name: newrelic-rolling-timeslices-threshold-deputy-office + project: death-star + spec: + description: This SLO is just for the e2e 'sloctl get' tests, it's not supposed to work! + service: deputy-office + indicator: + metricSource: + kind: Direct + name: newrelic-direct + timeWindows: + - count: 1 + isRolling: true + unit: Hour + budgetingMethod: Timeslices + objectives: + - target: 0.99 + op: lte + rawMetric: + query: + newRelic: + nrql: SELECT average(duration) FROM Transaction TIMESERIES + displayName: stretched + timeSliceTarget: 0.99 + value: 1.2 + name: objective-1 + primary: false + alertPolicies: + - trigger-alert-immediately + - budget-will-be-burn-in-3days