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

Fix error equals #2429

Merged
merged 2 commits into from
Aug 28, 2020
Merged

Conversation

albertteoh
Copy link
Contributor

Which problem is this PR solving?

Fixes a broken test introduced by an upgrade of go version to 1.15, caused by a change in the time package, specifically in format.go:1437.

Short description of the changes

  • Although the practice of asserting on error messages is debatable, the spirit of this PR is to respect the original intention of this test in making a strong assertion on the specific input value which causes the error. Further, the error message should be consistent between OSes, just not between go versions of course.
  • Fixes the broken test, which does not expect a quoted value in the error message. Go 1.15 introduces a sensible change of quoting the values to more clearly identify what is being parsed.
  • The fix involves modifying the test to accept either quoted (1.15) or unquoted values (1.14 or below) in a regex of the error message and hence, ensures compatibility between both versions.
  • Alternatives considered:
    • Using strings.HasPrefix which is slightly simpler but slightly reduces the fidelity of the test, losing a comparison on the actual value.
    • Just assert.Error(t, err), which is the simplest yet loses the most fidelity from the original test assertion.

Tested with the following to ensure they pass:

# Using go 1.14
$ go clean -testcache
$ go test github.com/jaegertracing/jaeger/cmd/query/app

# Switch to go 1.15
$ go clean -testcache
$ go test github.com/jaegertracing/jaeger/cmd/query/app

@albertteoh albertteoh requested a review from a team as a code owner August 28, 2020 13:30
albertteoh added 2 commits August 28, 2020 23:30
Copy link
Contributor

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Ideally, we'd start wrapping the constant parts of the messages into the variable parts, making it easy to compare with errors.Is. That said, your PR improves the code base and prepares it for 1.15.

@pavolloffay pavolloffay merged commit b5b2d79 into jaegertracing:master Aug 28, 2020
{"x?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20", "cannot not parse minDuration: time: missing unit in duration 20", nil},
{"x?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20s&maxDuration=30", "cannot not parse maxDuration: time: missing unit in duration 30", nil},
{"x?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20", `cannot not parse minDuration: time: missing unit in duration "?20"?$`, nil},
{"x?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20s&maxDuration=30", `cannot not parse maxDuration: time: missing unit in duration "?30"?$`, nil},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, having been burnt by the changing stdlib error messages in the past, I now try to write tests that only check for a substring or a prefix of the error which is stable and comes from our code, such as cannot not parse minDuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I would agree with that. Or, alternatively, wrap the error into a custom error type and assert on the type rather than error string comparisons.

@albertteoh albertteoh deleted the fix-error-equals branch August 28, 2020 20:55
@yurishkuro yurishkuro mentioned this pull request Aug 31, 2020
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

Successfully merging this pull request may close these issues.

4 participants