Skip to content

Commit c85ec90

Browse files
authored
Merge pull request #215 from flashcatcloud/feat/incident-get
fix(incident): fetch `get` by id through /incident/list-by-ids
2 parents f02e866 + b09f7bd commit c85ec90

2 files changed

Lines changed: 34 additions & 8 deletions

File tree

‎internal/cli/incident.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func newIncidentGetCmd() *cobra.Command {
280280
return &cobra.Command{
281281
Use: "get <id> [<id2> ...]",
282282
Short: "Get incident details",
283-
Long: curatedLong("Get details for one or more incidents by ID.", "Incidents", "List"),
283+
Long: curatedLong("Get details for one or more incidents by ID.", "Incidents", "ListByIDs"),
284284
Args: requireArgs("incident_id"),
285285
RunE: func(cmd *cobra.Command, args []string) error {
286286
return runCommand(cmd, args, func(ctx *RunContext) error {
@@ -296,7 +296,9 @@ func newIncidentGetCmd() *cobra.Command {
296296
ids = append(ids, fullID)
297297
}
298298

299-
result, _, err := ctx.Client.Incidents.List(cmdContext(ctx.Cmd), &flashduty.ListIncidentsRequest{
299+
// /incident/list requires a start_time/end_time window; lookup by id
300+
// goes through /incident/list-by-ids, which takes ids alone.
301+
result, _, err := ctx.Client.Incidents.ListByIDs(cmdContext(ctx.Cmd), &flashduty.ListIncidentsByIDsRequest{
300302
IncidentIDs: ids,
301303
})
302304
if err != nil {

‎internal/cli/incident_short_id_test.go‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,22 @@ func TestIncidentDetailFullIDSkipsResolve(t *testing.T) {
141141
}
142142
}
143143

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

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

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

172+
// TestIncidentGetFullIDUsesListByIDs: a full id skips the resolve and fetches
173+
// through /incident/list-by-ids. /incident/list rejects a request without a
174+
// start_time/end_time window, so the id lookup must not go through it.
175+
func TestIncidentGetFullIDUsesListByIDs(t *testing.T) {
176+
saveAndResetGlobals(t)
177+
stub := newGFStub(t)
178+
var paths []string
179+
stub.dataForPath = func(path string, body map[string]any) any {
180+
paths = append(paths, path)
181+
return incidentListData(incidentItem(testFullID, testShortID, "kafka backlog"))
182+
}
183+
184+
if _, err := execCommand("incident", "get", testFullID); err != nil {
185+
t.Fatalf("execCommand: %v", err)
186+
}
187+
if want := []string{"/incident/list-by-ids"}; !equalStrings(paths, want) {
188+
t.Fatalf("paths = %v, want %v", paths, want)
189+
}
190+
ids, _ := stub.bodies[0]["incident_ids"].([]any)
191+
if len(ids) != 1 || ids[0] != testFullID {
192+
t.Errorf("incident_ids = %#v, want [%q]", stub.bodies[0]["incident_ids"], testFullID)
193+
}
194+
}
195+
172196
// TestIncidentListNumsReachesWire: --nums is split and sent as the nums array.
173197
func TestIncidentListNumsReachesWire(t *testing.T) {
174198
saveAndResetGlobals(t)

0 commit comments

Comments
 (0)