Files
grafana/pkg/tsdb/cloudwatch/services/hardcoded_metrics_test.go
Erik Sundell c652135724 [v9.3.x] CloudWatch: Cross-account querying support (#59389)
* add cross-account querying support

* fix tests
2022-11-28 14:21:34 +01:00

40 lines
1.7 KiB
Go

package services
import (
"testing"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models/resources"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestHardcodedMetrics_GetHardCodedDimensionKeysByNamespace(t *testing.T) {
t.Run("Should return an error in case namespace doesnt exist in map", func(t *testing.T) {
resp, err := GetHardCodedDimensionKeysByNamespace("unknownNamespace")
require.Error(t, err)
assert.Nil(t, resp)
assert.Equal(t, err.Error(), "unable to find dimensions for namespace '\"unknownNamespace\"'")
})
t.Run("Should return keys if namespace exist", func(t *testing.T) {
resp, err := GetHardCodedDimensionKeysByNamespace("AWS/EC2")
require.NoError(t, err)
assert.Equal(t, []resources.ResourceResponse[string]{{Value: "AutoScalingGroupName"}, {Value: "ImageId"}, {Value: "InstanceId"}, {Value: "InstanceType"}}, resp)
})
}
func TestHardcodedMetrics_GetHardCodedMetricsByNamespace(t *testing.T) {
t.Run("Should return an error in case namespace doesnt exist in map", func(t *testing.T) {
resp, err := GetHardCodedMetricsByNamespace("unknownNamespace")
require.Error(t, err)
assert.Nil(t, resp)
assert.Equal(t, err.Error(), "unable to find metrics for namespace '\"unknownNamespace\"'")
})
t.Run("Should return metrics if namespace exist", func(t *testing.T) {
resp, err := GetHardCodedMetricsByNamespace("AWS/IoTAnalytics")
require.NoError(t, err)
assert.Equal(t, []resources.ResourceResponse[resources.Metric]{{Value: resources.Metric{Name: "ActionExecution", Namespace: "AWS/IoTAnalytics"}}, {Value: resources.Metric{Name: "ActivityExecutionError", Namespace: "AWS/IoTAnalytics"}}, {Value: resources.Metric{Name: "IncomingMessages", Namespace: "AWS/IoTAnalytics"}}}, resp)
})
}