mirror of
https://github.com/grafana/grafana.git
synced 2024-11-27 03:11:01 -06:00
00bef917ee
* CloudWatch: Datasource improvements * Add statistic as template variale * Add wildcard to list of values * Template variable intercept dimension key * Return row specific errors when transformation error occured * Add meta feedback * Make it possible to retrieve values without known metrics * Add curated dashboard for EC2 * Fix broken tests * Use correct dashboard name * Display alert in case multi template var is being used for some certain props in the cloudwatch query * Minor fixes after feedback * Update dashboard json * Update snapshot test * Make sure region default is intercepted in cloudwatch link * Update dashboards * Include ec2 dashboard in ds * Do not include ec2 dashboard in beta1 * Display actual region
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package cloudwatch
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
"github.com/aws/aws-sdk-go/aws/request"
|
|
"github.com/aws/aws-sdk-go/service/cloudwatch"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
)
|
|
|
|
var counter = 1
|
|
|
|
type cloudWatchFakeClient struct {
|
|
}
|
|
|
|
func (client *cloudWatchFakeClient) GetMetricDataWithContext(ctx aws.Context, input *cloudwatch.GetMetricDataInput, opts ...request.Option) (*cloudwatch.GetMetricDataOutput, error) {
|
|
nextToken := "next"
|
|
res := []*cloudwatch.MetricDataResult{{
|
|
Values: []*float64{aws.Float64(12.3), aws.Float64(23.5)},
|
|
}}
|
|
if counter == 0 {
|
|
nextToken = ""
|
|
res = []*cloudwatch.MetricDataResult{{
|
|
Values: []*float64{aws.Float64(100)},
|
|
}}
|
|
}
|
|
counter--
|
|
return &cloudwatch.GetMetricDataOutput{
|
|
MetricDataResults: res,
|
|
NextToken: aws.String(nextToken),
|
|
}, nil
|
|
}
|
|
|
|
func TestGetMetricDataExecutorTest(t *testing.T) {
|
|
Convey("TestGetMetricDataExecutorTest", t, func() {
|
|
Convey("pagination works", func() {
|
|
executor := &CloudWatchExecutor{}
|
|
inputs := &cloudwatch.GetMetricDataInput{MetricDataQueries: []*cloudwatch.MetricDataQuery{}}
|
|
res, err := executor.executeRequest(context.Background(), &cloudWatchFakeClient{}, inputs)
|
|
So(err, ShouldBeNil)
|
|
So(len(res), ShouldEqual, 2)
|
|
So(len(res[0].MetricDataResults[0].Values), ShouldEqual, 2)
|
|
So(*res[0].MetricDataResults[0].Values[1], ShouldEqual, 23.5)
|
|
So(*res[1].MetricDataResults[0].Values[0], ShouldEqual, 100)
|
|
})
|
|
})
|
|
|
|
}
|