sdk
sdk copied to clipboard
Return HTTP response codes as typed errors
This allows to differentiate a datasource not found from other errors, e.g.
_, err = client.GetDatasource(ctx, dsID)
if errors.Is(err, sdk.ErrNotFound) {
fmt.Fprintf(os.Stderr, "Creating new datasource %s (id=%d)\n", ds.Name, ds.ID)
}
Thanks for the feedback. I'll be back with some updates to this PR.
I amended my commit with the changes you proposed. Test are green on my workstation; not sure how I could run the GitHub actions.
It seems like linters are failing. Could you please take a look?
Should be fixed now.
Still, some errors are happening. AFAICT the issue is here: https://github.com/grafana-tools/sdk/blob/master/rest-dashboard_integration_test.go#L87-L90
We should ignore 404 errors here (: @suhlig could you please take a look?
Sure! Thanks for catching these. I ran go test ./...; shouldn't that have shown the error?
We also have integration tests. For that, you need a locally running Grafana, most likely in a Docker container, plus environment variable GRAFANA_INTEGRATION set to 1. You can see how it works here.
The integration test failure turned out to be a valuable one. I had overlooked a few error cases for delete-dashboard-by-uid and get-dashboard-by-uid.
I changed the integration test to consistently use DeleteDashboardByUID because this one has the 404 documented, whereas delete-dashboard-by-slug (DELETE /api/dashboards/db/:slug) as used by DeleteDashboard is deprecated since Grafana 5.0.
I also added instructions to the README on how to run local tests.
Coverage decreased (-1.7%) to 46.252% when pulling 66a7bce801909608578909e656e358ec54dc356e on suhlig:datasources-use-status-code into 9de4d14888c553cbde643c3c9fd26633a13d5736 on grafana-tools:master.
Thanks, I will take a look tomorrow
Bump ... anything I need to do before the PR can be merged?