Skip to content

Commit

Permalink
Keep post-serve action admin endpoint path consistent with the rest o…
Browse files Browse the repository at this point in the history
…f the apis
  • Loading branch information
tommysitu committed Sep 12, 2023
1 parent a389364 commit f4a51ce
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions core/handlers/v2/hoverfly_postserveactiondetails_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ type HoverflyPostServeActionDetailsHandler struct {

func (postServeActionDetailsHandler *HoverflyPostServeActionDetailsHandler) RegisterRoutes(mux *bone.Mux, am *handlers.AuthHandler) {

mux.Get("/api/v2/hoverfly/post-serve-actions", negroni.New(
mux.Get("/api/v2/hoverfly/post-serve-action", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(postServeActionDetailsHandler.Get),
))
mux.Put("/api/v2/hoverfly/post-serve-actions", negroni.New(
mux.Put("/api/v2/hoverfly/post-serve-action", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(postServeActionDetailsHandler.Put),
))
mux.Delete("/api/v2/hoverfly/post-serve-actions/:actionName", negroni.New(
mux.Delete("/api/v2/hoverfly/post-serve-action/:actionName", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(postServeActionDetailsHandler.Delete),
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Test_PostServeActionHandler_DeletePostServeAction(t *testing.T) {
stubHoverfly := &HoverflyPostServeActionDetailsStub{}
unit := HoverflyPostServeActionDetailsHandler{Hoverfly: stubHoverfly}

request, err := http.NewRequest("DELETE", "/api/v2/hoverfly/post-serve-actions/test-action", nil)
request, err := http.NewRequest("DELETE", "/api/v2/hoverfly/post-serve-action/test-action", nil)
Expect(err).To(BeNil())

response := makeRequestOnHandler(unit.Delete, request)
Expand All @@ -52,7 +52,7 @@ func Test_PostServeActionHandler_SetPostServeAction(t *testing.T) {
bodyBytes, err := json.Marshal(actionView)
Expect(err).To(BeNil())

request, err := http.NewRequest("PUT", "/api/v2/hoverfly/post-serve-actions", ioutil.NopCloser(bytes.NewBuffer(bodyBytes)))
request, err := http.NewRequest("PUT", "/api/v2/hoverfly/post-serve-action", ioutil.NopCloser(bytes.NewBuffer(bodyBytes)))
Expect(err).To(BeNil())

response := makeRequestOnHandler(unit.Put, request)
Expand All @@ -64,7 +64,7 @@ func Test_PostServeActionHandler_GetAllPostServeActions(t *testing.T) {
stubHoverfly := &HoverflyPostServeActionDetailsStub{}
unit := HoverflyPostServeActionDetailsHandler{Hoverfly: stubHoverfly}

request, err := http.NewRequest("GET", "/api/v2/hoverfly/post-serve-actions", nil)
request, err := http.NewRequest("GET", "/api/v2/hoverfly/post-serve-action", nil)
Expect(err).To(BeNil())

response := makeRequestOnHandler(unit.Get, request)
Expand Down
16 changes: 8 additions & 8 deletions docs/pages/reference/api/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ GET /api/v2/hoverfly/middleware
"""""""""""""""""""""""""""""""

Gets the middleware settings for the running instance of Hoverfly. This
could be either an executable binary, a script that can be executed with
could be either an executable binary, a script that can be executed with
a binary or a URL to remote middleware.

**Example response body**
Expand Down Expand Up @@ -505,7 +505,7 @@ and the binary to execute it or the URL to a remote middleware.

-------------------------------------------------------------------------------------------------------------

GET /api/v2/hoverfly/post-serve-actions
GET /api/v2/hoverfly/post-serve-action
"""""""""""""""""""""""""""""""""""""""

Get all the post serve actions for the running instance of Hoverfly.
Expand All @@ -526,7 +526,7 @@ It will return list of scripts that can be executed with a binary after response
}


PUT /api/v2/hoverfly/post-serve-actions
PUT /api/v2/hoverfly/post-serve-action
"""""""""""""""""""""""""""""""""""""""

Sets new post serve action, overwriting the existing post serve action for the running instance of Hoverfly.
Expand All @@ -543,7 +543,7 @@ It returns all the post serve actions.
"delayInMs": "#delay(in ms) post which script will be executed after serving the request"
}

DELETE /api/v2/hoverfly/post-serve-actions/:actionName
DELETE /api/v2/hoverfly/post-serve-action/:actionName
""""""""""""""""""""""""""""""""""""""""""""""""""""""

Delete a particular post serve action for the running instance of Hoverfly. It returns all the remaining post serve actions.
Expand Down Expand Up @@ -757,23 +757,23 @@ Running hoverfly with ``-logs-size=0`` disables logging and 500 response is retu
"level": "info",
"msg": "serving proxy",
"time": "2017-03-13T12:22:39Z"
},
},
{
"destination": ".",
"level": "info",
"mode": "simulate",
"msg": "current proxy configuration",
"port": "8500",
"time": "2017-03-13T12:22:39Z"
},
},
{
"destination": ".",
"Mode": "simulate",
"ProxyPort": "8500",
"level": "info",
"msg": "Proxy prepared...",
"time": "2017-03-13T12:22:39Z"
},
},
]
}

Expand Down Expand Up @@ -918,7 +918,7 @@ Deletes all state from Hoverfly and then sets the state to match the state in th

PATCH /api/v2/state
"""""""""""""""""""
Updates state in Hoverfly. Will update each state key referenced in the request body.
Updates state in Hoverfly. Will update each state key referenced in the request body.

**Example request body**
::
Expand Down
2 changes: 1 addition & 1 deletion examples/postserveaction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
```shell
hoverfly -post-serve-action "outbound-http python3 examples/postserveaction/outboundhttpaction.py 1000" -import examples/postserveaction/simulation-with-callback.json
```
- You can verify that the post serve action is registered by using the admin endpoint: http://localhost:8888/api/v2/hoverfly/post-serve-actions
- You can verify that the post serve action is registered by using the admin endpoint: http://localhost:8888/api/v2/hoverfly/post-serve-action

- Proxying a request to http://helloworld-test.com should trigger a callback to http://ip.jsontest.com,
and the log from the post serve action script should be printed out to the hoverfly logs:
Expand Down
6 changes: 3 additions & 3 deletions functional-tests/functional_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (this Hoverfly) GetMode() *v2.ModeView {

func (this Hoverfly) GetAllPostServeAction() *v2.PostServeActionDetailsView {
PostServeActionDetailsView := &v2.PostServeActionDetailsView{}
resp := DoRequest(sling.New().Get(fmt.Sprintf("http://localhost:%v/api/v2/hoverfly/post-serve-actions", this.adminPort)))
resp := DoRequest(sling.New().Get(fmt.Sprintf("http://localhost:%v/api/v2/hoverfly/post-serve-action", this.adminPort)))

body, err := ioutil.ReadAll(resp.Body)
Expect(err).To(BeNil())
Expand All @@ -139,7 +139,7 @@ func (this Hoverfly) GetAllPostServeAction() *v2.PostServeActionDetailsView {
func (this Hoverfly) SetPostServeAction(actionName, binary, scriptContent string, delayInMs int) *v2.PostServeActionDetailsView {
actionView := v2.ActionView{ActionName: actionName, Binary: binary, DelayInMs: delayInMs, ScriptContent: scriptContent}

resp := DoRequest(sling.New().Put(fmt.Sprintf("http://localhost:%v/api/v2/hoverfly/post-serve-actions", this.adminPort)).BodyJSON(actionView))
resp := DoRequest(sling.New().Put(fmt.Sprintf("http://localhost:%v/api/v2/hoverfly/post-serve-action", this.adminPort)).BodyJSON(actionView))

PostServeActionDetailsView := &v2.PostServeActionDetailsView{}
body, err := ioutil.ReadAll(resp.Body)
Expand All @@ -153,7 +153,7 @@ func (this Hoverfly) SetPostServeAction(actionName, binary, scriptContent string

func (this Hoverfly) DeletePostServeAction(actionName string) *v2.PostServeActionDetailsView {

resp := DoRequest(sling.New().Delete(fmt.Sprintf("http://localhost:%v/api/v2/hoverfly/post-serve-actions/%v", this.adminPort, actionName)))
resp := DoRequest(sling.New().Delete(fmt.Sprintf("http://localhost:%v/api/v2/hoverfly/post-serve-action/%v", this.adminPort, actionName)))

PostServeActionDetailsView := &v2.PostServeActionDetailsView{}
body, err := ioutil.ReadAll(resp.Body)
Expand Down
2 changes: 1 addition & 1 deletion hoverctl/wrapper/hoverfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
v2ApiDestination = "/api/v2/hoverfly/destination"
v2ApiState = "/api/v2/state"
v2ApiMiddleware = "/api/v2/hoverfly/middleware"
v2ApiPostServeAction = "/api/v2/hoverfly/post-serve-actions"
v2ApiPostServeAction = "/api/v2/hoverfly/post-serve-action"
v2ApiPac = "/api/v2/hoverfly/pac"
v2ApiCache = "/api/v2/cache"
v2ApiLogs = "/api/v2/logs"
Expand Down

0 comments on commit f4a51ce

Please sign in to comment.