[Groonga-commit] groonga/gcs [master] Add tests for configurations related to tables

Back to archive index

SHIMODA Hiroshi null+****@clear*****
Mon Aug 13 16:59:12 JST 2012


SHIMODA Hiroshi	2012-08-13 16:59:12 +0900 (Mon, 13 Aug 2012)

  New Revision: f66f007469cbfc8cf123d925504f78824732803e
  https://github.com/groonga/gcs/commit/f66f007469cbfc8cf123d925504f78824732803e

  Log:
    Add tests for configurations related to tables

  Modified files:
    lib/database/domain.js
    lib/database/index-field.js
    test/database-domain.test.js
    test/database-index-field.test.js
    test/fixture/companies/ddl-custom-id.grn
    test/fixture/companies/ddl.grn

  Modified: lib/database/domain.js (+10 -2)
===================================================================
--- lib/database/domain.js    2012-08-13 16:31:55 +0900 (965ab4a)
+++ lib/database/domain.js    2012-08-13 16:59:12 +0900 (93e580d)
@@ -403,6 +403,9 @@ Domain.prototype = {
   },
 
   setConfiguration: function(key, value) {
+    if (!this.context)
+      throw new Error('no context');
+
     this.context.commandSync('load', {
       table: this.configurationsTableName,
       values: JSON.stringify([{
@@ -412,12 +415,14 @@ Domain.prototype = {
     });
   },
   getConfiguration: function(key) {
+    if (!this.context)
+      throw new Error('no context');
+
     var options = {
           table: this.configurationsTableName,
           limit: -1,
           offset: 0,
-          query: '_key=' + key,
-          output_columns: '_key,value'
+          filter: '_key == "' + key.replace(/"/g, '\\"') + '"'
         };
     var values = this.context.commandSync('select', options);
     values = nroonga.formatSelectResult(values);
@@ -428,6 +433,9 @@ Domain.prototype = {
     return JSON.parse(value);
   },
   deleteConfiguration: function(key) {
+    if (!this.context)
+      throw new Error('no context');
+
     this.context.commandSync('delete', {
       table: this.configurationsTableName,
       key: key

  Modified: lib/database/index-field.js (+1 -1)
===================================================================
--- lib/database/index-field.js    2012-08-13 16:31:55 +0900 (4161eb8)
+++ lib/database/index-field.js    2012-08-13 16:59:12 +0900 (e0cf55f)
@@ -270,7 +270,7 @@ IndexField.prototype = {
   },
   deleteSync: function() {
     // backup information for re-creation
-    this._type = type;
+    this._type = this.type;
     this._facetEnabled = this.facetEnabled;
     this._resultEnabled = this.resultEnabled;
     this._searchEnabled = this.searchEnabled;

  Modified: test/database-domain.test.js (+95 -0)
===================================================================
--- test/database-domain.test.js    2012-08-13 16:31:55 +0900 (a1ecbf7)
+++ test/database-domain.test.js    2012-08-13 16:59:12 +0900 (0e5cd49)
@@ -518,5 +518,100 @@ suite('database', function() {
         assert.deepEqual(actualDump.slice(-2), expectedDump);
       });
     });
+
+    suite('configuration operations', function() {
+      var temporaryDatabase;
+      var context;
+      var domain;
+
+      setup(function() {
+        temporaryDatabase = utils.createTemporaryDatabase();
+        context = temporaryDatabase.get();
+        domain = new Domain('companies', context);
+        domain.createSync();
+      });
+
+      teardown(function() {
+        domain = undefined;
+        temporaryDatabase.teardown();
+        temporaryDatabase = undefined;
+      });
+
+      test('setConfiguration', function() {
+        domain.setConfiguration('key1_string', 'abc');
+        domain.setConfiguration('key2_number', 123);
+        domain.setConfiguration('key3_hash', { value: true });
+
+        var dumpExpected =
+             'table_create ' + domain.tableName +  ' ' +
+               'TABLE_HASH_KEY ShortText\n' +
+             'table_create ' + domain.configurationsTableName +  ' ' +
+               'TABLE_HASH_KEY ShortText\n' +
+             'column_create ' + domain.configurationsTableName + ' ' +
+               'value COLUMN_SCALAR ShortText\n' +
+             'table_create ' + domain.termsTableName +  ' ' +
+               'TABLE_PAT_KEY|KEY_NORMALIZE ShortText ' +
+               '--default_tokenizer TokenBigram\n' +
+             'load --table ' + domain.configurationsTableName + '\n' +
+             '[\n' +
+             '["_key","value"],\n' +
+             '["key1_string","\\"abc\\""],\n' +
+             '["key2_number","123"],\n' +
+             '["key3_hash","{\\"value\\":true}"]\n' +
+             ']';
+        var dumpActual = context.commandSync('dump', {
+              tables: domain.configurationsTableName
+            });
+        assert.equal(dumpExpected, dumpActual);
+      });
+
+      test('getConfiguration', function() {
+        var expectedValues = {
+              string: 'abc',
+              number: 123,
+              hash: { value: true }
+            };
+        domain.setConfiguration('key1_string', expectedValues.string);
+        domain.setConfiguration('key2_number', expectedValues.number);
+        domain.setConfiguration('key3_hash', expectedValues.hash);
+
+        var actualValues = {
+              string: domain.getConfiguration('key1_string'),
+              number: domain.getConfiguration('key2_number'),
+              hash: domain.getConfiguration('key3_hash'),
+            };
+        assert.deepEqual(actualValues, expectedValues);
+      });
+
+      test('getConfiguration (undefined configuration)', function() {
+        assert.deepEqual(undefined, domain.getConfiguration('unknown'));
+      });
+
+      test('deleteConfiguration', function() {
+        domain.setConfiguration('key1_string', 'abc');
+        domain.setConfiguration('key2_number', 123);
+        domain.deleteConfiguration('key2_number');
+
+        var dumpExpected =
+             'table_create ' + domain.tableName +  ' ' +
+               'TABLE_HASH_KEY ShortText\n' +
+             'table_create ' + domain.configurationsTableName +  ' ' +
+               'TABLE_HASH_KEY ShortText\n' +
+             'column_create ' + domain.configurationsTableName + ' ' +
+               'value COLUMN_SCALAR ShortText\n' +
+             'table_create ' + domain.termsTableName +  ' ' +
+               'TABLE_PAT_KEY|KEY_NORMALIZE ShortText ' +
+               '--default_tokenizer TokenBigram\n' +
+             'load --table ' + domain.configurationsTableName + '\n' +
+             '[\n' +
+             '["_key","value"],\n' +
+             '["key1_string","\\"abc\\""]\n' +
+             ']';
+        var dumpActual = context.commandSync('dump', {
+              tables: domain.configurationsTableName
+            });
+        assert.equal(dumpExpected, dumpActual);
+      });
+    });
   });
 });

  Modified: test/database-index-field.test.js (+11 -3)
===================================================================
--- test/database-index-field.test.js    2012-08-13 16:31:55 +0900 (3abfe14)
+++ test/database-index-field.test.js    2012-08-13 16:59:12 +0900 (74e060c)
@@ -7,15 +7,23 @@ var IndexField = require('../lib/database/index-field').IndexField;
 
 suite('database', function() {
   suite('IndexField', function() {
+    var temporaryDatabase;
+    var context;
     var domain;
 
     setup(function() {
-      domain = new Domain('testdomain');
+      temporaryDatabase = utils.createTemporaryDatabase();
+      context = temporaryDatabase.get();
+      domain = new Domain('testdomain', context);
       domain.id = Domain.DEFAULT_ID;
+      domain.createSync();
     });
 
     teardown(function() {
       domain = undefined;
+      context = undefined;
+      temporaryDatabase.teardown();
+      temporaryDatabase = undefined;
     });
 
     test('lower case', function() {
@@ -108,7 +116,7 @@ suite('database', function() {
         resultEnabled: false,
         searchEnabled: true,
         state:         'Active',
-        options:       'Search Facet Result'
+        options:       'Search'
       });
     });
 
@@ -144,7 +152,7 @@ suite('database', function() {
         resultEnabled: false,
         searchEnabled: false,
         state:         'Active',
-        options:       'Search Facet Result'
+        options:       ''
       });
     });
 

  Modified: test/fixture/companies/ddl-custom-id.grn (+1 -1)
===================================================================
--- test/fixture/companies/ddl-custom-id.grn    2012-08-13 16:31:55 +0900 (ef0d957)
+++ test/fixture/companies/ddl-custom-id.grn    2012-08-13 16:59:12 +0900 (fec452d)
@@ -2,6 +2,7 @@ table_create companies_id0123_index_product TABLE_HASH_KEY ShortText
 table_create companies_id0123_index_age TABLE_HASH_KEY UInt32
 table_create companies_id0123_index_BigramTerms TABLE_PAT_KEY|KEY_NORMALIZE ShortText --default_tokenizer TokenBigram
 table_create companies_id0123_configurations TABLE_HASH_KEY ShortText
+column_create companies_id0123_configurations value COLUMN_SCALAR ShortText
 table_create companies_id0123 TABLE_HASH_KEY ShortText
 column_create companies_id0123 address COLUMN_SCALAR ShortText
 column_create companies_id0123 age COLUMN_SCALAR UInt32
@@ -15,4 +16,3 @@ column_create companies_id0123_index_BigramTerms companies_description COLUMN_IN
 column_create companies_id0123_index_BigramTerms companies_address COLUMN_INDEX|WITH_POSITION companies_id0123 address
 column_create companies_id0123_index_age companies_age COLUMN_INDEX|WITH_POSITION companies_id0123 age
 column_create companies_id0123_index_product companies_product COLUMN_INDEX|WITH_POSITION companies_id0123 product
-column_create companies_id0123_configurations value COLUMN_SCALAR ShortText

  Modified: test/fixture/companies/ddl.grn (+1 -1)
===================================================================
--- test/fixture/companies/ddl.grn    2012-08-13 16:31:55 +0900 (dead0e3)
+++ test/fixture/companies/ddl.grn    2012-08-13 16:59:12 +0900 (ddeff38)
@@ -2,6 +2,7 @@ table_create companies_00000000000000000000000000_index_product TABLE_HASH_KEY S
 table_create companies_00000000000000000000000000_index_age TABLE_HASH_KEY UInt32
 table_create companies_00000000000000000000000000_index_BigramTerms TABLE_PAT_KEY|KEY_NORMALIZE ShortText --default_tokenizer TokenBigram
 table_create companies_00000000000000000000000000_configurations TABLE_HASH_KEY ShortText
+column_create companies_00000000000000000000000000_configurations value COLUMN_SCALAR ShortText
 table_create companies_00000000000000000000000000 TABLE_HASH_KEY ShortText
 column_create companies_00000000000000000000000000 address COLUMN_SCALAR ShortText
 column_create companies_00000000000000000000000000 age COLUMN_SCALAR UInt32
@@ -15,4 +16,3 @@ column_create companies_00000000000000000000000000_index_BigramTerms companies_d
 column_create companies_00000000000000000000000000_index_BigramTerms companies_address COLUMN_INDEX|WITH_POSITION companies_00000000000000000000000000 address
 column_create companies_00000000000000000000000000_index_age companies_age COLUMN_INDEX|WITH_POSITION companies_00000000000000000000000000 age
 column_create companies_00000000000000000000000000_index_product companies_product COLUMN_INDEX|WITH_POSITION companies_00000000000000000000000000 product
-column_create companies_00000000000000000000000000_configurations value COLUMN_SCALAR ShortText
-------------- next part --------------
HTML����������������������������...
下載 



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