metrics_test.go 1.7 KB

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