YUKI Hiroshi
null+****@clear*****
Mon Oct 15 17:51:21 JST 2012
YUKI Hiroshi 2012-10-15 17:51:21 +0900 (Mon, 15 Oct 2012) New Revision: ea038317db20efbcbb5f847580e86a4bfe89c5fb https://github.com/groonga/gcs/commit/ea038317db20efbcbb5f847580e86a4bfe89c5fb Log: Make gcs-delete-domain command working correctly Modified files: lib/command-line.js test/gcs-commands.test.js Modified: lib/command-line.js (+37 -23) =================================================================== --- lib/command-line.js 2012-10-15 17:04:18 +0900 (094c9df) +++ lib/command-line.js 2012-10-15 17:51:21 +0900 (c392248) @@ -139,31 +139,40 @@ CommandLineInterface.prototype = { this.getDomainStatuses( { 'DomainNames.member.1' : domainName }, function(error, domainStatuses) { - if (domainStatuses.length) { + if (error) + self.raiseFatalError(error); + if (domainStatuses.length && domainStatuses[0]) { callback(null, domainStatuses[0]); } else { - self.raiseFatalError('You must specify an existing domain name.'); + self.raiseFatalError(domainName + ' does not exist. You must specify an existing domain name.'); } } ); }, getDomainStatuses: function(options, callback) { - var self = this; - var domainStatusesCallback = function(error, response) { - if (error) - self.raiseFatalError(error); - var domainStatuses = response.Body - .DescribeDomainsResponse - .DescribeDomainsResult - .DomainStatusList - .member; - (callback || options)(null, domainStatuses); - }; - if (callback) - this.cloudSearch.DescribeDomains(options, domainStatusesCallback); - else - this.cloudSearch.DescribeDomains(domainStatusesCallback); + try { + var self = this; + if (!callback) callback = options; + var domainStatusesCallback = function(error, response) { + if (error) + self.raiseFatalError(error); + var domainStatuses = response.Body + .DescribeDomainsResponse + .DescribeDomainsResult + .DomainStatusList + .member; + if (!Array.isArray(domainStatuses)) + domainStatuses = [domainStatuses]; + callback(null, domainStatuses); + }; + if (arguments.length > 1) + this.cloudSearch.DescribeDomains(options, domainStatusesCallback); + else + this.cloudSearch.DescribeDomains(domainStatusesCallback); + } catch(error) { + this.raiseFatalError(error); + } }, getIndexFieldStatuses: function(domainName, callback) { @@ -177,8 +186,11 @@ CommandLineInterface.prototype = { var indexFields = response.Body .DescribeIndexFieldsResponse .DescribeIndexFieldsResult - .IndexFields; - indexFields = Array.isArray(indexFields.member) ? indexFields.member : []; + .IndexFields + .member; + indexFields = !indexFields ? [] : + !Array.isArray(indexFields.member) ? [indexFields.member] : + indexFields.member; callback(null, indexFields); } ); @@ -207,16 +219,18 @@ CommandLineInterface.prototype = { }, assertDomainExistsHTTP: function(callback) { - this.getDomainStatus(this.domainName, function(error, domain) { - if (error) - self.raiseFatalError('You must specify an existing domain name.'); + var domainName = this.domainName; + var self = this; + this.getDomainStatus(domainName, function(error, domain) { + if (error || !domain) + self.raiseFatalError(domainName + ' does not exist. You must specify an existing domain name.'); callback(); }); }, assertDomainExists: function() { if (!this.domain.exists()) - this.raiseFatalError('You must specify an existing domain name.'); + this.raiseFatalError(this.domainName + ' does not exist. You must specify an existing domain name.'); return this; }, Modified: test/gcs-commands.test.js (+9 -8) =================================================================== --- test/gcs-commands.test.js 2012-10-15 17:04:18 +0900 (3a0011e) +++ test/gcs-commands.test.js 2012-10-15 17:51:21 +0900 (1111f43) @@ -30,11 +30,11 @@ function assertDomainNotSpecified(result) { result.output.stderr); } -function assertDomainNotExist(result) { +function assertDomainNotExist(result, domainName) { assert.deepEqual({ code: result.code, message: result.output.stdout }, { code: 1, - message: 'You must specify an existing domain name.\n' }, + message: domainName + ' does not exist. You must specify an existing domain name.\n' }, result.output.stderr); } @@ -142,9 +142,10 @@ suite('gcs-delete-domain', function() { .run('gcs-delete-domain', '--domain-name', 'test', '--force', - '--database-path', temporaryDatabase.path) + '--port', utils.testPort, + '--base-host', 'localhost:' + utils.testPort) .next(function(result) { - assertDomainNotExist(result); + assertDomainNotExist(result, 'test'); done(); }) .error(function(e) { @@ -622,7 +623,7 @@ suite('gcs-configure-text-options', function() { '--synonyms', path.join(__dirname, 'fixtures', 'synonyms.txt'), '--database-path', temporaryDatabase.path) .next(function(result) { - assertDomainNotExist(result); + assertDomainNotExist(result, 'companies'); done(); }) .error(function(e) { @@ -677,7 +678,7 @@ suite('gcs-configure-text-options', function() { '--print-synonyms', '--database-path', temporaryDatabase.path) .next(function(result) { - assertDomainNotExist(result); + assertDomainNotExist(result, 'companies'); done(); }) .error(function(e) { @@ -877,7 +878,7 @@ suite('gcs-index-documents', function() { '--domain-name', 'test', '--database-path', temporaryDatabase.path) .next(function(result) { - assertDomainNotExist(result); + assertDomainNotExist(result, 'test'); done(); }) .error(function(e) { @@ -1078,7 +1079,7 @@ suite('gcs-post-sdf', function() { '--domain-name', 'test', '--database-path', temporaryDatabase.path) .next(function(result) { - assertDomainNotExist(result); + assertDomainNotExist(result, 'test'); done(); }) .error(function(e) { -------------- next part -------------- HTML����������������������������... 下载