Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nieomylnieja committed Jan 8, 2025
1 parent 026ea60 commit b79b807
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 17 deletions.
16 changes: 1 addition & 15 deletions internal/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
26 changes: 24 additions & 2 deletions test/get.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
32 changes: 32 additions & 0 deletions test/outputs/get/slo-by-service-name.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b79b807

Please sign in to comment.