The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/tsdb/cloudwatch/models/request/metrics_test.go

48 lines
1.2 KiB

package request
import (
"net/url"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMetricsRequest(t *testing.T) {
t.Run("Should parse parameters", func(t *testing.T) {
request, err := GetMetricsRequest(map[string][]string{"region": {"us-east-1"}, "namespace": {"AWS/EC2"}})
require.NoError(t, err)
assert.Equal(t, "us-east-1", request.Region)
assert.Equal(t, "AWS/EC2", request.Namespace)
})
tests := []struct {
reqType MetricsRequestType
params url.Values
}{
{
params: map[string][]string{"region": {"us-east-1"}, "namespace": {"AWS/EC2"}},
reqType: MetricsByNamespaceRequestType,
},
{
params: map[string][]string{"region": {"us-east-1"}},
reqType: AllMetricsRequestType,
},
{
params: map[string][]string{"region": {"us-east-1"}, "namespace": {""}},
reqType: AllMetricsRequestType,
},
{
params: map[string][]string{"region": {"us-east-1"}, "namespace": {"custom-namespace"}},
reqType: CustomNamespaceRequestType,
},
}
for _, tc := range tests {
t.Run("Should resolve the correct type", func(t *testing.T) {
request, err := GetMetricsRequest(tc.params)
require.NoError(t, err)
assert.Equal(t, tc.reqType, request.Type())
})
}
}