mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 10:20:29 -06:00
2616366a0a
* Re-add feature flag with deprecation note * Hide the field in frontend if ff disabled * Block scope overriding if ff is disabled in backend - Update promlib to forward logger to extendOptions - Add warning - Update tests * Default toggle to true for now * Update description * Update prom tests * Fix lint
55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package prometheus
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana-azure-sdk-go/v2/azsettings"
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
sdkhttpclient "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestExtendClientOpts(t *testing.T) {
|
|
t.Run("add azure credentials if configured", func(t *testing.T) {
|
|
cfg := backend.NewGrafanaCfg(map[string]string{
|
|
azsettings.AzureCloud: azsettings.AzurePublic,
|
|
azsettings.AzureAuthEnabled: "true",
|
|
})
|
|
settings := backend.DataSourceInstanceSettings{
|
|
BasicAuthEnabled: false,
|
|
BasicAuthUser: "",
|
|
JSONData: []byte(`{
|
|
"azureCredentials": {
|
|
"authType": "msi"
|
|
}
|
|
}`),
|
|
DecryptedSecureJSONData: map[string]string{},
|
|
}
|
|
ctx := backend.WithGrafanaConfig(context.Background(), cfg)
|
|
opts := &sdkhttpclient.Options{}
|
|
err := extendClientOpts(ctx, settings, opts, backend.Logger)
|
|
require.NoError(t, err)
|
|
require.Equal(t, 1, len(opts.Middlewares))
|
|
})
|
|
|
|
t.Run("add sigV4 auth if opts has SigV4 configured", func(t *testing.T) {
|
|
settings := backend.DataSourceInstanceSettings{
|
|
BasicAuthEnabled: false,
|
|
BasicAuthUser: "",
|
|
JSONData: []byte(""),
|
|
DecryptedSecureJSONData: map[string]string{},
|
|
}
|
|
opts := &sdkhttpclient.Options{
|
|
SigV4: &sdkhttpclient.SigV4Config{
|
|
AuthType: "test",
|
|
AccessKey: "accesskey",
|
|
SecretKey: "secretkey",
|
|
},
|
|
}
|
|
err := extendClientOpts(context.Background(), settings, opts, backend.Logger)
|
|
require.NoError(t, err)
|
|
require.Equal(t, "aps", opts.SigV4.Service)
|
|
})
|
|
}
|