[Groonga-commit] groonga/gcs [master] Return all domains by DescribeDomains if no "DomainNames" option is specified

Back to archive index

null+****@clear***** null+****@clear*****
2012年 8月 3日 (金) 15:41:26 JST


SHIMODA Hiroshi	2012-08-03 15:41:26 +0900 (Fri, 03 Aug 2012)

  New Revision: 8ae9e1163eeb6ff7290c97af99837237c64ec34d
  https://github.com/groonga/gcs/commit/8ae9e1163eeb6ff7290c97af99837237c64ec34d

  Log:
    Return all domains by DescribeDomains if no "DomainNames" option is specified

  Modified files:
    lib/api/2011-02-01/configuration.js
    test/api-configuration.test.js

  Modified: lib/api/2011-02-01/configuration.js (+6 -4)
===================================================================
--- lib/api/2011-02-01/configuration.js    2012-08-03 15:32:25 +0900 (159c2eb)
+++ lib/api/2011-02-01/configuration.js    2012-08-03 15:41:26 +0900 (5fab23b)
@@ -154,9 +154,11 @@ handlers.DescribeDomains = function(context, request, response) {
     var domainNames = keys.sort().map(function(key) {
           return request.query[key];
         });
-    var domains = domainNames.map(function(name) {
-          return new Domain(name, context);
-        });
+    var domains = domainNames.length ?
+                    domainNames.map(function(name) {
+                      return new Domain(name, context);
+                    }) :
+                    Domain.getAll(context) ;
     response.contentType('application/xml');
     response.send(createDescribeDomainsResponse({
       domains: domains,
@@ -196,7 +198,7 @@ function createIndexFieldOptionStatus(options) {
 
 function createIndexFieldStatus(options) {
   var indexFieldStatus = xmlbuilder.create();
-  indexFieldStatus.begin('IndexField', { version: '1.0' })
+  indexFieldStatus.begin(options.element || 'IndexField', { version: '1.0' })
     .element('Options')
       .element('IndexFieldName').text(options.field.name).up()
       .element('IndexFieldType').text(options.field.type).up()

  Modified: test/api-configuration.test.js (+47 -13)
===================================================================
--- test/api-configuration.test.js    2012-08-03 15:32:25 +0900 (2a0d9cd)
+++ test/api-configuration.test.js    2012-08-03 15:41:26 +0900 (2dcd5d8)
@@ -330,7 +330,52 @@ suite('Configuration API', function() {
       });
   });
 
-  test('Get, Action=DescribeDomains', function(done) {
+  function getActualDescribedDomains(response) {
+    var actualDomains = response.body.DescribeDomainsResponse
+                                     .DescribeDomainsResult
+                                     .DomainStatusList
+                                     .member;
+    var domains = [];
+    for (var i in actualDomains) {
+      if (actualDomains.hasOwnProperty(i))
+        domains.push(actualDomains[i].DomainName);
+    }
+    return domains;
+  }
+
+  test('Get, Action=DescribeDomains (all domains)', function(done) {
+    var domain;
+    utils
+      .get('/?DomainName=domain3&Action=CreateDomain&Version=2011-02-01', {
+        'Host': 'cloudsearch.localhost'
+      })
+      .get('/?DomainName=domain1&Action=CreateDomain&Version=2011-02-01', {
+        'Host': 'cloudsearch.localhost'
+      })
+      .get('/?DomainName=domain2&Action=CreateDomain&Version=2011-02-01', {
+        'Host': 'cloudsearch.localhost'
+      })
+      .get('/?Action=DescribeDomains&Version=2011-02-01', {
+        'Host': 'cloudsearch.localhost'
+      })
+      .next(function(response) {
+        response = toParsedResponse(response);
+        var expectedDomains = ['domain1', 'domain2', 'domain3'];
+        assert.deepEqual(response.pattern,
+                         { statusCode: 200,
+                           body: PATTERN_DescribeDomainsResponse(expectedDomains) });
+
+        var actualDomains = getActualDescribedDomains(response);
+        assert.deepEqual(actualDomains, expectedDomains);
+
+        done();
+      })
+      .error(function(error) {
+        done(error);
+      });
+  });
+
+  test('Get, Action=DescribeDomains (specified domains)', function(done) {
     var domain;
     utils
       .get('/?DomainName=domain3&Action=CreateDomain&Version=2011-02-01', {
@@ -354,18 +399,7 @@ suite('Configuration API', function() {
                          { statusCode: 200,
                            body: PATTERN_DescribeDomainsResponse(expectedDomains) });
 
-        var actualDomains = response.body.DescribeDomainsResponse
-                                         .DescribeDomainsResult
-                                         .DomainStatusList
-                                         .member;
-        actualDomains = (function() {
-          var domains = [];
-          for (var i in actualDomains) {
-            if (actualDomains.hasOwnProperty(i))
-              domains.push(actualDomains[i].DomainName);
-          }
-          return domains;
-        })();
+        var actualDomains = getActualDescribedDomains(response);
         assert.deepEqual(actualDomains, expectedDomains);
 
         done();
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
下載 



Groonga-commit メーリングリストの案内
Back to archive index