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

Clearer dashboard validation #333

Merged
merged 3 commits into from
Feb 8, 2024
Merged

Conversation

malcolmholmes
Copy link
Collaborator

We now have Validate() and Prepare(). Validate, well, validates. That is, it either returns nil
or an error. Prepare mutates the resource.

This PR moves these two related funcs closer to each other in the code. Also, for dashboards it
refactors the validation logic:

  • if UID not set or ="", then use name as UID
  • if UID and name set, but not equal, throw an error
  • if name is blank, throw an error.

@malcolmholmes malcolmholmes requested a review from a team February 5, 2024 19:52
Comment on lines 92 to 94
if resource.Name() == "" {
return fmt.Errorf("name cannot be blank")
}
Copy link
Member

Choose a reason for hiding this comment

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

Isn't that a base condition for all resources?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah. I did wonder while typing it. Hmm.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've updated the PR to do some validation for every resource before calling handler.Validate().

pkg/grafana/dashboard_test.go Outdated Show resolved Hide resolved
@malcolmholmes malcolmholmes merged commit 425a2c5 into main Feb 8, 2024
7 checks passed
@malcolmholmes malcolmholmes deleted the malcolmholmes/prepare-and-validate branch February 8, 2024 10:42
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