[Groonga-commit] droonga/express-droonga at 5fc9ffb [master] Test the response-cache middleware

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Mar 20 17:45:04 JST 2014


YUKI Hiroshi	2014-03-20 17:45:04 +0900 (Thu, 20 Mar 2014)

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

  Message:
    Test the response-cache middleware

  Added files:
    test/response-cache/middleware.test.js
  Modified files:
    package.json

  Modified: package.json (+2 -1)
===================================================================
--- package.json    2014-03-20 17:44:35 +0900 (1ccb62a)
+++ package.json    2014-03-20 17:45:04 +0900 (f667924)
@@ -35,7 +35,8 @@
     "jsdeferred": "*",
     "mocha": "*",
     "nodemock": "*",
-    "socket.io-client": "*"
+    "socket.io-client": "*",
+    "supertest": "*"
   },
   "scripts": {
     "start": "./application.js",

  Added: test/response-cache/middleware.test.js (+50 -0) 100644
===================================================================
--- /dev/null
+++ test/response-cache/middleware.test.js    2014-03-20 17:45:04 +0900 (899047e)
@@ -0,0 +1,50 @@
+var client = require('supertest');
+var express = require('express');
+
+var assert = require('chai').assert;
+
+var middleware = require('../../lib/response-cache');
+
+suite('Response Cache Middleware', function() {
+  var application;
+  setup(function() {
+    application = express();
+    application.use(middleware({
+      rules: [
+        { regex: /cached/ }
+      ]
+    }));
+    application.get('/cached/success', function(request, response){
+      response.send(200, 'OK');
+    });
+    application.get('/cached/fail', function(request, response){
+      response.send(400, 'NG');
+    });
+    application.get('/fresh', function(request, response){
+      response.send(200, 'OK');
+    });
+    application.listen(3000, '0.0.0.0');
+  });
+
+  test('cached', function(done) {
+    client(application)
+      .get('/cached/success')
+      .expect(200)
+      .end(function(error, response){
+        if (error)
+          return done(error);
+
+        client(application)
+          .get('/cached/success')
+          .expect(200)
+          .expect('X-Droonga-Cached', 'yes')
+          .end(function(error, response){
+            if (error)
+              done(error);
+            else
+              done();
+          });
+      });
+  });
+});
+
-------------- next part --------------
HTML����������������������������...
Download 



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