Skip to content

Commit

Permalink
bug: allow setting continueOnErr to false or not at all #546 (#548)
Browse files Browse the repository at this point in the history
* bug: allow setting continueOnErr to false or not at all #546

* chore: update unit tests #546
  • Loading branch information
srinandan authored Sep 25, 2024
1 parent 47caa16 commit 343e9b6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 3 additions & 1 deletion internal/client/flowhooks/flowhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ func TestAttach(t *testing.T) {
if _, err := sharedflows.Create(name, path.Join(cliPath, testFolder, "test_flow.zip")); err != nil {
t.Fatalf("%v", err)
}
if _, err := Attach("PreProxyFlowHook", "test description", name, true); err != nil {
cPtr := new(bool)
*cPtr = true
if _, err := Attach("PreProxyFlowHook", "test description", name, cPtr); err != nil {
t.Fatalf("%v", err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/client/flowhooks/flowhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

// Attach
func Attach(name string, description string, sharedflow string, continueOnErr bool) (respBody []byte, err error) {
func Attach(name string, description string, sharedflow string, continueOnErr *bool) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.GetApigeeBaseURL())

flowhook := []string{}
Expand All @@ -36,8 +36,8 @@ func Attach(name string, description string, sharedflow string, continueOnErr bo

flowhook = append(flowhook, "\"sharedFlow\":\""+sharedflow+"\"")

if continueOnErr {
flowhook = append(flowhook, "\"continueOnError\":"+strconv.FormatBool(continueOnErr))
if continueOnErr != nil {
flowhook = append(flowhook, "\"continueOnError\":"+strconv.FormatBool(*continueOnErr))
}

payload := "{" + strings.Join(flowhook, ",") + "}"
Expand Down
19 changes: 14 additions & 5 deletions internal/cmd/flowhooks/crtfh.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package flowhooks

import (
"fmt"
"internal/apiclient"
"internal/client/flowhooks"
"strconv"

"github.com/spf13/cobra"
)
Expand All @@ -34,14 +36,21 @@ var CreateCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) (err error) {
cmd.SilenceUsage = true

_, err = flowhooks.Attach(name, description, sharedflow, continueOnErr)
if continueOnErrStr != "" {
continueOnErrPtr = new(bool)
*continueOnErrPtr, err = strconv.ParseBool(continueOnErrStr)
if err != nil {
return fmt.Errorf("continueOnErr should be a boolean value: %v", err)
}
}
_, err = flowhooks.Attach(name, description, sharedflow, continueOnErrPtr)
return
},
}

var (
description, sharedflow string
continueOnErr bool
continueOnErrPtr *bool
description, sharedflow, continueOnErrStr string
)

func init() {
Expand All @@ -51,8 +60,8 @@ func init() {
"", "Description for the flowhook")
CreateCmd.Flags().StringVarP(&sharedflow, "sharedflow", "s",
"", "Sharedflow name")
CreateCmd.Flags().BoolVarP(&continueOnErr, "continue", "c",
true, "Continue on error")
CreateCmd.Flags().StringVarP(&continueOnErrStr, "continue", "c",
"", "Continue on error")

_ = CreateCmd.MarkFlagRequired("name")
_ = CreateCmd.MarkFlagRequired("sharedflow")
Expand Down

0 comments on commit 343e9b6

Please sign in to comment.