CloudMonitoring: Improve error message (#46599) (#46620)

(cherry picked from commit 727204ed5e)

Co-authored-by: Andres Martinez Gotor <andres.mgotor@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2022-03-16 09:48:46 +01:00
committed by GitHub
co-authored by Andres Martinez Gotor
parent f1cd74a5e9
commit aaf3abc468
2 changed files with 40 additions and 2 deletions
@@ -1,7 +1,9 @@
package cloudmonitoring
import (
"context"
"encoding/json"
"fmt"
"net/url"
"reflect"
"strings"
@@ -9,6 +11,8 @@ import (
"time"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -933,3 +937,29 @@ func baseReq() *backend.QueryDataRequest {
}
return query
}
func TestCheckHealth(t *testing.T) {
t.Run("and using GCE authentation should return proper error", func(t *testing.T) {
im := datasource.NewInstanceManager(func(s backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
return &datasourceInfo{
authenticationType: gceAuthentication,
}, nil
})
service := &Service{
im: im,
gceDefaultProjectGetter: func(ctx context.Context) (string, error) {
return "", fmt.Errorf("not found!")
},
}
res, err := service.CheckHealth(context.Background(), &backend.CheckHealthRequest{
PluginContext: backend.PluginContext{
DataSourceInstanceSettings: &backend.DataSourceInstanceSettings{},
},
})
assert.Nil(t, err)
assert.Equal(t, &backend.CheckHealthResult{
Status: backend.HealthStatusError,
Message: "not found!",
}, res)
})
}