[Groonga-commit] groonga/gcs [master] test: Add a test case for search

アーカイブの一覧に戻る

null+****@clear***** null+****@clear*****
2012年 7月 5日 (木) 17:25:20 JST


Yoji SHIDARA	2012-07-05 17:25:20 +0900 (Thu, 05 Jul 2012)

  New Revision: 7a55ae40218ef7852d140fd935d8cac4b4005204
  https://github.com/groonga/gcs/commit/7a55ae40218ef7852d140fd935d8cac4b4005204

  Log:
    test: Add a test case for search

  Modified files:
    test/search.test.js

  Modified: test/search.test.js (+108 -45)
===================================================================
--- test/search.test.js    2012-07-05 17:08:16 +0900 (163238b)
+++ test/search.test.js    2012-07-05 17:25:20 +0900 (4922972)
@@ -4,9 +4,13 @@ var http = require('http');
 var fs = require('fs');
 
 var temporaryDatabase;
+var database;
 
 suiteSetup(function() {
   temporaryDatabase = utils.createTemporaryDatabase();
+  database = temporaryDatabase.get();
+  utils.loadDumpFile(database, __dirname + '/fixture/companies/ddl.grn');
+  utils.loadDumpFile(database, __dirname + '/fixture/companies/data.grn');
 });
 
 suiteTeardown(function() {
@@ -15,13 +19,9 @@ suiteTeardown(function() {
 });
 
 suite('Search API', function() {
-  var database;
   var server;
 
   setup(function() {
-    database = temporaryDatabase.get();
-    utils.loadDumpFile(database, __dirname + '/fixture/companies/ddl.grn');
-    utils.loadDumpFile(database, __dirname + '/fixture/companies/data.grn');
     server = utils.setupServer(database);
   });
 
@@ -29,32 +29,86 @@ suite('Search API', function() {
     server.close();
   });
 
-  test('GET /2011-02-01/search', function(done) {
-    var options = {
-      host: utils.testHost,
-      port: utils.testPort,
-      path: '/2011-02-01/search?q=Hongo',
-      headers: {
-        Host: 'search-companies-00000000000000000000000000.localhost'
-      }
-    };
-    http.get(options, function(response) {
-      assert.equal(response.statusCode, 200);
-      var body = '';
-      response.on('data', function(data) {
-        body += data;
-      });
-      response.on('end', function() {
-        var actual = JSON.parse(body);
-        assert.operator(actual.info['time-ms'], '>=', 0, 'time-ms is ok');
-        actual.info['time-ms'] = 0; // always set 0 for test
-        var expected = { // FIXME
-          rank: '-text_relevance',
-          'match-expr': '',
-          hits: {
-            found: 1,
-            start: 0,
-            hit: [{
+  function testSearch(path, host, callback) {
+    test('GET ' + path, function(done) {
+      var options = {
+        host: utils.testHost,
+        port: utils.testPort,
+        path: path,
+        headers: {Host: host}
+      };
+      http.get(options, function(response) {
+        var body = '';
+        response.on('data', function(data) {
+          body += data;
+        });
+        response.on('end', function() {
+          callback(response, body, done);
+        });
+      } );
+    });
+  }
+
+  testSearch('/2011-02-01/search?q=Hongo',
+             'search-companies-00000000000000000000000000.localhost',
+    function(response, body, done) {
+      var actual = JSON.parse(body);
+      assert.operator(actual.info['time-ms'], '>=', 0, 'time-ms is ok');
+      actual.info['time-ms'] = 0; // always set 0 for test
+      var expected = { // FIXME
+        rank: '-text_relevance',
+        'match-expr': '',
+        hits: {
+          found: 1,
+          start: 0,
+          hit: [{
+            id: 'id3',
+            data: {
+              _id: [3],
+              _key: ['id3'],
+              address: ['Hongo, Tokyo, Japan'],
+              description: [''],
+              email_address: ['info****@clear*****'],
+              name: ['ClearCode Inc.']
+            }
+          }]
+        },
+        info: {
+          rid: '000000000000000000000000000000000000000000000000000000000000000',
+          'time-ms': 0, // always 0
+          'cpu-time-ms': 0
+        }
+      };
+      assert.deepEqual(actual, expected);
+      done();
+    }
+  );
+
+  testSearch('/2011-02-01/search?q=Tokyo',
+             'search-companies-00000000000000000000000000.localhost',
+    function(response, body, done) {
+      var actual = JSON.parse(body);
+      assert.operator(actual.info['time-ms'], '>=', 0, 'time-ms is ok');
+      actual.info['time-ms'] = 0; // always set 0 for test
+      var expected = {
+        rank: '-text_relevance',
+        'match-expr': '',
+        hits: {
+          found: 3,
+          start: 0,
+          hit: [
+            {
+              id: 'id1',
+              data: {
+                _id: [1],
+                _key: ['id1'],
+                address: ['Shibuya, Tokyo, Japan'],
+                description: [''],
+                email_address: ['info****@razil*****'],
+                name: ['Brazil']
+              }
+            },
+            {
               id: 'id3',
               data: {
                 _id: [3],
@@ -64,19 +118,28 @@ suite('Search API', function() {
                 email_address: ['info****@clear*****'],
                 name: ['ClearCode Inc.']
               }
-            }]
-          },
-          info: {
-            rid: '000000000000000000000000000000000000000000000000000000000000000',
-            'time-ms': 0, // always 0
-            'cpu-time-ms': 0
-          }
-        };
-        assert.deepEqual(actual, expected);
-        done();
-      });
-    }).on('error', function(error) {
-      throw error;
-    });
-  });
+            },
+            {
+              id: 'id9',
+              data: {
+                _id: [9],
+                _key: ['id9'],
+                address: ['Tokyo, Japan'],
+                description: [''],
+                email_address: [''],
+                name: ['Umbrella Corporation']
+              }
+            }
+          ]
+        },
+        info: {
+          rid: '000000000000000000000000000000000000000000000000000000000000000',
+          'time-ms': 0, // always 0
+          'cpu-time-ms': 0
+        }
+      };
+      assert.deepEqual(actual, expected);
+      done();
+    }
+  );
 });
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
ダウンロード 



Groonga-commit メーリングリストの案内
アーカイブの一覧に戻る