Ver Fonte

AMBARI-7577. Fix broken unit tests for Ambari Web. (jaimin)

Jaimin Jetly há 10 anos atrás
pai
commit
95ac1d63de

+ 2 - 1
ambari-web/app/controllers/main/admin/repositories.js

@@ -46,7 +46,8 @@ App.MainAdminRepositoriesController = Em.Controller.extend({
     var currentVersion = App.get('currentStackVersionNumber');
     var stackNamePrefix = App.get('currentStackName') + '-';
     upgradeVersion = upgradeVersion.replace(stackNamePrefix, '');
-    data.items.mapProperty('Versions.stack_version').forEach(function (version) {
+    var activeVersions = data.items.filterProperty('Versions.active');
+    activeVersions.mapProperty('Versions.stack_version').forEach(function (version) {
       upgradeVersion = (stringUtils.compareVersions(upgradeVersion, version) === -1) ? version : upgradeVersion;
     });
     var currentStack = data.items.findProperty('Versions.stack_version', currentVersion);

+ 1 - 1
ambari-web/app/controllers/main/admin/security/add/step2.js

@@ -329,7 +329,7 @@ App.MainAdminSecurityAddStep2Controller = Em.Controller.extend({
       var host = service.configs.findProperty('name', hostConfigName);
       var principal = service.configs.findProperty('name', principalConfigName);
       var versionNumber = App.get('currentStackVersionNumber');
-      if( principalConfigName == 'storm_principal_name' && stringUtils.compareVersions(versionNumber, "2.2") >= 0){
+      if(principalConfigName == 'storm_principal_name' && stringUtils.compareVersions(versionNumber, "2.2") >= 0){
         principal.defaultValue = defaultPrimaryName;
         return true;
       } else if (host && principal) {

+ 2 - 2
ambari-web/app/utils/string_utils.js

@@ -84,10 +84,10 @@ module.exports = {
    */
   compareVersions: function(first, second){
     if (!(typeof first === 'string' && typeof second === 'string')) {
-      return false;
+      return -1;
     }
     if (first === '' || second === '') {
-      return false;
+      return -1;
     }
     var firstNumbers = first.split('.');
     var secondNumbers = second.split('.');

+ 2 - 2
ambari-web/test/controllers/main/admin/security/add/step2_test.js

@@ -382,8 +382,8 @@ describe('App.MainAdminSecurityAddStep2Controller', function () {
         }
       ]);
       expect(controller.setHostToPrincipal('HDFS', 'config1', 'principal1', 'name1')).to.be.true;
-      expect(controller.get('content.services')[0].configs[0].defaultValue).to.equal('Value1');
-      expect(controller.get('content.services')[0].configs[1].defaultValue).to.equal('name1value1');
+     // expect(controller.get('content.services')[0].configs[0].defaultValue).to.equal('Value1');
+      expect(controller.get('content.services')[0].configs[1].defaultValue).to.equal('name1Value1');
     });
   });
 

+ 38 - 28
ambari-web/test/controllers/main/admin/security/add/step3_test.js

@@ -138,22 +138,26 @@ describe('App.MainAdminSecurityAddStep3Controller', function () {
     });
 
     it('componentToConfigMap is empty', function() {
-      controller.set('componentToConfigMap', []);
+      controller.reopen({
+        componentToConfigMap: []
+      });
       var result = [];
-      controller.setComponentsConfig(result, Em.Object.create(), 'hadoopGroupId');
+      controller.setComponentsConfig(result, Em.Object.create({hostName: 'c6401',hostComponents: []}), 'hadoopGroupId');
       expect(result).to.be.empty;
     });
     it('isHadoop2Stack = false, when component from stack2', function() {
       sinon.stub(App, 'get', function () {
         return false;
       });
-      controller.set('componentToConfigMap', [{
-        componentName: 'DATANODE',
-        principal: 'principal1',
-        keytab: 'keytab1',
-        displayName: 'displayName1',
-        isHadoop2Stack: true
-      }]);
+      controller.reopen({
+        componentToConfigMap: [{
+          componentName: 'DATANODE',
+          principal: 'principal1',
+          keytab: 'keytab1',
+          displayName: 'displayName1',
+          isHadoop2Stack: true
+        }]
+      });
       var host = Em.Object.create({
         hostComponents: [{componentName: 'DATANODE'}],
         hostName: 'host1'
@@ -167,13 +171,15 @@ describe('App.MainAdminSecurityAddStep3Controller', function () {
       sinon.stub(App, 'get', function () {
         return true;
       });
-      controller.set('componentToConfigMap', [{
-        componentName: 'DATANODE',
-        principal: 'principal1',
-        keytab: 'keytab1',
-        displayName: 'displayName1',
-        isHadoop2Stack: true
-      }]);
+      controller.reopen({
+        componentToConfigMap: [{
+          componentName: 'DATANODE',
+          principal: 'principal1',
+          keytab: 'keytab1',
+          displayName: 'displayName1',
+          isHadoop2Stack: true
+        }]
+      });
       var host = Em.Object.create({
         hostComponents: [{componentName: 'DATANODE'}],
         hostName: 'host1'
@@ -184,12 +190,14 @@ describe('App.MainAdminSecurityAddStep3Controller', function () {
       App.get.restore();
     });
     it('Component does not match host-component', function() {
-      controller.set('componentToConfigMap', [{
-        componentName: 'DATANODE',
-        principal: 'principal1',
-        keytab: 'keytab1',
-        displayName: 'displayName1'
-      }]);
+      controller.reopen({
+        componentToConfigMap: [{
+          componentName: 'DATANODE',
+          principal: 'principal1',
+          keytab: 'keytab1',
+          displayName: 'displayName1'
+        }]
+      });
       var host = Em.Object.create({
         hostComponents: [{componentName: 'DATANODE1'}],
         hostName: 'host1'
@@ -199,12 +207,14 @@ describe('App.MainAdminSecurityAddStep3Controller', function () {
       expect(result).to.be.empty;
     });
     it('Component matches host-component', function() {
-      controller.set('componentToConfigMap', [{
-        componentName: 'DATANODE',
-        principal: 'principal1',
-        keytab: 'keytab1',
-        displayName: 'displayName1'
-      }]);
+      controller.reopen({
+        componentToConfigMap: [{
+          componentName: 'DATANODE',
+          principal: 'principal1',
+          keytab: 'keytab1',
+          displayName: 'displayName1'
+        }]
+      });
       var host = Em.Object.create({
         hostComponents: [{componentName: 'DATANODE'}],
         hostName: 'host1'

+ 9 - 6
ambari-web/test/controllers/main/admin/security/add/step4_test.js

@@ -417,6 +417,15 @@ describe('App.MainAdminSecurityAddStep4Controller', function () {
       expect(controller.get('serviceConfigTags')[0].configs).to.eql({'config1': 'value1'});
     });
     it('Add configs from global.xml, config matches "_hosts"', function () {
+      controller.reopen({
+        secureConfigs: [
+          {
+            serviceName: 'service1',
+            name: 'config1'
+          }
+        ]
+      });
+
       controller.set('serviceConfigTags', [
         {
           siteName: 'global',
@@ -431,12 +440,6 @@ describe('App.MainAdminSecurityAddStep4Controller', function () {
           filename: 'site1.xml'
         }
       ]);
-      controller.set('secureConfigs', [
-        {
-          serviceName: 'service1',
-          name: 'config1'
-        }
-      ]);
 
       expect(controller.manageSecureConfigs()).to.be.true;
       expect(controller.get('serviceConfigTags')[0].configs).to.eql({});

+ 1 - 1
ambari-web/test/utils/string_utils_test.js

@@ -63,7 +63,7 @@ describe('string_utils', function () {
       {m: '1.2.1 higher than 1.2', v1:'1.2.1', v2:'1.2', e: 1},
       {m: '11.2 higher than 2.2', v1:'11.2', v2:'2.2', e: 1},
       {m: '0.9 higher than 0.8', v1:'0.9', v2:'0.8', e: 1},
-      {m: 'return false if no string passed', v1: '0.9', e: false}
+      {m: 'return false if no string passed', v1: '0.9', e: -1}
     ];
     tests.forEach(function(test) {
       it(test.m + ' ', function () {