Kouhei Sutou
null+****@clear*****
Fri Apr 25 12:55:48 JST 2014
Kouhei Sutou 2014-04-25 12:55:48 +0900 (Fri, 25 Apr 2014) New Revision: 976dc55017883b6e658f0ebea5aacc77bcda2435 https://github.com/droonga/express-droonga/commit/976dc55017883b6e658f0ebea5aacc77bcda2435 Message: groonga load test: add simple success cases Added files: test/adapter/api/groonga.test.js Added: test/adapter/api/groonga.test.js (+100 -0) 100644 =================================================================== --- /dev/null +++ test/adapter/api/groonga.test.js 2014-04-25 12:55:48 +0900 (cbc515d) @@ -0,0 +1,100 @@ +var assert = require('chai').assert; +var nodemock = require('nodemock'); +var Deferred = require('jsdeferred').Deferred; + +var utils = require('../../test-utils'); + +var express = require('express'); +var httpAdapter = require('../../../lib/adapter/http'); +var groongaAPI = require('../../../lib/adapter/api/groonga'); + +suite('adapter/api: Groonga', function() { + suite('load', function() { + var connection; + var application; + var server; + var backend; + + setup(function(done) { + utils.setupApplication() + .next(function(result) { + backend = result.backend; + server = result.server; + connection = result.connection; + application = result.application; + httpAdapter.register(application, { + prefix: '', + connection: connection, + plugins: [groongaAPI] + }); + done(); + }); + }); + + teardown(function() { + utils.teardownApplication({ + backend: backend, + server: server, + connection: connection + }); + }); + + function pushSuccessResponse() { + backend.reserveResponse(function(request) { + return utils.createReplyPacket(request, + { + statusCode: 200, + body: true + }); + }); + } + + suite('success', function() { + suite('key only', function() { + test('one', function(done) { + pushSuccessResponse(); + var body = [ + { + _key: 'alice' + } + ] + utils.post('/d/load?table=Users', JSON.stringify(body)) + .next(function(response) { + try { + assert.deepEqual([1], JSON.parse(response.body)[1]); + done(); + } catch (error) { + done(error); + } + }); + }); + + test('multiple', function(done) { + pushSuccessResponse(); + pushSuccessResponse(); + var body = [ + { + _key: 'alice' + }, + { + _key: 'bob' + } + ] + utils.post('/d/load?table=Users', JSON.stringify(body)) + .next(function(response) { + try { + assert.deepEqual([2], JSON.parse(response.body)[1]); + done(); + } catch (error) { + done(error); + } + }); + }); + }); + }); + + suite('failure', function() { + }); + }); +}); + -------------- next part -------------- HTML����������������������������...Download