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

Test and remove panic possibilities in newDashboardCompatibleRelease #1445

Merged
merged 1 commit into from
Jan 14, 2020

Conversation

absoludity
Copy link
Contributor

Description of the change

Related to a question I had at #1434 (comment) , it was unclear why we were handling panics in tests rather than eliminating them.

I added a number of test cases which caused a panic as mentioned in the above comment, then fixed with a guard clause. While there, I also added some tests for the parsing of the Deleted timestamp.

Benefits

A number of conditions which could cause a panic have been eliminated.

Possible drawbacks

The error for the failed parsing of the Deletion timestamp is less explicit (so I could test it without doing string comparisons - guilty I'll update it if you think it's important)

Applicable issues

  • fixes #

Additional information

Copy link
Contributor

@latiif latiif left a comment

Choose a reason for hiding this comment

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

Good job removing the panic 👍

But are we sure/How sure are we, the two types of errors are the only ones that could occur?

Copy link
Contributor

@andresmgot andresmgot 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 improvements! Take a look to my comment and let me know what you think.

var deleted *timestamp.Timestamp
if !h3r.Info.Deleted.IsZero() {
var err error
deleted, err = ptypes.TimestampProto(h3r.Info.Deleted.Time)
if err != nil {
return h2.Release{}, fmt.Errorf("Failed to parse deletion time %v", err)
return h2.Release{}, ErrFailedToParseDeletionTime
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's important to have the error text somewhere. That way, if a user reports that it's hitting this error we'd get more info (for example if .IsZero() is not working as expected or if the Time is no longer valid).

If the only reason to set a fixed message is the test, you can still do string.Contains(got, want) instead of got != want which is a bit more flexible and unlikely to report a false-positive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #1451 Thanks!

@andresmgot
Copy link
Contributor

But are we sure/How sure are we, the two types of errors are the only ones that could occur?

As far as I can see, the fields that use pointers (which are the ones that may throw a panic if they are not defined) are covered (*h3r.Info, *h3r.Chart and *h3r.Chart.Metadata). Now there is not an expected panic (but that doesn't mean that we are missing something) but we can always extend the tests/code if we find new cases in which the code panics.

@andresmgot
Copy link
Contributor

Merging this because it will conflict with my PR in #1441 I can open a follow-up PR with my comment later on.

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.

3 participants