Skip to content

Commit

Permalink
feat(api): print trigger id when it already exists (#1113)
Browse files Browse the repository at this point in the history
* feat(api): print trigger id when it already exists
  • Loading branch information
HeavyPunk authored Oct 14, 2024
1 parent 993d37f commit 0fd0b04
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/controller/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func CreateTrigger(dataBase moira.Database, trigger *dto.TriggerModel, timeSerie
return nil, api.ErrorInternalServer(err)
}
if exists {
return nil, api.ErrorInvalidRequest(fmt.Errorf("trigger with this ID already exists"))
return nil, api.ErrorInvalidRequest(fmt.Errorf("trigger with this ID (%s) already exists", trigger.ID))
}
}
resp, err := saveTrigger(dataBase, trigger.ToMoiraTrigger(), trigger.ID, timeSeriesNames)
Expand Down
5 changes: 3 additions & 2 deletions api/controller/triggers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ func TestCreateTrigger(t *testing.T) {
})

Convey("Trigger already exists", t, func() {
triggerModel := dto.TriggerModel{ID: uuid.Must(uuid.NewV4()).String()}
triggerId := uuid.Must(uuid.NewV4()).String()
triggerModel := dto.TriggerModel{ID: triggerId}
trigger := triggerModel.ToMoiraTrigger()
dataBase.EXPECT().GetTrigger(triggerModel.ID).Return(*trigger, nil)
resp, err := CreateTrigger(dataBase, &triggerModel, make(map[string]bool))
So(err, ShouldResemble, api.ErrorInvalidRequest(fmt.Errorf("trigger with this ID already exists")))
So(err, ShouldResemble, api.ErrorInvalidRequest(fmt.Errorf("trigger with this ID (%s) already exists", triggerId)))
So(resp, ShouldBeNil)
})

Expand Down

0 comments on commit 0fd0b04

Please sign in to comment.