null+****@clear*****
null+****@clear*****
2012年 6月 21日 (木) 17:00:50 JST
SHIMODA Hiroshi 2012-06-21 17:00:50 +0900 (Thu, 21 Jun 2012) New Revision: ae83caaaa22e97e90d51e9e3736665cc9215a509 https://github.com/groonga/gcs/commit/ae83caaaa22e97e90d51e9e3736665cc9215a509 Log: Assert response body of configuration API for actions: CreateDomain and DefineIndexField Modified files: test/api-configuration.test.js test/test-utils.js Modified: test/api-configuration.test.js (+62 -5) =================================================================== --- test/api-configuration.test.js 2012-06-21 16:48:38 +0900 (355919a) +++ test/api-configuration.test.js 2012-06-21 17:00:50 +0900 (8f7e136) @@ -24,6 +24,9 @@ function createCommonErrorResponse(errorCode, message) { '</Response>'; } +var XMLNS = 'http://cloudsearch.amazonaws.com/doc/2011-02-01'; +var FAKE_DOMAIN_ID = 'example'; + suite('Configuration API', function() { var database; var server; @@ -40,13 +43,38 @@ suite('Configuration API', function() { test('Get, Action=CreateDomain', function(done) { var path = '/?DomainName=companies&Action=CreateDomain&Version=2011-02-01'; - utils.get(path) + utils.get(path, { + 'Host': 'cloudsearch.localhost' + }) .next(function(response) { var expected = { statusCode: 200, - body: '' + body: '<?xml version="1.0"?>\n' + + '<CreateDomainResponse xmlns="' + XMLNS + '">' + + '<CreateDomainResult>' + + '<DomainStatus>' + + '<Created>true</Created>' + + '<Deleted>false</Deleted>' + + '<DocService>' + + '<Endpoint>http://doc-companies-example.localhost/2011-02-01/documents</Endpoint>' + + '</DocService>' + + '<DomainId>' + FAKE_DOMAIN_ID + '</DomainId>' + + '<DomainName>companies</DomainName>' + + '<NumSearchableDocs>0</NumSearchableDocs>' + + '<RequiresIndexDocuments>false</RequiresIndexDocuments>' + + '<SearchInstanceCount>0</SearchInstanceCount>' + + '<SearchPartitionCount>0</SearchPartitionCount>' + + '<SearchService>' + + '<Endpoint>http://search-companies-example.localhost/2011-02-01/search</Endpoint>' + + '</SearchService>' + + '</DomainStatus>'; + '</CreateDomainResult>' + + '<ResponseMetadata>' + + '<RequestId></RequestId>' + + '</ResponseMetadata>' + + '</CreateDomainResponse>' }; -// assert.deepEqual(response, expected); + assert.deepEqual(response, expected); var dump = database.commandSync('dump', { tables: 'companies' @@ -75,9 +103,38 @@ suite('Configuration API', function() { .next(function(response) { var expected = { statusCode: 200, - body: '' + body: '<?xml version="1.0"?>\n' + + '<DefineIndexFieldResponse xmlns="' + XMLNS + '">' + + '<DefineIndexFieldResult>' + + '<IndexField>' + + '<Options>' + + '<IndexFieldName>name</IndexFieldName>' + + '<IndexFieldType>text</IndexFieldType>' + + '<TextOptions>' + + '<DefaultValue/>' + + '<FacetEnabled>false</FacetEnabled>' + + '<ResultEnabled>true</ResultEnabled>' + + '</TextOptions>' + + '</Options>' + + '<Status>' + + '<CreationDate>...</CreationDate>' + + '<State>RequiresIndexDocuments</State>' + + '<UpdateDate>...</UpdateDate>' + + '<UpdateVersion>0</UpdateVersion>' + + '</Status>' + + '</IndexField>'; + '</DefineIndexFieldResult>' + + '<ResponseMetadata>' + + '<RequestId></RequestId>' + + '</ResponseMetadata>' + + '</DefineIndexFieldResponse>' + }; + var actual = { + statusCode: response.statusCode, + body: response.body + .replace(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/g, '') }; -// assert.deepEqual(response, expected); + assert.deepEqual(actual, expected); var dump = database.commandSync('dump', { tables: 'companies' Modified: test/test-utils.js (+12 -30) =================================================================== --- test/test-utils.js 2012-06-21 16:48:38 +0900 (a14e5d3) +++ test/test-utils.js 2012-06-21 17:00:50 +0900 (866fe01) @@ -21,41 +21,14 @@ function setupServer(database) { } exports.setupServer = setupServer; -function get(path) { - var deferred = new Deferred(); - - var options = { - host: testHost, - port: testPort, - path: path - }; - http.get(options, function(response) { - var body = ''; - response.on('data', function(data) { - body += data; - }); - response.on('end', function() { - deferred.call({ - statusCode: response.statusCode, - body: body - }); - }); - }).on('error', function(error) { - deferred.fail(error); - }); - - return deferred; -} -exports.get = get; - -function post(path, body, headers) { +function sendRequest(method, path, postData, headers) { var deferred = new Deferred(); var options = { host: testHost, port: testPort, path: path, - method: 'POST', + method: method, headers: {} }; @@ -83,12 +56,21 @@ function post(path, body, headers) { deferred.fail(error); }); - if (body) request.write(body); + if (postData) request.write(postData); request.end(); }); return deferred; } + +function get(path, headers) { + return sendRequest('GET', path, null, headers); +} +exports.get = get; + +function post(path, body, headers) { + return sendRequest('POST', path, body, headers); +} exports.post = post; var databaseCount = 0; -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B... ダウンロード