Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/cli/incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func newIncidentGetCmd() *cobra.Command {
return &cobra.Command{
Use: "get <id> [<id2> ...]",
Short: "Get incident details",
Long: curatedLong("Get details for one or more incidents by ID.", "Incidents", "List"),
Long: curatedLong("Get details for one or more incidents by ID.", "Incidents", "ListByIDs"),
Args: requireArgs("incident_id"),
RunE: func(cmd *cobra.Command, args []string) error {
return runCommand(cmd, args, func(ctx *RunContext) error {
Expand All @@ -296,7 +296,9 @@ func newIncidentGetCmd() *cobra.Command {
ids = append(ids, fullID)
}

result, _, err := ctx.Client.Incidents.List(cmdContext(ctx.Cmd), &flashduty.ListIncidentsRequest{
// /incident/list requires a start_time/end_time window; lookup by id
// goes through /incident/list-by-ids, which takes ids alone.
result, _, err := ctx.Client.Incidents.ListByIDs(cmdContext(ctx.Cmd), &flashduty.ListIncidentsByIDsRequest{
IncidentIDs: ids,
})
if err != nil {
Expand Down
36 changes: 30 additions & 6 deletions internal/cli/incident_short_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,22 @@ func TestIncidentDetailFullIDSkipsResolve(t *testing.T) {
}
}

// TestIncidentGetShortIDResolves: `get <6-hex>` resolves the short id, then
// fetches by the resolved full id via incident_ids.
// TestIncidentGetShortIDResolves: `get <6-hex>` resolves the short id via
// /incident/list, then fetches by the resolved full id via /incident/list-by-ids.
func TestIncidentGetShortIDResolves(t *testing.T) {
saveAndResetGlobals(t)
stub := newGFStub(t)
var paths []string
stub.dataForPath = func(path string, body map[string]any) any {
// Both the resolve and the final fetch hit /incident/list; the canned
// row is fine for either.
paths = append(paths, path)
return incidentListData(incidentItem(testFullID, testShortID, "kafka backlog"))
}

if _, err := execCommand("incident", "get", testShortID); err != nil {
t.Fatalf("execCommand: %v", err)
}
if stub.requests != 2 {
t.Fatalf("requests = %d, want 2 (resolve + fetch)", stub.requests)
if want := []string{"/incident/list", "/incident/list-by-ids"}; !equalStrings(paths, want) {
t.Fatalf("paths = %v, want %v (resolve + fetch)", paths, want)
}

// Resolve sent nums; final fetch sent the resolved full id via incident_ids.
Expand All @@ -169,6 +169,30 @@ func TestIncidentGetShortIDResolves(t *testing.T) {
}
}

// TestIncidentGetFullIDUsesListByIDs: a full id skips the resolve and fetches
// through /incident/list-by-ids. /incident/list rejects a request without a
// start_time/end_time window, so the id lookup must not go through it.
func TestIncidentGetFullIDUsesListByIDs(t *testing.T) {
saveAndResetGlobals(t)
stub := newGFStub(t)
var paths []string
stub.dataForPath = func(path string, body map[string]any) any {
paths = append(paths, path)
return incidentListData(incidentItem(testFullID, testShortID, "kafka backlog"))
}

if _, err := execCommand("incident", "get", testFullID); err != nil {
t.Fatalf("execCommand: %v", err)
}
if want := []string{"/incident/list-by-ids"}; !equalStrings(paths, want) {
t.Fatalf("paths = %v, want %v", paths, want)
}
ids, _ := stub.bodies[0]["incident_ids"].([]any)
if len(ids) != 1 || ids[0] != testFullID {
t.Errorf("incident_ids = %#v, want [%q]", stub.bodies[0]["incident_ids"], testFullID)
}
}

// TestIncidentListNumsReachesWire: --nums is split and sent as the nums array.
func TestIncidentListNumsReachesWire(t *testing.T) {
saveAndResetGlobals(t)
Expand Down
Loading