[Groonga-commit] groonga/gcs [master] Separate test of synonym to database and API layers

Back to archive index

null+****@clear***** null+****@clear*****
2012年 8月 2日 (木) 15:31:03 JST


SHIMODA Hiroshi	2012-08-02 15:31:03 +0900 (Thu, 02 Aug 2012)

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

  Log:
    Separate test of synonym to database and API layers

  Modified files:
    lib/database/domain.js
    test/api-configuration.test.js
    test/database-domain.test.js

  Modified: lib/database/domain.js (+6 -3)
===================================================================
--- lib/database/domain.js    2012-08-02 15:20:52 +0900 (af7e3cc)
+++ lib/database/domain.js    2012-08-02 15:31:03 +0900 (14e3206)
@@ -229,6 +229,7 @@ Domain.prototype = {
       default_tokenizer: nroonga.TokenBigram
     });
   },
+
   deleteSync: function() {
     if (!this.context)
       throw new Error('no context');
@@ -240,11 +241,13 @@ Domain.prototype = {
       name: this.termsTableName
     });
   },
+
   reindexSync: function() {
     this.indexFields.forEach(function(field) {
       field.reindexSync();
     });
   },
+
   updateSynonymsSync: function(synonymOptions) {
     if (!this.context)
       throw new Error('no context');
@@ -279,13 +282,13 @@ Domain.prototype = {
       values: JSON.stringify(load)
     });
   },
+
   isSynonymTableAvailableSync: function() {
     var results = this.context.commandSync('table_list');
     var tables = nroonga.formatResults(results);
-    var self = this;
     return tables.some(function(table) {
-      return table.name === self.synonymTableName;
-    });
+      return table.name === this.synonymTableName;
+    }, this);
   },
 
   exists: function() {

  Modified: test/api-configuration.test.js (+2 -13)
===================================================================
--- test/api-configuration.test.js    2012-08-02 15:20:52 +0900 (acd49ca)
+++ test/api-configuration.test.js    2012-08-02 15:31:03 +0900 (8eff977)
@@ -577,19 +577,8 @@ suite('Configuration API', function() {
         'Host': 'cloudsearch.localhost'
       })
       .next(function(response) {
-        var dumpExpected =
-             'table_create companies_00000000000000000000000000_synonyms TABLE_HASH_KEY|KEY_NORMALIZE ShortText\n' +
-             'column_create companies_00000000000000000000000000_synonyms synonyms COLUMN_VECTOR ShortText\n' +
-             'load --table companies_00000000000000000000000000_synonyms\n' +
-             '[\n' +
-             '["_key","synonyms"],\n' +
-             '["tokio",["tokyo"]],\n' +
-             '["dekkaido",["hokkaido"]]\n' +
-             ']';
-        var dumpActual = context.commandSync('dump', {
-          tables: 'companies_00000000000000000000000000_synonyms'
-        });
-        assert.equal(dumpExpected, dumpActual);
+        var domain = new Domain('companies', context);
+        assert.isTrue(domain.isSynonymTableAvailableSync());
 
         response = toParsedResponse(response);
         assert.deepEqual(response.pattern,

  Modified: test/database-domain.test.js (+27 -0)
===================================================================
--- test/database-domain.test.js    2012-08-02 15:20:52 +0900 (e418be7)
+++ test/database-domain.test.js    2012-08-02 15:31:03 +0900 (abb8c7e)
@@ -303,6 +303,33 @@ suite('database', function() {
         var expectedDump = '';
         assert.equal(dump, expectedDump);
       });
+
+      test('updateSynonymsSync', function() {
+        var domain = new Domain('companies', context);
+        assert.isFalse(domain.isSynonymTableAvailableSync());
+
+        domain.updateSynonymsSync(
+          synonyms: {
+            tokio: ['tokyo'],
+            dekkaido: 'hokkaido'
+          }
+        });
+        assert.isTrue(domain.isSynonymTableAvailableSync());
+
+        var dumpExpected =
+             'table_create ' + domain.synonymTableName + ' TABLE_HASH_KEY|KEY_NORMALIZE ShortText\n' +
+             'column_create ' + domain.synonymTableName + ' synonyms COLUMN_VECTOR ShortText\n' +
+             'load --table ' + domain.synonymTableName + '\n' +
+             '[\n' +
+             '["_key","synonyms"],\n' +
+             '["tokio",["tokyo"]],\n' +
+             '["dekkaido",["hokkaido"]]\n' +
+             ']';
+        var dumpActual = context.commandSync('dump', {
+              tables: domain.synonymTableName
+            });
+        assert.equal(dumpExpected, dumpActual);
+      });
     });
   });
 });
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
Download 



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