host_test.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. App.set('testMode', false);
  51. App.store.loadMany(App.Host, data);
  52. describe('#diskUsedFormatted', function () {
  53. it('host1 - 10GB ', function () {
  54. var host = App.Host.find().findProperty('hostName', 'host1');
  55. expect(host.get('diskUsedFormatted')).to.equal('10GB');
  56. });
  57. it('host2 - 0GB', function () {
  58. var host = App.Host.find().findProperty('hostName', 'host2');
  59. expect(host.get('diskUsedFormatted')).to.equal('0GB');
  60. });
  61. it('host3 - 100GB', function () {
  62. var host = App.Host.find().findProperty('hostName', 'host3');
  63. expect(host.get('diskUsedFormatted')).to.equal('100GB');
  64. });
  65. });
  66. describe('#diskTotalFormatted', function () {
  67. it('host1 - 100.56GB ', function () {
  68. var host = App.Host.find().findProperty('hostName', 'host1');
  69. expect(host.get('diskTotalFormatted')).to.equal('100.56GB');
  70. });
  71. it('host2 - 90GB', function () {
  72. var host = App.Host.find().findProperty('hostName', 'host2');
  73. expect(host.get('diskTotalFormatted')).to.equal('90GB');
  74. });
  75. it('host3 - 100GB', function () {
  76. var host = App.Host.find().findProperty('hostName', 'host3');
  77. expect(host.get('diskTotalFormatted')).to.equal('100GB');
  78. });
  79. });
  80. describe('#diskUsageFormatted', function () {
  81. it('host1 - 9.94% ', function () {
  82. var host = App.Host.find().findProperty('hostName', 'host1');
  83. expect(host.get('diskUsageFormatted')).to.equal('9.94%');
  84. });
  85. it('host2 - 0%', function () {
  86. var host = App.Host.find().findProperty('hostName', 'host2');
  87. expect(host.get('diskUsageFormatted')).to.equal('0%');
  88. });
  89. it('host3 - 100%', function () {
  90. var host = App.Host.find().findProperty('hostName', 'host3');
  91. expect(host.get('diskUsageFormatted')).to.equal('100%');
  92. });
  93. });
  94. describe('#isNotHeartBeating', function () {
  95. it('host1 - true ', function () {
  96. var host = App.Host.find().findProperty('hostName', 'host1');
  97. expect(host.get('isNotHeartBeating')).to.equal(true);
  98. });
  99. it('host2 - false', function () {
  100. var host = App.Host.find().findProperty('hostName', 'host2');
  101. expect(host.get('isNotHeartBeating')).to.equal(false);
  102. });
  103. it('host3 - false', function () {
  104. var host = App.Host.find().findProperty('hostName', 'host3');
  105. expect(host.get('isNotHeartBeating')).to.equal(false);
  106. });
  107. });
  108. });