heatmap_test.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var heatmap = require('utils/heatmap');
  19. describe('heatmap utils', function () {
  20. describe('mappers', function () {
  21. var mappers;
  22. beforeEach(function () {
  23. mappers = Em.Object.create(heatmap.mappers);
  24. });
  25. describe('#metricMapperWithTransform', function () {
  26. var cases = [
  27. {
  28. hostComponents: null,
  29. hostToValueMap: {},
  30. title: 'no host components data'
  31. },
  32. {
  33. hostComponents: [null, null],
  34. metricName: 'm0',
  35. hostToValueMap: {},
  36. title: 'host components data is absent'
  37. },
  38. {
  39. hostComponents: [{}, {}],
  40. metricName: 'm1',
  41. hostToValueMap: {},
  42. title: 'provided metric data is absent'
  43. },
  44. {
  45. hostComponents: [{}, {}],
  46. metricName: 'm2.m3',
  47. hostToValueMap: {},
  48. title: 'provided metrics data is absent'
  49. },
  50. {
  51. hostComponents: [
  52. null,
  53. {},
  54. {
  55. m4: 1,
  56. HostRoles: {
  57. host_name: 'h0'
  58. }
  59. },
  60. {
  61. m4: 1.5,
  62. HostRoles: {
  63. host_name: 'h1'
  64. }
  65. },
  66. {
  67. m4: 1.60,
  68. HostRoles: {
  69. host_name: 'h2'
  70. }
  71. },
  72. {
  73. m4: 1.72,
  74. HostRoles: {
  75. host_name: 'h3'
  76. }
  77. },
  78. {
  79. m4: 1.85,
  80. HostRoles: {
  81. host_name: 'h4'
  82. }
  83. },
  84. {
  85. m4: 1.97,
  86. HostRoles: {
  87. host_name: 'h5'
  88. }
  89. }
  90. ],
  91. metricName: 'm4',
  92. hostToValueMap: {
  93. h0: '1.0',
  94. h1: '1.5',
  95. h2: '1.6',
  96. h3: '1.7',
  97. h4: '1.9',
  98. h5: '2.0'
  99. },
  100. title: 'no transform function'
  101. },
  102. {
  103. hostComponents: [
  104. {
  105. m5: 100,
  106. HostRoles: {
  107. host_name: 'h6'
  108. }
  109. }
  110. ],
  111. metricName: 'm5',
  112. transformValueFunction: Math.sqrt,
  113. hostToValueMap: {
  114. h6: '10.0'
  115. },
  116. title: 'transform function provided'
  117. }
  118. ];
  119. cases.forEach(function (item) {
  120. it(item.title, function () {
  121. expect(mappers.metricMapperWithTransform({
  122. host_components: item.hostComponents
  123. }, item.metricName, item.transformValueFunction)).to.eql(item.hostToValueMap);
  124. });
  125. });
  126. });
  127. });
  128. });