[Groonga-commit] groonga/gcs [master] Add tests for field options specified via the configurations API

Back to archive index

SHIMODA Hiroshi null+****@clear*****
Mon Aug 13 17:29:50 JST 2012


SHIMODA Hiroshi	2012-08-13 17:29:50 +0900 (Mon, 13 Aug 2012)

  New Revision: 0ebf012b7164c9ec41b341712cbef6b2f9bb8434
  https://github.com/groonga/gcs/commit/0ebf012b7164c9ec41b341712cbef6b2f9bb8434

  Log:
    Add tests for field options specified via the configurations API

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

  Modified: lib/api/2011-02-01/configuration.js (+3 -3)
===================================================================
--- lib/api/2011-02-01/configuration.js    2012-08-13 17:21:36 +0900 (e74a1ae)
+++ lib/api/2011-02-01/configuration.js    2012-08-13 17:29:50 +0900 (57a6c29)
@@ -242,7 +242,7 @@ handlers.DefineIndexField = function(context, request, response) {
                          request.query['LiteralOptions.FacetEnabled'] :
                          null ;
     if (facetEnabled !== null)
-      field.facetEnabled = facetEnabled;
+      field.facetEnabled = facetEnabled.toLowerCase() == 'true';
 
     var resultEnabled = fieldType == 'text' ?
                           request.query['TextOptions.ResultEnabled'] :
@@ -250,13 +250,13 @@ handlers.DefineIndexField = function(context, request, response) {
                           request.query['LiteralOptions.ResultEnabled'] :
                           null ;
     if (resultEnabled !== null)
-      field.resultEnabled = resultEnabled;
+      field.resultEnabled = resultEnabled.toLowerCase() == 'true';
 
     var searchEnabled = fieldType == 'literal' ?
                           request.query['LiteralOptions.SearchEnabled'] :
                           null ;
     if (searchEnabled !== null)
-      field.searchEnabled = searchEnabled;
+      field.searchEnabled = searchEnabled.toLowerCase() == 'true';
 
     if (!field.exists()) {
       field.type = fieldType;

  Modified: test/api-configuration.test.js (+90 -13)
===================================================================
--- test/api-configuration.test.js    2012-08-13 17:21:36 +0900 (770a566)
+++ test/api-configuration.test.js    2012-08-13 17:29:50 +0900 (0a3a07f)
@@ -422,7 +422,7 @@ suite('Configuration API', function() {
       });
   });
 
-  test('Get, Action=DefineIndexField (text)', function(done) {
+  test('Get, Action=DefineIndexField (text, without options)', function(done) {
     utils
       .get('/?DomainName=companies&Action=CreateDomain&Version=2011-02-01', {
         'Host': 'cloudsearch.localhost'
@@ -440,12 +440,49 @@ suite('Configuration API', function() {
                          { statusCode: 200,
                            body: PATTERN_DefineIndexFieldResponse_Text });
         var expectedOptions = {
-              IndexFieldName: field.name,
-              IndexFieldType: field.type,
+              IndexFieldName: 'name',
+              IndexFieldType: 'text',
               TextOptions: {
                 DefaultValue: {},
-                FacetEnabled: String(field.facetEnabled),
-                ResultEnabled: String(field.resultEnabled)
+                FacetEnabled: false,
+                ResultEnabled: false
+              }
+            };
+        var options = response.body.DefineIndexFieldResponse.DefineIndexFieldResult.IndexField.Options;
+        assert.deepEqual(options, expectedOptions);
+
+        done();
+      })
+      .error(function(error) {
+        done(error);
+      });
+  });
+
+  test('Get, Action=DefineIndexField (text, with options)', function(done) {
+    utils
+      .get('/?DomainName=companies&Action=CreateDomain&Version=2011-02-01', {
+        'Host': 'cloudsearch.localhost'
+      })
+      .get('/?DomainName=companies&IndexField.IndexFieldName=name&' +
+           'IndexField.IndexFieldType=text&' +
+           'TextOptions.FacetEnabled=true&TextOptions.ResultEnabled=true&' +
+           'Action=DefineIndexField&Version=2011-02-01')
+      .next(function(response) {
+        var domain = new Domain('companies', context);
+        var field = domain.getIndexField('name');
+        assert.isTrue(field.exists());
+
+        response = toParsedResponse(response);
+        assert.deepEqual(response.pattern,
+                         { statusCode: 200,
+                           body: PATTERN_DefineIndexFieldResponse_Text });
+        var expectedOptions = {
+              IndexFieldName: 'name',
+              IndexFieldType: 'text',
+              TextOptions: {
+                DefaultValue: {},
+                FacetEnabled: true,
+                ResultEnabled: true
               }
             };
         var options = response.body.DefineIndexFieldResponse.DefineIndexFieldResult.IndexField.Options;
@@ -476,8 +513,8 @@ suite('Configuration API', function() {
                          { statusCode: 200,
                            body: PATTERN_DefineIndexFieldResponse_UInt });
         var expectedOptions = {
-              IndexFieldName: field.name,
-              IndexFieldType: field.type,
+              IndexFieldName: 'age',
+              IndexFieldType: 'uint',
               UIntOptions: {
                 DefaultValue: {}
               }
@@ -492,13 +529,53 @@ suite('Configuration API', function() {
       });
   });
 
-  test('Get, Action=DefineIndexField (literal)', function(done) {
+  test('Get, Action=DefineIndexField (literal, without options)', function(done) {
+    utils
+      .get('/?DomainName=companies&Action=CreateDomain&Version=2011-02-01', {
+        'Host': 'cloudsearch.localhost'
+      })
+      .get('/?DomainName=companies&IndexField.IndexFieldName=product&' +
+           'IndexField.IndexFieldType=literal&' +
+           'Action=DefineIndexField&Version=2011-02-01')
+      .next(function(response) {
+        var domain = new Domain('companies', context);
+        var field = domain.getIndexField('product');
+        assert.isTrue(field.exists());
+
+        response = toParsedResponse(response);
+        assert.deepEqual(response.pattern,
+                         { statusCode: 200,
+                           body: PATTERN_DefineIndexFieldResponse_Literal });
+        var expectedOptions = {
+              IndexFieldName: 'product',
+              IndexFieldType: 'literal',
+              LiteralOptions: {
+                DefaultValue: {},
+                FacetEnabled: false,
+                ResultEnabled: false,
+                SearchEnabled: false
+              }
+            };
+        var options = response.body.DefineIndexFieldResponse.DefineIndexFieldResult.IndexField.Options;
+        assert.deepEqual(options, expectedOptions);
+
+        done();
+      })
+      .error(function(error) {
+        done(error);
+      });
+  });
+
+  test('Get, Action=DefineIndexField (literal, with options)', function(done) {
     utils
       .get('/?DomainName=companies&Action=CreateDomain&Version=2011-02-01', {
         'Host': 'cloudsearch.localhost'
       })
       .get('/?DomainName=companies&IndexField.IndexFieldName=product&' +
            'IndexField.IndexFieldType=literal&' +
+           'LiteralOptions.SearchEnabled=true&' +
+           'LiteralOptions.FacetEnabled=true&' +
+           'LiteralOptions.ResultEnabled=true&' +
            'Action=DefineIndexField&Version=2011-02-01')
       .next(function(response) {
         var domain = new Domain('companies', context);
@@ -510,13 +587,13 @@ suite('Configuration API', function() {
                          { statusCode: 200,
                            body: PATTERN_DefineIndexFieldResponse_Literal });
         var expectedOptions = {
-              IndexFieldName: field.name,
-              IndexFieldType: field.type,
+              IndexFieldName: 'product',
+              IndexFieldType: 'literal',
               LiteralOptions: {
                 DefaultValue: {},
-                FacetEnabled: String(field.facetEnabled),
-                ResultEnabled: String(field.resultEnabled),
-                SearchEnabled: String(field.searchEnabled)
+                FacetEnabled: true,
+                ResultEnabled: true,
+                SearchEnabled: true
               }
             };
         var options = response.body.DefineIndexFieldResponse.DefineIndexFieldResult.IndexField.Options;
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index