2019-11-14 03:59:41 -06:00
|
|
|
package cloudwatch
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/service/cloudwatch"
|
2022-11-08 03:28:50 -06:00
|
|
|
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/mocks"
|
2020-05-18 05:25:58 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-11-08 03:28:50 -06:00
|
|
|
"github.com/stretchr/testify/mock"
|
2020-05-18 05:25:58 -05:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-11-14 03:59:41 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetMetricDataExecutorTest(t *testing.T) {
|
2020-07-14 01:23:23 -05:00
|
|
|
executor := &cloudWatchExecutor{}
|
2020-05-18 05:25:58 -05:00
|
|
|
inputs := &cloudwatch.GetMetricDataInput{MetricDataQueries: []*cloudwatch.MetricDataQuery{}}
|
2022-11-08 03:28:50 -06:00
|
|
|
mockMetricClient := &mocks.MetricsAPI{}
|
|
|
|
mockMetricClient.On("GetMetricDataWithContext", mock.Anything, mock.Anything, mock.Anything).Return(
|
|
|
|
&cloudwatch.GetMetricDataOutput{
|
|
|
|
MetricDataResults: []*cloudwatch.MetricDataResult{{Values: []*float64{aws.Float64(12.3), aws.Float64(23.5)}}},
|
|
|
|
NextToken: aws.String("next"),
|
|
|
|
}, nil).Once()
|
|
|
|
mockMetricClient.On("GetMetricDataWithContext", mock.Anything, mock.Anything, mock.Anything).Return(
|
|
|
|
&cloudwatch.GetMetricDataOutput{
|
|
|
|
MetricDataResults: []*cloudwatch.MetricDataResult{{Values: []*float64{aws.Float64(100)}}},
|
|
|
|
}, nil).Once()
|
|
|
|
res, err := executor.executeRequest(context.Background(), mockMetricClient, inputs)
|
2020-05-18 05:25:58 -05:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, res, 2)
|
|
|
|
require.Len(t, res[0].MetricDataResults[0].Values, 2)
|
|
|
|
assert.Equal(t, 23.5, *res[0].MetricDataResults[0].Values[1])
|
|
|
|
assert.Equal(t, 100.0, *res[1].MetricDataResults[0].Values[0])
|
2019-11-14 03:59:41 -06:00
|
|
|
}
|