metrics_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. region := "us-east-1"
  11. namespace := "Foo"
  12. database := "default"
  13. f := func(region string, namespace string, database string) (cloudwatch.ListMetricsOutput, error) {
  14. return cloudwatch.ListMetricsOutput{
  15. Metrics: []*cloudwatch.Metric{
  16. {
  17. MetricName: aws.String("Test_MetricName"),
  18. Dimensions: []*cloudwatch.Dimension{
  19. {
  20. Name: aws.String("Test_DimensionName"),
  21. },
  22. },
  23. },
  24. },
  25. }, nil
  26. }
  27. metrics, _ := getMetricsForCustomMetrics(region, namespace, database, f)
  28. Convey("Should contain Test_MetricName", func() {
  29. So(metrics, ShouldContain, "Test_MetricName")
  30. })
  31. })
  32. Convey("When calling getDimensionsForCustomMetrics", t, func() {
  33. region := "us-east-1"
  34. namespace := "Foo"
  35. database := "default"
  36. f := func(region string, namespace string, database string) (cloudwatch.ListMetricsOutput, error) {
  37. return cloudwatch.ListMetricsOutput{
  38. Metrics: []*cloudwatch.Metric{
  39. {
  40. MetricName: aws.String("Test_MetricName"),
  41. Dimensions: []*cloudwatch.Dimension{
  42. {
  43. Name: aws.String("Test_DimensionName"),
  44. },
  45. },
  46. },
  47. },
  48. }, nil
  49. }
  50. dimensionKeys, _ := getDimensionsForCustomMetrics(region, namespace, database, f)
  51. Convey("Should contain Test_DimensionName", func() {
  52. So(dimensionKeys, ShouldContain, "Test_DimensionName")
  53. })
  54. })
  55. }