The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/plugins/errors_test.go

58 lines
1.7 KiB

package plugins
import (
"context"
"errors"
"testing"
"github.com/grafana/grafana/pkg/apimachinery/errutil"
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/stretchr/testify/assert"
)
func TestErrPluginGrpcConnectionUnavailableBase(t *testing.T) {
tests := []struct {
name string
ctx context.Context
err error
expectedPublic string
}{
{
name: "without stack ID in context",
ctx: identity.WithRequester(context.Background(), &identity.StaticRequester{
Namespace: "org-123",
}),
err: errors.New("connection failed"),
expectedPublic: "Data source became unavailable during request. Please try again.",
},
{
name: "with stack ID in context",
ctx: identity.WithRequester(context.Background(), &identity.StaticRequester{
Namespace: "stacks-123",
}),
err: errors.New("connection failed"),
expectedPublic: "Data source became unavailable during request. Please try again. If the problem persists, please contact customer support.",
},
{
name: "without static requester in context",
ctx: context.Background(),
err: errors.New("connection failed"),
expectedPublic: "Data source became unavailable during request. Please try again.",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := ErrPluginGrpcConnectionUnavailableBaseFn(tt.ctx).Errorf("%v", tt.err)
assert.Error(t, err)
// Check if it's a Grafana error
var grafanaErr errutil.Error
assert.ErrorAs(t, err, &grafanaErr)
// Check the public message
publicErr := grafanaErr.Public()
assert.Equal(t, tt.expectedPublic, publicErr.Message)
})
}
}