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

ShouldResemble can fail when there's no visual diff between the inputs #50

Closed
srabraham opened this issue Mar 30, 2023 · 1 comment
Closed

Comments

@srabraham
Copy link
Contributor

This was initially filed as an issue on goconvey: smartystreets/goconvey#665
But really it's a problem in this assertions code.

Assuming you read that issue first, and especially smartystreets/goconvey#665 (comment) , the right fix would be for the diff to report which types are different. That would be a little involved, especially if anyone has managed to rely on the exact output format that is provided currently.
A lazier fix would be something like the below

func ShouldResemble(actual interface{}, expected ...interface{}) string {
	if message := need(1, expected); message != success {
		return message
	}

	if matchError := oglematchers.DeepEquals(expected[0]).Matches(actual); matchError != nil {
		renderedExpected, renderedActual := render.Render(expected[0]), render.Render(actual)
		message := fmt.Sprintf(shouldHaveResembled, renderedExpected, renderedActual)

		if renderedExpected != renderedActual {
			message += composePrettyDiff(renderedExpected, renderedActual)
		} else {
			message += "No visual diff, but there is a difference in type within expected versus actual"
		}
		return serializer.serializeDetailed(expected[0], actual, message)
	}

	return success
}

FYI @riannucci

@mdwhatcott
Copy link
Contributor

mdwhatcott commented Mar 30, 2023

I'd welcome a PR with code similar to what @srabraham suggested above (including test cases please).

srabraham added a commit to srabraham/smartystreets-assertions that referenced this issue Apr 3, 2023
Currently ShouldResemble fails confusingly when the visual diff of
two items is the same despite DeepEquals being false.

See more context in comments in the PR, or at these issues
smarty#50
smartystreets/goconvey#665
mdwhatcott added a commit that referenced this issue Apr 3, 2023
> Render doesn't show the types of fields, so something like int(5) will appear
the same as int64(5), but they will cause DeepEquals to return false. This
message at least makes it clear why there appears to be no diff. A better solution
would be to have the diff look for where the two items actually differ, e.g. through
something like https://github.com/go-test/deep

See PR #51 and Issue #50
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