[Groonga-commit] groonga/gcs [master] Compare response of GCS server with ACS's one

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Nov 14 19:10:21 JST 2012


YUKI Hiroshi	2012-11-14 19:10:21 +0900 (Wed, 14 Nov 2012)

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

  Log:
    Compare response of GCS server with ACS's one

  Modified files:
    test/api-configuration.test.js

  Modified: test/api-configuration.test.js (+27 -9)
===================================================================
--- test/api-configuration.test.js    2012-11-14 18:52:38 +0900 (92c29d5)
+++ test/api-configuration.test.js    2012-11-14 19:10:21 +0900 (0462b52)
@@ -1320,19 +1320,22 @@ suite('Configuration API', function() {
   });
 
 /*
-  suite('compare response with ACS\'s one', function() {
+  suite('responses', function() {
     setup(commonSetup);
     teardown(commonTeardown);
 
     var scenariosDir = path.join(__dirname, 'scenarios/configuration');
+    var expectedResponsesBaseDir = path.join(__dirname, 'response/configuration');
     var scenarioFiles = fs.readdirSync(scenariosDir);
     scenarioFiles.filter(function(name) {
-      return /\.json$/i.test(name)
-    }).map(function(name) {
-      var file = path.resolve(scenariosDir, name);
+      return /\.json$/i.test(name);
+    }).map(function(scenarioFileName) {
+      var file = path.resolve(scenariosDir, scenarioFileName);
       var requests = fs.readFileSync(file);
       requests = JSON.parse(requests);
 
+      var scenarioName = scenarioFileName.replace(/\.json$/, '');
+
       var setupRequests = requests.filter(function(request) {
             return request.name.indexOf('setup:') == 0;
           });
@@ -1340,12 +1343,20 @@ suite('Configuration API', function() {
             return request.name.indexOf('teardown:') == 0;
           });
 
+      var fileNames = {};
       requests.forEach(function(request, index) {
+        var fileName = ScenarioRunner.toSafeName(request.name);
+        var count = 1;
+        while (fileName in fileNames) {
+          fileName = request.name + count++;
+        }
+        request.fileName = fileName + '.txt';
+
         if (request.name.indexOf('setup:') == 0 ||
             request.name.indexOf('teardown:') == 0)
           return;
 
-        test(name + ': ' + request.name, function(done) {
+        test(scenarioName + ': ' + request.name, function(done) {
           var scenario = {
                 requests: setupRequests
                             .concat([request])
@@ -1360,18 +1371,25 @@ suite('Configuration API', function() {
                 host: 'localhost',
                 port: utils.testPort
               });
-          runner.on('end', function(error, result) {
+          var expectedResponsesDir = path.join(expectedResponsesBaseDir, scenarioName);
+          runner.on('end', function(event) {
             try {
-              if (error)
-                throw new Error('unexpected error: ' + error);
               scenario.requests.forEach(function(request) {
-                console.log(request.result);
+                var file = path.join(expectedResponsesDir, request.fileName);
+                var expected = fs.readFileSync(file).toString();
+                assert.equal(expected, request.response);
               });
               done();
             } catch(error) {
               done(error);
             }
           });
+          runner.on('error:fatal', function(error) {
+            done(error);
+          });
+          runner.on('error:status_unknown', function(error) {
+            done(error);
+          });
           runner.run(scenario);
         });
       });
-------------- next part --------------
HTML����������������������������...
下载 



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