diff --git a/core/cmd/hoverfly/main.go b/core/cmd/hoverfly/main.go index 0f68d18e7..9536d3aa4 100644 --- a/core/cmd/hoverfly/main.go +++ b/core/cmd/hoverfly/main.go @@ -120,8 +120,7 @@ var ( cors = flag.Bool("cors", false, "Enable CORS support") noImportCheck = flag.Bool("no-import-check", false, "Skip duplicate request check when importing simulations") - pacFile = flag.String("pac-file", "", "Path to the pac file to be imported on startup") - fallbackPostServeAction = flag.String("fallback-post-serve-action", "", "Set fallback post serve action by passing the binary and the path of the action script and delay in Ms separated by space or remote and deply in Ms separated by space. (i.e. '-fallback-post-serve-action \"http://localhost:8080 2000\"')") + pacFile = flag.String("pac-file", "", "Path to the pac file to be imported on startup") clientAuthenticationDestination = flag.String("client-authentication-destination", "", "Regular expression of destination with client authentication") clientAuthenticationClientCert = flag.String("client-authentication-client-cert", "", "Path to the client certification file used for authentication") @@ -590,44 +589,6 @@ func main() { } } - if *fallbackPostServeAction != "" { - splitPostServeAction := strings.Split(*fallbackPostServeAction, " ") - if len(splitPostServeAction) == 3 { - delayInMs, err := strconv.Atoi(splitPostServeAction[2]) - if err != nil { - //default to 1000 incase of error - delayInMs = 1000 - } - - if fileContents, err := ioutil.ReadFile(splitPostServeAction[1]); err == nil { - err = hoverfly.SetLocalPostServeAction("", splitPostServeAction[0], string(fileContents), delayInMs) - if err != nil { - log.WithFields(log.Fields{ - "error": err.Error(), - "import": *fallbackPostServeAction, - }).Fatal("Failed to import fallback post serve action") - } - } - } else if len(splitPostServeAction) == 2 { - delayInMs, err := strconv.Atoi(splitPostServeAction[1]) - if err != nil { - //default to 1000 in case of error - delayInMs = 1000 - } - err = hoverfly.SetRemotePostServeAction(" ", splitPostServeAction[0], delayInMs) - if err != nil { - log.WithFields(log.Fields{ - "error": err.Error(), - "import": *fallbackPostServeAction, - }).Fatal("Failed to import fallback post serve action") - } - } else { - log.WithFields(log.Fields{ - "import": *fallbackPostServeAction, - }).Fatal("Failed to import fallback post serve action due to invalid input passed") - } - } - if len(templatingDataSourceFlags) > 0 { for _, v := range templatingDataSourceFlags { diff --git a/core/handlers/v2/postserveactiondetails_views.go b/core/handlers/v2/postserveactiondetails_views.go index 56392fc56..ba2558a0d 100644 --- a/core/handlers/v2/postserveactiondetails_views.go +++ b/core/handlers/v2/postserveactiondetails_views.go @@ -1,8 +1,7 @@ package v2 type PostServeActionDetailsView struct { - Actions []ActionView `json:"actions,omitempty"` - FallbackAction *ActionView `json:"fallbackAction,omitempty"` + Actions []ActionView `json:"actions,omitempty"` } type ActionView struct { diff --git a/core/hoverfly_service.go b/core/hoverfly_service.go index 0dcf65eb9..cd9b33c67 100644 --- a/core/hoverfly_service.go +++ b/core/hoverfly_service.go @@ -468,14 +468,12 @@ func (hf *Hoverfly) GetAllPostServeActions() v2.PostServeActionDetailsView { actions = append(actions, action.GetActionView(actionName)) } - var fallbackActionView v2.ActionView if hf.PostServeActionDetails.FallbackAction != nil { - fallbackActionView = hf.PostServeActionDetails.FallbackAction.GetActionView("") + actions = append(actions, hf.PostServeActionDetails.FallbackAction.GetActionView("")) } return v2.PostServeActionDetailsView{ - Actions: actions, - FallbackAction: &fallbackActionView, + Actions: actions, } } diff --git a/core/hoverfly_service_test.go b/core/hoverfly_service_test.go index b1b9561af..7e8765e3f 100644 --- a/core/hoverfly_service_test.go +++ b/core/hoverfly_service_test.go @@ -1397,16 +1397,16 @@ func TestHoverfly_GetPostServeActions_WithFallback(t *testing.T) { postServeActions := unit.GetAllPostServeActions() Expect(postServeActions).NotTo(BeNil()) - Expect(postServeActions.Actions).To(HaveLen(2)) + Expect(postServeActions.Actions).To(HaveLen(3)) 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)) - Expect(postServeActions.FallbackAction).NotTo(BeNil()) - Expect(postServeActions.FallbackAction.Remote).To(Equal("http://localhost:8081")) - Expect(postServeActions.FallbackAction.DelayInMs).To(Equal(1800)) + Expect(postServeActions.Actions[2]).NotTo(BeNil()) + Expect(postServeActions.Actions[2].Remote).To(Equal("http://localhost:8081")) + Expect(postServeActions.Actions[2].DelayInMs).To(Equal(1800)) } func TestHoverfly_SetLocalPostServeAction(t *testing.T) { diff --git a/functional-tests/core/ft_postserveaction_test.go b/functional-tests/core/ft_postserveaction_test.go index 6e0383ced..aa1e2f0f7 100644 --- a/functional-tests/core/ft_postserveaction_test.go +++ b/functional-tests/core/ft_postserveaction_test.go @@ -59,22 +59,6 @@ var _ = Describe("Manage post serve actions in hoverfly", func() { Expect(postServeActionDetails.Actions[0].DelayInMs).To(Equal(1300)) }) }) - - Context("hoverfly with fallback remote post-serve-action", func() { - - BeforeEach(func() { - hoverfly.Start("-fallback-post-serve-action", "http://localhost:8080 1300") - }) - - It("Should return post serve action details", func() { - postServeActionDetails := hoverfly.GetAllPostServeAction() - Expect(postServeActionDetails).NotTo(BeNil()) - Expect(postServeActionDetails.FallbackAction).NotTo(BeNil()) - Expect(postServeActionDetails.FallbackAction.ActionName).To(Equal("")) - Expect(postServeActionDetails.FallbackAction.Remote).To(Equal("http://localhost:8080")) - Expect(postServeActionDetails.FallbackAction.DelayInMs).To(Equal(1300)) - }) - }) }) Context("set local post serve action", func() { @@ -133,10 +117,10 @@ var _ = Describe("Manage post serve actions in hoverfly", func() { It("Should set post serve action", func() { postServeActionDetails := hoverfly.SetRemotePostServeAction("", "http://localhost:8080", 1600) Expect(postServeActionDetails).NotTo(BeNil()) - Expect(postServeActionDetails.FallbackAction).NotTo(BeNil()) - Expect(postServeActionDetails.FallbackAction.ActionName).To(Equal("")) - Expect(postServeActionDetails.FallbackAction.Remote).To(Equal("http://localhost:8080")) - Expect(postServeActionDetails.FallbackAction.DelayInMs).To(Equal(1600)) + Expect(postServeActionDetails.Actions).NotTo(BeNil()) + Expect(postServeActionDetails.Actions[0].ActionName).To(Equal("")) + Expect(postServeActionDetails.Actions[0].Remote).To(Equal("http://localhost:8080")) + Expect(postServeActionDetails.Actions[0].DelayInMs).To(Equal(1600)) }) }) }) diff --git a/functional-tests/hoverctl/postserveaction_test.go b/functional-tests/hoverctl/postserveaction_test.go index 640c1f599..621b27842 100644 --- a/functional-tests/hoverctl/postserveaction_test.go +++ b/functional-tests/hoverctl/postserveaction_test.go @@ -118,7 +118,7 @@ var _ = Describe("When I use hoverctl", func() { Expect(output).To(ContainSubstring("Success")) output = functional_tests.Run(hoverctlBinary, "post-serve-action", "get-all") - Expect(output).To(ContainSubstring("default")) + Expect(output).To(ContainSubstring("fallback")) Expect(output).To(ContainSubstring("http://localhost")) Expect(output).To(ContainSubstring("1700")) }) diff --git a/hoverctl/cmd/postserveaction.go b/hoverctl/cmd/postserveaction.go index 562b3bd54..176ce0539 100644 --- a/hoverctl/cmd/postserveaction.go +++ b/hoverctl/cmd/postserveaction.go @@ -109,18 +109,16 @@ func getPostServeActionsTabularData(postServeActions v2.PostServeActionDetailsVi actionData := []string{action.ActionName, action.Binary, getContentShorthand(action.ScriptContent), fmt.Sprint(action.DelayInMs)} localPostServeActionsData = append(localPostServeActionsData, actionData) } else { - actionData := []string{action.ActionName, action.Remote, fmt.Sprint(action.DelayInMs)} + var actionName string + if action.ActionName == "" { + actionName = "fallback" + } else { + actionName = action.ActionName + } + actionData := []string{actionName, action.Remote, fmt.Sprint(action.DelayInMs)} remotePostServeActionData = append(remotePostServeActionData, actionData) } } - action := *postServeActions.FallbackAction - const defaultActionName = "default" - if action.Remote == "" { - actionData := []string{defaultActionName, action.Binary, getContentShorthand(action.ScriptContent), fmt.Sprint(action.DelayInMs)} - localPostServeActionsData = append(localPostServeActionsData, actionData) - } else { - actionData := []string{defaultActionName, action.Remote, fmt.Sprint(action.DelayInMs)} - remotePostServeActionData = append(remotePostServeActionData, actionData) - } + return localPostServeActionsData, remotePostServeActionData }