metric_find_query_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package cloudwatch
  2. import (
  3. "testing"
  4. "github.com/aws/aws-sdk-go/aws"
  5. "github.com/aws/aws-sdk-go/service/cloudwatch"
  6. cwapi "github.com/grafana/grafana/pkg/api/cloudwatch"
  7. . "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestCloudWatchMetrics(t *testing.T) {
  10. Convey("When calling getMetricsForCustomMetrics", t, func() {
  11. dsInfo := &cwapi.DatasourceInfo{
  12. Region: "us-east-1",
  13. Namespace: "Foo",
  14. Profile: "default",
  15. AssumeRoleArn: "",
  16. }
  17. f := func(dsInfo *cwapi.DatasourceInfo) (cloudwatch.ListMetricsOutput, error) {
  18. return cloudwatch.ListMetricsOutput{
  19. Metrics: []*cloudwatch.Metric{
  20. {
  21. MetricName: aws.String("Test_MetricName"),
  22. Dimensions: []*cloudwatch.Dimension{
  23. {
  24. Name: aws.String("Test_DimensionName"),
  25. },
  26. },
  27. },
  28. },
  29. }, nil
  30. }
  31. metrics, _ := getMetricsForCustomMetrics(dsInfo, f)
  32. Convey("Should contain Test_MetricName", func() {
  33. So(metrics, ShouldContain, "Test_MetricName")
  34. })
  35. })
  36. Convey("When calling getDimensionsForCustomMetrics", t, func() {
  37. dsInfo := &cwapi.DatasourceInfo{
  38. Region: "us-east-1",
  39. Namespace: "Foo",
  40. Profile: "default",
  41. AssumeRoleArn: "",
  42. }
  43. f := func(dsInfo *cwapi.DatasourceInfo) (cloudwatch.ListMetricsOutput, error) {
  44. return cloudwatch.ListMetricsOutput{
  45. Metrics: []*cloudwatch.Metric{
  46. {
  47. MetricName: aws.String("Test_MetricName"),
  48. Dimensions: []*cloudwatch.Dimension{
  49. {
  50. Name: aws.String("Test_DimensionName"),
  51. },
  52. },
  53. },
  54. },
  55. }, nil
  56. }
  57. dimensionKeys, _ := getDimensionsForCustomMetrics(dsInfo, f)
  58. Convey("Should contain Test_DimensionName", func() {
  59. So(dimensionKeys, ShouldContain, "Test_DimensionName")
  60. })
  61. })
  62. }