host_test.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 App = require('app');
  19. require('models/host');
  20. describe('App.Host', function () {
  21. var data = [
  22. {
  23. id: 'host1',
  24. host_name: 'host1',
  25. memory: 200000,
  26. disk_total: 100.555,
  27. disk_free: 90.555,
  28. health_status: 'HEALTHY',
  29. last_heart_beat_time: (new Date()).getTime() - 18100000
  30. },
  31. {
  32. id: 'host2',
  33. host_name: 'host2',
  34. memory: 99999,
  35. disk_total: 90,
  36. disk_free: 90,
  37. health_status: 'HEALTHY',
  38. last_heart_beat_time: (new Date()).getTime() - 170000
  39. },
  40. {
  41. id: 'host3',
  42. host_name: 'host3',
  43. memory: 99999,
  44. disk_total: 99.999,
  45. disk_free: 0,
  46. health_status: 'UNKNOWN',
  47. last_heart_beat_time: (new Date()).getTime()
  48. }
  49. ];
  50. before(function() {
  51. App.set('testMode', false);
  52. });
  53. App.store.loadMany(App.Host, data);
  54. describe('#diskUsedFormatted', function () {
  55. it('host1 - 10GB ', function () {
  56. var host = App.Host.find().findProperty('hostName', 'host1');
  57. expect(host.get('diskUsedFormatted')).to.equal('10GB');
  58. });
  59. it('host2 - 0GB', function () {
  60. var host = App.Host.find().findProperty('hostName', 'host2');
  61. expect(host.get('diskUsedFormatted')).to.equal('0GB');
  62. });
  63. it('host3 - 100GB', function () {
  64. var host = App.Host.find().findProperty('hostName', 'host3');
  65. expect(host.get('diskUsedFormatted')).to.equal('100GB');
  66. });
  67. });
  68. describe('#diskTotalFormatted', function () {
  69. it('host1 - 100.56GB ', function () {
  70. var host = App.Host.find().findProperty('hostName', 'host1');
  71. expect(host.get('diskTotalFormatted')).to.equal('100.56GB');
  72. });
  73. it('host2 - 90GB', function () {
  74. var host = App.Host.find().findProperty('hostName', 'host2');
  75. expect(host.get('diskTotalFormatted')).to.equal('90GB');
  76. });
  77. it('host3 - 100GB', function () {
  78. var host = App.Host.find().findProperty('hostName', 'host3');
  79. expect(host.get('diskTotalFormatted')).to.equal('100GB');
  80. });
  81. });
  82. describe('#diskUsageFormatted', function () {
  83. it('host1 - 9.94% ', function () {
  84. var host = App.Host.find().findProperty('hostName', 'host1');
  85. expect(host.get('diskUsageFormatted')).to.equal('9.94%');
  86. });
  87. it('host2 - 0%', function () {
  88. var host = App.Host.find().findProperty('hostName', 'host2');
  89. expect(host.get('diskUsageFormatted')).to.equal('0%');
  90. });
  91. it('host3 - 100%', function () {
  92. var host = App.Host.find().findProperty('hostName', 'host3');
  93. expect(host.get('diskUsageFormatted')).to.equal('100%');
  94. });
  95. });
  96. describe('#isNotHeartBeating', function () {
  97. it('host2 - false', function () {
  98. var host = App.Host.find().findProperty('hostName', 'host2');
  99. expect(host.get('isNotHeartBeating')).to.equal(false);
  100. });
  101. it('host3 - false', function () {
  102. var host = App.Host.find().findProperty('hostName', 'host3');
  103. expect(host.get('isNotHeartBeating')).to.equal(true);
  104. });
  105. });
  106. });