gabs
gabs copied to clipboard
Make fail merge
My question is how can i make fail the merge , i need a merge error for my uni test, but sending correct json objects mergeError:=initialBody.Merge(binInfo) if mergeError!=nil { logger.Info("[BinInfoMiddlewareError] error merging json objects")
return nil, errors.New("[BinInfoMiddlewareError] error merging json objects")
}
Hi @MegalLink, thank you for the question! One way is to get it to land on this code path and have target < 1
. The following should do the trick:
package main
import (
"fmt"
"github.com/Jeffail/gabs/v2"
)
func main() {
first := `[[0]]`
second := `{"-":"foo"}`
firstContainer, _ := gabs.ParseJSON([]byte(first))
secondContainer, _ := gabs.ParseJSON([]byte(second))
if err := firstContainer.Merge(secondContainer); err != nil {
fmt.Printf("Failed to merge: %s\n", err)
}
}