Skip to content

Commit

Permalink
review comment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kapishmalik committed Apr 10, 2024
1 parent 5be2f69 commit ca64d19
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
1 change: 0 additions & 1 deletion core/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func (action *Action) Execute(pair *models.RequestResponsePair, journalIDChannel
time.Sleep(time.Duration(200+action.DelayInMs) * time.Millisecond)

journalID := <-journalIDChannel
close(journalIDChannel)
log.Info("Journal ID received ", journalID)

//if it is remote callback
Expand Down
3 changes: 3 additions & 0 deletions core/action/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func Test_ExecuteLocalPostServeAction(t *testing.T) {
newJournal := journal.NewJournal()
journalIDChannel <- "demo-id"
err = newAction.Execute(&originalPair, journalIDChannel, newJournal)
close(journalIDChannel)
Expect(err).To(BeNil())
}

Expand All @@ -136,6 +137,7 @@ func Test_ExecuteRemotePostServeAction(t *testing.T) {
newJournal := journal.NewJournal()
journalIDChannel <- "1"
newAction, err := action.NewRemoteAction("test-callback", server.URL+"/process", 0)
close(journalIDChannel)
Expect(err).To(BeNil())
err = newAction.Execute(&originalPair, journalIDChannel, newJournal)
Expect(err).To(BeNil())
Expand All @@ -156,6 +158,7 @@ func Test_ExecuteRemotePostServeAction_WithUnReachableHost(t *testing.T) {
newJournal := journal.NewJournal()
journalIDChannel <- "1"
err = newAction.Execute(&originalPair, journalIDChannel, newJournal)
close(journalIDChannel)
Expect(err).NotTo(BeNil())
}

Expand Down
5 changes: 2 additions & 3 deletions core/hoverfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,11 @@ func (hf *Hoverfly) processRequest(req *http.Request) (*http.Response, chan stri
}

if result.PostServeActionInputDetails != nil {

journalIDChannel := make(chan string, 1)
if postServeAction, ok := hf.PostServeActionDetails.Actions[result.PostServeActionInputDetails.PostServeAction]; ok {
journalIDChannel := make(chan string, 1)
go postServeAction.Execute(result.PostServeActionInputDetails.Pair, journalIDChannel, hf.Journal)
return result.Response, journalIDChannel
}
return result.Response, journalIDChannel
}

return result.Response, nil
Expand Down
6 changes: 6 additions & 0 deletions core/hoverfly_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,12 @@ func TestHoverfly_GetPostServeActions(t *testing.T) {

Expect(postServeActions).NotTo(BeNil())
Expect(postServeActions.Actions).To(HaveLen(2))
Expect(postServeActions.Actions[0].ActionName).To(Equal("test-local-callback"))
Expect(postServeActions.Actions[0].Binary).To(Equal("python3"))
Expect(postServeActions.Actions[0].DelayInMs).To(Equal(1900))
Expect(postServeActions.Actions[1].ActionName).To(Equal("test-remote-callback"))
Expect(postServeActions.Actions[1].Remote).To(Equal("http://localhost"))
Expect(postServeActions.Actions[1].DelayInMs).To(Equal(1800))
}

func TestHoverfly_SetLocalPostServeAction(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions core/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func NewProxy(hoverfly *Hoverfly) *goproxy.ProxyHttpServer {
func sendJournalIDToPostServeAction(journalIDChannel chan string, id string) {
if journalIDChannel != nil {
journalIDChannel <- id
close(journalIDChannel)
}
}

Expand Down

0 comments on commit ca64d19

Please sign in to comment.