Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make fail merge #105

Open
MegalLink opened this issue Jul 13, 2021 · 1 comment
Open

Make fail merge #105

MegalLink opened this issue Jul 13, 2021 · 1 comment

Comments

@MegalLink
Copy link

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")

			}
@mihaitodor
Copy link
Contributor

mihaitodor commented Jul 14, 2021

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)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants