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

Return error when failing to parse deletion time #1447

Closed
wants to merge 1 commit into from

Conversation

andresmgot
Copy link
Contributor

Description of the change

Context: #1445 (comment)

Copy link
Contributor

@absoludity absoludity left a comment

Choose a reason for hiding this comment

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

Thanks for the suggestion, I think there's a small issue with one of the conditions - see below.

I had been thinking about how I could do this yesterday using the new errors functionality (ie. without doing string comparisons) but couldn't find a good solution. Came back today with a fresh mind and found one... see what you think (#1451). Happy for you to land either that or this (with the point below fixed).

@@ -206,8 +207,10 @@ func TestConvert(t *testing.T) {
t.Run(test.Description, func(t *testing.T) {
// Perform conversion
compatibleH3rls, err := Convert(test.Helm3Release)
if got, want := err, test.ExpectedError; got != want {
t.Errorf("got: %v, want: %v", got, want)
if test.ExpectedError != nil || err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is problematic: I assume you added it because you saw a panic on either got.Error() or want.Error() (or both) when either of them is nil. So in the case where a test would fail (say a test where test.ExpectedError == nil but an error was returned), then you'd still see a panic. To avoid that, you'd need to replace the || with &&, but then you're effectively skipping this assertion when we don't want to.

We could fix that here easily enough by first testing to ensure we have an error when we didn't expect one (or vice-verse):

if gotError, wantError := err != nil, test.ExpectedError != nil; gotError != wantError {
    ...
}
if test.ExpectedError != nil && err != nil {
...(something that uses .Error() on both)
}

But, I think this alternative, using the new error wrapping, is simpler and perhaps a good precedent: #1451

@andresmgot
Copy link
Contributor Author

Thanks for the comment and investigating this! I indeed prefer your solution in #1451, it's cleaner and more readable 👍

@andresmgot andresmgot closed this Jan 15, 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.

2 participants