Cloudwatch: Refactor metrics resource request (#57424)
* refactor metrics request * Update pkg/tsdb/cloudwatch/routes/dimension_keys_test.go Co-authored-by: Shirley <4163034+fridgepoet@users.noreply.github.com> * return metric struct value intead of pointer * make it possible to test hard coded metrics service * test all paths in route * fix broken test * fix one more broken test * add integration test Co-authored-by: Shirley <4163034+fridgepoet@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
|
||||
"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, []string{"AutoScalingGroupName", "ImageId", "InstanceId", "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, []models.Metric{{Name: "ActionExecution", Namespace: "AWS/IoTAnalytics"}, {Name: "ActivityExecutionError", Namespace: "AWS/IoTAnalytics"}, {Name: "IncomingMessages", Namespace: "AWS/IoTAnalytics"}}, resp)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user