cloudwatch-datasource-specs.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // define([
  2. // './helpers',
  3. // 'app/plugins/datasource/cloudwatch/datasource',
  4. // 'aws-sdk',
  5. // ], function(helpers) {
  6. // 'use strict';
  7. //
  8. // describe('CloudWatchDatasource', function() {
  9. // var ctx = new helpers.ServiceTestContext();
  10. //
  11. // beforeEach(module('grafana.services'));
  12. // beforeEach(module('grafana.controllers'));
  13. // beforeEach(ctx.providePhase(['templateSrv']));
  14. // beforeEach(ctx.createService('CloudWatchDatasource'));
  15. // beforeEach(function() {
  16. // ctx.ds = new ctx.service({
  17. // jsonData: {
  18. // defaultRegion: 'us-east-1',
  19. // access: 'proxy'
  20. // }
  21. // });
  22. // });
  23. //
  24. // describe('When performing CloudWatch query', function() {
  25. // var requestParams;
  26. //
  27. // var query = {
  28. // range: { from: 'now-1h', to: 'now' },
  29. // targets: [
  30. // {
  31. // region: 'us-east-1',
  32. // namespace: 'AWS/EC2',
  33. // metricName: 'CPUUtilization',
  34. // dimensions: {
  35. // InstanceId: 'i-12345678'
  36. // },
  37. // statistics: {
  38. // Average: true
  39. // },
  40. // period: 300
  41. // }
  42. // ]
  43. // };
  44. //
  45. // var response = {
  46. // Datapoints: [
  47. // {
  48. // Average: 1,
  49. // Timestamp: 'Wed Dec 31 1969 16:00:00 GMT-0800 (PST)'
  50. // }
  51. // ],
  52. // Label: 'CPUUtilization'
  53. // };
  54. //
  55. // beforeEach(function() {
  56. // ctx.ds.getCloudWatchClient = function() {
  57. // return {
  58. // getMetricStatistics: function(params, callback) {
  59. // setTimeout(function() {
  60. // requestParams = params;
  61. // callback(null, response);
  62. // }, 0);
  63. // }
  64. // };
  65. // };
  66. // });
  67. //
  68. // it('should generate the correct query', function() {
  69. // ctx.ds.query(query).then(function() {
  70. // expect(requestParams.Namespace).to.be(query.targets[0].namespace);
  71. // expect(requestParams.MetricName).to.be(query.targets[0].metricName);
  72. // expect(requestParams.Dimensions[0].Name).to.be(Object.keys(query.targets[0].dimensions)[0]);
  73. // expect(requestParams.Dimensions[0].Value).to.be(query.targets[0].dimensions[Object.keys(query.targets[0].dimensions)[0]]);
  74. // expect(requestParams.Statistics).to.eql(Object.keys(query.targets[0].statistics));
  75. // expect(requestParams.Period).to.be(query.targets[0].period);
  76. // });
  77. // });
  78. //
  79. // it('should return series list', function() {
  80. // ctx.ds.query(query).then(function(result) {
  81. // var s = Object.keys(query.targets[0].statistics)[0];
  82. // expect(result.data[0].target).to.be(response.Label + s);
  83. // expect(result.data[0].datapoints[0][0]).to.be(response.Datapoints[0][s]);
  84. // });
  85. // });
  86. // });
  87. //
  88. // describe('When performing CloudWatch metricFindQuery', function() {
  89. // var requestParams;
  90. //
  91. // var response = {
  92. // Metrics: [
  93. // {
  94. // Namespace: 'AWS/EC2',
  95. // MetricName: 'CPUUtilization',
  96. // Dimensions: [
  97. // {
  98. // Name: 'InstanceId',
  99. // Value: 'i-12345678'
  100. // }
  101. // ]
  102. // }
  103. // ]
  104. // };
  105. //
  106. // beforeEach(function() {
  107. // ctx.ds.getCloudWatchClient = function() {
  108. // return {
  109. // listMetrics: function(params, callback) {
  110. // setTimeout(function() {
  111. // requestParams = params;
  112. // callback(null, response);
  113. // }, 0);
  114. // }
  115. // };
  116. // };
  117. // });
  118. //
  119. // it('should return suggest list for region()', function() {
  120. // var query = 'region()';
  121. // ctx.ds.metricFindQuery(query).then(function(result) {
  122. // expect(result).to.contain('us-east-1');
  123. // });
  124. // });
  125. //
  126. // it('should return suggest list for namespace()', function() {
  127. // var query = 'namespace()';
  128. // ctx.ds.metricFindQuery(query).then(function(result) {
  129. // expect(result).to.contain('AWS/EC2');
  130. // });
  131. // });
  132. //
  133. // it('should return suggest list for metrics()', function() {
  134. // var query = 'metrics(AWS/EC2)';
  135. // ctx.ds.metricFindQuery(query).then(function(result) {
  136. // expect(result).to.contain('CPUUtilization');
  137. // });
  138. // });
  139. //
  140. // it('should return suggest list for dimension_keys()', function() {
  141. // var query = 'dimension_keys(AWS/EC2)';
  142. // ctx.ds.metricFindQuery(query).then(function(result) {
  143. // expect(result).to.contain('InstanceId');
  144. // });
  145. // });
  146. //
  147. // it('should return suggest list for dimension_values()', function() {
  148. // var query = 'dimension_values(us-east-1,AWS/EC2,CPUUtilization)';
  149. // ctx.ds.metricFindQuery(query).then(function(result) {
  150. // expect(result).to.contain('InstanceId');
  151. // });
  152. // });
  153. // });
  154. // });
  155. // });