-
Notifications
You must be signed in to change notification settings - Fork 6
feat: validate grafanaDep with semver #515
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,32 @@ func TestMetadataInvalid(t *testing.T) { | |
| ) | ||
| } | ||
|
|
||
| func TestGrafanaDependencyInvalid(t *testing.T) { | ||
| var interceptor testpassinterceptor.TestPassInterceptor | ||
| pass := &analysis.Pass{ | ||
| RootDir: filepath.Join("./"), | ||
| ResultOf: map[*analysis.Analyzer]interface{}{ | ||
| archive.Analyzer: filepath.Join("testdata", "invalid", "grafana-dep"), | ||
| metadataschema.Analyzer: getSchema(), | ||
| }, | ||
| Report: interceptor.ReportInterceptor(), | ||
| } | ||
|
|
||
| _, err := Analyzer.Run(pass) | ||
| require.NoError(t, err) | ||
| require.Len(t, interceptor.Diagnostics, 2) | ||
| require.Equal( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: validate that the schema is not reporting
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now the new error message is checked in the main_test.go |
||
| t, | ||
| "plugin.json: Dependencies.grafanaDependency field has invalid or empty version constraint: \">=invalid\"", | ||
| interceptor.Diagnostics[0].Title, | ||
| ) | ||
| require.Equal( | ||
| t, | ||
| "plugin.json: (root): Additional property invalid is not allowed", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we really need this validation here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is to check combination of schema and grafanaDependency. |
||
| interceptor.Diagnostics[1].Title, | ||
| ) | ||
| } | ||
|
|
||
| func getSchema() []byte { | ||
| if len(schemaContent) > 0 { | ||
| return schemaContent | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| { | ||
| "type": "panel", | ||
| "name": "Clock", | ||
| "id": "grafana-clock-panel", | ||
| "skipDataQuery": true, | ||
| "invalid": "invalid", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can remove this, we want to test the grafanaDependency, there are tests already for invalid schema fields. |
||
| "info": { | ||
| "description": "Clock panel for grafana", | ||
| "author": { | ||
| "name": "Grafana Labs", | ||
| "url": "https://grafana.com" | ||
| }, | ||
| "keywords": [ | ||
| "clock", | ||
| "panel" | ||
| ], | ||
| "logos": { | ||
| "small": "img/clock.svg", | ||
| "large": "img/clock.svg" | ||
| }, | ||
| "links": [ | ||
| { | ||
| "name": "Project site", | ||
| "url": "https://github.com/grafana/clock-panel" | ||
| }, | ||
| { | ||
| "name": "MIT License", | ||
| "url": "https://github.com/grafana/clock-panel/blob/master/LICENSE" | ||
| } | ||
| ], | ||
| "screenshots": [ | ||
| { | ||
| "name": "Showcase", | ||
| "path": "img/screenshot-showcase.png" | ||
| }, | ||
| { | ||
| "name": "Options", | ||
| "path": "img/screenshot-clock-options.png" | ||
| } | ||
| ], | ||
| "version": "%VERSION%", | ||
| "updated": "%TODAY%" | ||
| }, | ||
| "dependencies": { | ||
| "grafanaDependency": ">=invalid", | ||
| "plugins": [] | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm: with this change we will validate both that the GrafanaDependency is valid according to the regex in the schema + actual semver library used by Grafana's backend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will use hashicorp/semver to validate the constraint. Schema validation for grafanaDependency will be ignored.