[Groonga-commit] droonga/express-droonga at aa0c336 [master] test: support /d/load with GET

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Apr 30 17:57:03 JST 2014


Kouhei Sutou	2014-04-30 17:57:03 +0900 (Wed, 30 Apr 2014)

  New Revision: aa0c33626c0450f73c14f9575ba8a842935b9872
  https://github.com/droonga/express-droonga/commit/aa0c33626c0450f73c14f9575ba8a842935b9872

  Message:
    test: support /d/load with GET

  Modified files:
    lib/adapter/api/groonga/index.js
    test/adapter/api/groonga/load.test.js
    test/test-utils.js

  Modified: lib/adapter/api/groonga/index.js (+11 -2)
===================================================================
--- lib/adapter/api/groonga/index.js    2014-04-29 00:50:36 +0900 (e1a1244)
+++ lib/adapter/api/groonga/index.js    2014-04-30 17:57:03 +0900 (8bc9b45)
@@ -12,9 +12,18 @@ function normalizeCommandName(commandName) {
   return commandName;
 }
 
-function handleGetRequest(request, connection) {
+function handleGetRequest(request, connection, response) {
   var commandName = normalizeCommandName(request.params.commandName);
-  connection.emit(commandName, request.query);
+  if (commandName == 'load') {
+    var loader = new Loader(request, response, connection, this.logger);
+    loader.run();
+    if (request.query.values) {
+      request.emit('data', request.query.values);
+    }
+    request.emit('end');
+  } else {
+    connection.emit(commandName, request.query);
+  }
 }
 
 function handlePostRequest(request, connection, response) {

  Modified: test/adapter/api/groonga/load.test.js (+83 -0)
===================================================================
--- test/adapter/api/groonga/load.test.js    2014-04-29 00:50:36 +0900 (615bdfc)
+++ test/adapter/api/groonga/load.test.js    2014-04-30 17:57:03 +0900 (e8a6ba0)
@@ -307,6 +307,89 @@ suite('adapter/api/groonga: load', function() {
           });
       });
     });
+
+    suite('GET', function() {
+      test('object style', function(done) {
+        var requestBody;
+        backend.reserveResponse(function(requestPacket) {
+          requestBody = requestPacket[2].body;
+          return utils.createReplyPacket(requestPacket, groongaUtils.successMessage);
+        });
+        var values = [
+          {
+            _key: 'alice',
+            name: 'Alice',
+            age: 20
+          }
+        ];
+        var path = {
+          pathname: '/d/load',
+          query: {
+            table: 'Users',
+            values: JSON.stringify(values)
+          }
+        };
+        utils.get(path)
+          .next(function(response) {
+            assert.deepEqual(requestBody,
+                             {
+                               table: 'Users',
+                               key: 'alice',
+                               values: {
+                                 name: 'Alice',
+                                 age: 20
+                               }
+                             });
+            done();
+          })
+          .error(function(error) {
+            done(error);
+          });
+      });
+
+      test('array style', function(done) {
+        var requestBody;
+        backend.reserveResponse(function(requestPacket) {
+          requestBody = requestPacket[2].body;
+          return utils.createReplyPacket(requestPacket, groongaUtils.successMessage);
+        });
+        var values = [
+          [
+            '_key',
+            'name',
+            'age'
+          ],
+          [
+            'alice',
+            'Alice',
+            20
+          ]
+        ];
+        var path = {
+          pathname: '/d/load',
+          query: {
+            table: 'Users',
+            values: JSON.stringify(values)
+          }
+        };
+        utils.get(path)
+          .next(function(response) {
+            assert.deepEqual(requestBody,
+                             {
+                               table: 'Users',
+                               key: 'alice',
+                               values: {
+                                 name: 'Alice',
+                                 age: 20
+                               }
+                             });
+            done();
+          })
+          .error(function(error) {
+            done(error);
+          });
+      });
+    });
   });
 
   suite('failure', function() {

  Modified: test/test-utils.js (+9 -0)
===================================================================
--- test/test-utils.js    2014-04-29 00:50:36 +0900 (d2077e7)
+++ test/test-utils.js    2014-04-30 17:57:03 +0900 (3d24a0d)
@@ -7,6 +7,7 @@ var http = require('http');
 var Deferred = require('jsdeferred').Deferred;
 var client = require('socket.io-client');
 var express = require('express');
+var url = require('url');
 
 var FluentReceiver = require('../lib/droonga-protocol/receiver').FluentReceiver;
 exports.FluentReceiver = FluentReceiver;
@@ -75,9 +76,17 @@ function setupServer(handlerOrServer) {
 exports.setupServer = setupServer;
 Deferred.register('setupServer', setupServer);
 
+function normalizePath(path) {
+  if (typeof path != 'string') {
+    path = url.format(path);
+  }
+  return path;
+}
+
 function sendRequest(method, path, postData, headers) {
   var deferred = new Deferred();
 
+  path = normalizePath(path);
   var options = {
         host: '127.0.0.1',
         port: testServerPort,
-------------- next part --------------
HTML����������������������������...
Download 



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