stack_test.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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/stack');
  20. describe('App.Stack', function () {
  21. var stack;
  22. beforeEach(function () {
  23. stack = App.Stack.createRecord();
  24. });
  25. describe('#stackNameVersion', function () {
  26. it('should concat stack name and stack version', function () {
  27. stack.setProperties({
  28. stackName: 'HDP',
  29. stackVersion: '2.5'
  30. });
  31. expect(stack.get('stackNameVersion')).to.equal('HDP-2.5');
  32. });
  33. });
  34. describe('#isPatch', function () {
  35. var cases = [
  36. {
  37. type: 'PATCH',
  38. isPatch: true
  39. },
  40. {
  41. type: 'STANDARD',
  42. isPatch: false
  43. }
  44. ];
  45. cases.forEach(function (item) {
  46. it(item.type, function () {
  47. stack.set('type', item.type);
  48. expect(stack.get('isPatch')).to.equal(item.isPatch);
  49. });
  50. });
  51. });
  52. describe('#displayName', function () {
  53. it('should concat stack name and stack version', function () {
  54. stack.setProperties({
  55. stackName: 'HDP',
  56. repositoryVersion: '2.5.0.0-999'
  57. });
  58. expect(stack.get('displayName')).to.equal('HDP-2.5.0.0-999');
  59. });
  60. });
  61. describe('#repositories', function () {
  62. beforeEach(function () {
  63. stack.reopen({
  64. operatingSystems: [
  65. Em.Object.create({
  66. isSelected: false,
  67. repositories: [
  68. {
  69. id: 0
  70. },
  71. {
  72. id: 1
  73. }
  74. ]
  75. }),
  76. Em.Object.create({
  77. isSelected: false,
  78. repositories: [
  79. {
  80. id: 2
  81. },
  82. {
  83. id: 3
  84. }
  85. ]
  86. }),
  87. Em.Object.create({
  88. isSelected: false,
  89. repositories: [
  90. {
  91. id: 4
  92. },
  93. {
  94. id: 5
  95. }
  96. ]
  97. })
  98. ]
  99. });
  100. });
  101. it('no OSes selected', function () {
  102. expect(stack.get('repositories')).to.be.empty;
  103. });
  104. it('some OSes selected', function () {
  105. stack.get('operatingSystems')[0].isSelected = true;
  106. stack.get('operatingSystems')[2].isSelected = true;
  107. expect(stack.get('repositories').toArray()).to.eql([
  108. {
  109. id: 0
  110. },
  111. {
  112. id: 1
  113. },
  114. {
  115. id: 4
  116. },
  117. {
  118. id: 5
  119. }
  120. ]);
  121. });
  122. });
  123. describe('#cleanReposBaseUrls', function () {
  124. beforeEach(function () {
  125. stack.reopen({
  126. operatingSystems: [
  127. Em.Object.create({
  128. isSelected: true,
  129. repositories: [
  130. Em.Object.create({
  131. baseUrl: 'http://localhost/repo0'
  132. }),
  133. Em.Object.create({
  134. baseUrl: 'http://localhost/repo1'
  135. })
  136. ]
  137. }),
  138. Em.Object.create({
  139. isSelected: true,
  140. repositories: [
  141. Em.Object.create({
  142. baseUrl: 'http://localhost/repo2'
  143. }),
  144. Em.Object.create({
  145. baseUrl: 'http://localhost/repo3'
  146. })
  147. ]
  148. })
  149. ]
  150. });
  151. stack.cleanReposBaseUrls();
  152. });
  153. it('should clear repo urls', function () {
  154. expect(stack.get('repositories').mapProperty('baseUrl')).to.eql(['', '', '', '']);
  155. });
  156. });
  157. describe('#restoreReposBaseUrls', function () {
  158. beforeEach(function () {
  159. stack.reopen({
  160. operatingSystems: [
  161. Em.Object.create({
  162. isSelected: true,
  163. repositories: [
  164. Em.Object.create({
  165. baseUrlInit: 'http://localhost/repo0'
  166. }),
  167. Em.Object.create({
  168. baseUrlInit: 'http://localhost/repo1'
  169. })
  170. ]
  171. }),
  172. Em.Object.create({
  173. isSelected: true,
  174. repositories: [
  175. Em.Object.create({
  176. baseUrlInit: 'http://localhost/repo2'
  177. }),
  178. Em.Object.create({
  179. baseUrlInit: 'http://localhost/repo3'
  180. })
  181. ]
  182. })
  183. ]
  184. });
  185. stack.restoreReposBaseUrls();
  186. });
  187. it('should reset repo urls', function () {
  188. expect(stack.get('repositories').mapProperty('baseUrl')).to.eql([
  189. 'http://localhost/repo0',
  190. 'http://localhost/repo1',
  191. 'http://localhost/repo2',
  192. 'http://localhost/repo3'
  193. ]);
  194. });
  195. });
  196. });