grafana/pkg/tsdb/prometheus/prometheus_test.go
ismail simsek 3fb6319d1b
Prometheus: Introduce prometheus backend library (#83952)
* 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
2024-03-11 17:22:33 +01:00

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)
})
}