metrics_test.go 1.6 KB

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