mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fix missing defaultRegion (#35436)
This commit is contained in:
parent
ccd3ec5f2f
commit
086309700e
@ -102,7 +102,7 @@ func NewInstanceSettings() datasource.InstanceFactoryFunc {
|
|||||||
return func(settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
|
return func(settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
|
||||||
jsonData := struct {
|
jsonData := struct {
|
||||||
Profile string `json:"profile"`
|
Profile string `json:"profile"`
|
||||||
Region string `json:"defaulRegion"`
|
Region string `json:"defaultRegion"`
|
||||||
AssumeRoleARN string `json:"assumeRoleArn"`
|
AssumeRoleARN string `json:"assumeRoleArn"`
|
||||||
ExternalID string `json:"externalId"`
|
ExternalID string `json:"externalId"`
|
||||||
Endpoint string `json:"endpoint"`
|
Endpoint string `json:"endpoint"`
|
||||||
|
73
pkg/tsdb/cloudwatch/cloudwatch_test.go
Normal file
73
pkg/tsdb/cloudwatch/cloudwatch_test.go
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
package cloudwatch
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
"github.com/grafana/grafana-aws-sdk/pkg/awsds"
|
||||||
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewInstanceSettings(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
settings backend.DataSourceInstanceSettings
|
||||||
|
expectedDS datasourceInfo
|
||||||
|
Err require.ErrorAssertionFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "creates a request",
|
||||||
|
settings: backend.DataSourceInstanceSettings{
|
||||||
|
JSONData: []byte(`{
|
||||||
|
"profile": "foo",
|
||||||
|
"defaultRegion": "us-east2",
|
||||||
|
"assumeRoleArn": "role",
|
||||||
|
"externalId": "id",
|
||||||
|
"endpoint": "bar",
|
||||||
|
"customMetricsNamespaces": "ns",
|
||||||
|
"authType": "keys"
|
||||||
|
}`),
|
||||||
|
DecryptedSecureJSONData: map[string]string{
|
||||||
|
"accessKey": "A123",
|
||||||
|
"secretKey": "secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedDS: datasourceInfo{
|
||||||
|
profile: "foo",
|
||||||
|
region: "us-east2",
|
||||||
|
assumeRoleARN: "role",
|
||||||
|
externalID: "id",
|
||||||
|
endpoint: "bar",
|
||||||
|
namespace: "ns",
|
||||||
|
authType: awsds.AuthTypeKeys,
|
||||||
|
accessKey: "A123",
|
||||||
|
secretKey: "secret",
|
||||||
|
},
|
||||||
|
Err: require.NoError,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
f := NewInstanceSettings()
|
||||||
|
model, err := f(tt.settings)
|
||||||
|
tt.Err(t, err)
|
||||||
|
datasourceComparer := cmp.Comparer(func(d1 datasourceInfo, d2 datasourceInfo) bool {
|
||||||
|
return d1.profile == d2.profile &&
|
||||||
|
d1.region == d2.region &&
|
||||||
|
d1.authType == d2.authType &&
|
||||||
|
d1.assumeRoleARN == d2.assumeRoleARN &&
|
||||||
|
d1.externalID == d2.externalID &&
|
||||||
|
d1.namespace == d2.namespace &&
|
||||||
|
d1.endpoint == d2.endpoint &&
|
||||||
|
d1.accessKey == d2.accessKey &&
|
||||||
|
d1.secretKey == d2.secretKey &&
|
||||||
|
d1.datasourceID == d2.datasourceID
|
||||||
|
})
|
||||||
|
if !cmp.Equal(model.(datasourceInfo), tt.expectedDS, datasourceComparer) {
|
||||||
|
t.Errorf("Unexpected result. Expecting\n%v \nGot:\n%v", model, tt.expectedDS)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user