Fix events filter in GetPipelines API (#4498)

This commit is contained in:
Robert Kaussow 2024-12-01 23:32:46 +01:00 committed by GitHub
parent 3c31284e7b
commit 8cfb8f93fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View file

@ -132,7 +132,7 @@ func GetPipelines(c *gin.Context) {
if events := c.Query("event"); events != "" {
eventList := strings.Split(events, ",")
wel := make(model.WebhookEventList, 0, len(eventList))
for _, event := range events {
for _, event := range eventList {
we := model.WebhookEvent(event)
if err := we.Validate(); err != nil {
_ = c.AbortWithError(http.StatusBadRequest, err)

View file

@ -96,6 +96,24 @@ func TestGetPipelines(t *testing.T) {
assert.Equal(t, http.StatusOK, c.Writer.Status())
})
t.Run("should filter pipelines by events", func(t *testing.T) {
pipelines := []*model.Pipeline{fakePipeline}
mockStore := store_mocks.NewStore(t)
mockStore.On("GetPipelineList", mock.Anything, mock.Anything, mock.Anything).Return(pipelines, nil)
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Set("store", mockStore)
c.Request, _ = http.NewRequest(http.MethodGet, "/?event=push,pull_request", nil)
GetPipelines(c)
mockStore.AssertCalled(t, "GetPipelineList", mock.Anything, mock.Anything, &model.PipelineFilter{
Events: model.WebhookEventList{model.EventPush, model.EventPull},
})
assert.Equal(t, http.StatusOK, c.Writer.Status())
})
}
func TestDeletePipeline(t *testing.T) {