mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 21:19:28 -06:00
3fb6319d1b
* Move files to prometheus-library * refactor core prometheus to use prometheus-library * modify client transport options * mock * have a type * import aliases * rename * call the right method * remove unrelated test from the library * update codeowners * go work sync * update go.work.sum * make swagger-clean && make openapi3-gen * add promlib to makefile * remove clilogger * Export the function * update unit test * add prometheus_test.go * fix mock type * use mapUtil from grafana-plugin-sdk-go
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package prometheus
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana-azure-sdk-go/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)
|
|
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)
|
|
require.NoError(t, err)
|
|
require.Equal(t, "aps", opts.SigV4.Service)
|
|
})
|
|
}
|