summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrey Zelenkov <zelenkov@nginx.com>2018-12-11 18:30:58 +0300
committerAndrey Zelenkov <zelenkov@nginx.com>2018-12-11 18:30:58 +0300
commitaafa4bbaf92cca2968eac19d74c59f7c7711b9dd (patch)
tree6cda981350e8b3039c32f63e5e9bffdcbf6f8d13
parent37cd6d23b6106f24b1fbaf8c0c898725ef4e6c58 (diff)
downloadunit-aafa4bbaf92cca2968eac19d74c59f7c7711b9dd.tar.gz
unit-aafa4bbaf92cca2968eac19d74c59f7c7711b9dd.tar.bz2
Tests: more Node.js tests.
-rwxr-xr-xtest/node/double_end/app.js6
-rwxr-xr-xtest/node/get_header_names/app.js8
-rwxr-xr-xtest/node/has_header/app.js6
-rwxr-xr-xtest/node/header_name_case/app.js8
-rwxr-xr-xtest/node/header_name_valid/app.js7
-rwxr-xr-xtest/node/header_value_object/app.js6
-rwxr-xr-xtest/node/promise_end/app.js16
-rwxr-xr-xtest/node/promise_handler/app.js18
-rwxr-xr-xtest/node/remove_header/app.js2
-rwxr-xr-xtest/node/write_multiple/app.js8
-rw-r--r--test/test_node_application.py117
11 files changed, 200 insertions, 2 deletions
diff --git a/test/node/double_end/app.js b/test/node/double_end/app.js
new file mode 100755
index 00000000..d8280917
--- /dev/null
+++ b/test/node/double_end/app.js
@@ -0,0 +1,6 @@
+#!/usr/bin/env node
+
+require('unit-http').createServer(function (req, res) {
+ res.end();
+ res.end();
+}).listen(7080);
diff --git a/test/node/get_header_names/app.js b/test/node/get_header_names/app.js
new file mode 100755
index 00000000..4cbccc16
--- /dev/null
+++ b/test/node/get_header_names/app.js
@@ -0,0 +1,8 @@
+#!/usr/bin/env node
+
+require('unit-http').createServer(function (req, res) {
+ res.setHeader('DATE', ['date1', 'date2']);
+ res.setHeader('X-Header', 'blah');
+ res.setHeader('X-Names', res.getHeaderNames());
+ res.end();
+}).listen(7080);
diff --git a/test/node/has_header/app.js b/test/node/has_header/app.js
new file mode 100755
index 00000000..040f551e
--- /dev/null
+++ b/test/node/has_header/app.js
@@ -0,0 +1,6 @@
+#!/usr/bin/env node
+
+require('unit-http').createServer(function (req, res) {
+ res.setHeader('X-Has-Header', res.hasHeader(req['headers']['X-Header']) + '');
+ res.end();
+}).listen(7080);
diff --git a/test/node/header_name_case/app.js b/test/node/header_name_case/app.js
new file mode 100755
index 00000000..490bd4d5
--- /dev/null
+++ b/test/node/header_name_case/app.js
@@ -0,0 +1,8 @@
+#!/usr/bin/env node
+
+require('unit-http').createServer(function (req, res) {
+ res.setHeader('X-Header', '1');
+ res.setHeader('X-header', '2');
+ res.setHeader('X-HEADER', '3');
+ res.end();
+}).listen(7080);
diff --git a/test/node/header_name_valid/app.js b/test/node/header_name_valid/app.js
new file mode 100755
index 00000000..425f026f
--- /dev/null
+++ b/test/node/header_name_valid/app.js
@@ -0,0 +1,7 @@
+#!/usr/bin/env node
+
+require('unit-http').createServer(function (req, res) {
+ res.writeHead(200, {});
+ res.setHeader('@$', 'test');
+ res.end();
+}).listen(7080);
diff --git a/test/node/header_value_object/app.js b/test/node/header_value_object/app.js
new file mode 100755
index 00000000..ff4e2bb0
--- /dev/null
+++ b/test/node/header_value_object/app.js
@@ -0,0 +1,6 @@
+#!/usr/bin/env node
+
+require('unit-http').createServer(function (req, res) {
+ res.setHeader('X-Header', {});
+ res.end();
+}).listen(7080);
diff --git a/test/node/promise_end/app.js b/test/node/promise_end/app.js
new file mode 100755
index 00000000..ed22464c
--- /dev/null
+++ b/test/node/promise_end/app.js
@@ -0,0 +1,16 @@
+#!/usr/bin/env node
+
+var fs = require('fs');
+
+require('unit-http').createServer(function (req, res) {
+ res.write('blah');
+
+ Promise.resolve().then(() => {
+ res.end();
+ });
+
+ req.on('data', (data) => {
+ fs.appendFile('callback', '', function() {});
+ });
+
+}).listen(7080);
diff --git a/test/node/promise_handler/app.js b/test/node/promise_handler/app.js
new file mode 100755
index 00000000..54df09d1
--- /dev/null
+++ b/test/node/promise_handler/app.js
@@ -0,0 +1,18 @@
+#!/usr/bin/env node
+
+var fs = require('fs');
+
+require('unit-http').createServer(function (req, res) {
+ res.end();
+
+ if (req.headers['X-Write-Call']) {
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.write('blah');
+ }
+
+ Promise.resolve().then(() => {
+ req.on('data', (data) => {
+ fs.appendFile(data.toString(), '', function() {});
+ });
+ });
+}).listen(7080);
diff --git a/test/node/remove_header/app.js b/test/node/remove_header/app.js
index 28fee16d..578b72a7 100755
--- a/test/node/remove_header/app.js
+++ b/test/node/remove_header/app.js
@@ -4,7 +4,7 @@ require('unit-http').createServer(function (req, res) {
res.setHeader('X-Header', 'test');
res.setHeader('Was-Header', res.hasHeader('X-Header').toString());
- res.removeHeader('X-Header');
+ res.removeHeader(req['headers']['X-Remove']);
res.setHeader('Has-Header', res.hasHeader('X-Header').toString());
res.end();
diff --git a/test/node/write_multiple/app.js b/test/node/write_multiple/app.js
new file mode 100755
index 00000000..3cbb3b86
--- /dev/null
+++ b/test/node/write_multiple/app.js
@@ -0,0 +1,8 @@
+#!/usr/bin/env node
+
+require('unit-http').createServer(function (req, res) {
+ res.writeHead(200, {'Content-Type': 'text/plain', 'Content-Length': 14});
+ res.write('write');
+ res.write('write2');
+ res.end('end');
+}).listen(7080);
diff --git a/test/test_node_application.py b/test/test_node_application.py
index b736058c..5dedb5a3 100644
--- a/test/test_node_application.py
+++ b/test/test_node_application.py
@@ -127,6 +127,12 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode):
self.get()
+ def test_node_application_double_end(self):
+ self.load('double_end')
+
+ self.assertEqual(self.get()['status'], 200, 'double end')
+ self.assertEqual(self.get()['status'], 200, 'double end 2')
+
def test_node_application_write_return(self):
self.load('write_return')
@@ -136,11 +142,22 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode):
def test_node_application_remove_header(self):
self.load('remove_header')
- resp = self.get()
+ resp = self.get(headers={
+ 'Host': 'localhost',
+ 'X-Remove': 'X-Header'
+ })
self.assertEqual(resp['headers']['Was-Header'], 'true', 'was header')
self.assertEqual(resp['headers']['Has-Header'], 'false', 'has header')
self.assertFalse('X-Header' in resp['headers'], 'remove header')
+ def test_node_application_remove_header_nonexisting(self):
+ self.load('remove_header')
+
+ self.assertEqual(self.get(headers={
+ 'Host': 'localhost',
+ 'X-Remove': 'blah'
+ })['headers']['Has-Header'], 'true', 'remove header nonexisting')
+
def test_node_application_update_header(self):
self.load('update_header')
@@ -165,5 +182,103 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode):
self.assertEqual(self.get()['headers']['X-Type'], 'number',
'get header type')
+ @unittest.expectedFailure
+ def test_node_application_header_name_case(self):
+ self.load('header_name_case')
+
+ headers = self.get()['headers']
+
+ self.assertEqual(headers['X-HEADER'], '3', 'header value')
+ self.assertNotIn('X-Header', headers, 'insensitive')
+ self.assertNotIn('X-header', headers, 'insensitive 2')
+
+ def test_node_application_promise_handler(self):
+ self.load('promise_handler')
+
+ self.assertEqual(self.post(headers={
+ 'Host': 'localhost',
+ 'Content-Type': 'text/html'
+ }, body='callback')['status'], 200, 'promise handler request')
+ self.assertTrue(self.waitforfiles(self.testdir + '/node/callback'),
+ 'promise handler')
+
+ @unittest.expectedFailure
+ def test_node_application_promise_handler_write_after_end(self):
+ self.skip_alerts.append(r'process \d+ exited on signal')
+ self.load('promise_handler')
+
+ self.assertEqual(self.post(headers={
+ 'Host': 'localhost',
+ 'Content-Type': 'text/html',
+ 'X-Write-Call': '1'
+ }, body='callback')['status'], 200,
+ 'promise handler request write after end')
+
+ def test_node_application_promise_end(self):
+ self.load('promise_end')
+
+ self.assertEqual(self.post(headers={
+ 'Host': 'localhost',
+ 'Content-Type': 'text/html'
+ }, body='end')['status'], 200, 'promise end request')
+ self.assertTrue(self.waitforfiles(self.testdir + '/node/callback'),
+ 'promise end')
+
+ def test_node_application_promise_multiple_calls(self):
+ self.load('promise_handler')
+
+ self.post(headers={
+ 'Host': 'localhost',
+ 'Content-Type': 'text/html'
+ }, body='callback1')
+
+ self.assertTrue(self.waitforfiles(self.testdir + '/node/callback1'),
+ 'promise first call')
+
+ self.post(headers={
+ 'Host': 'localhost',
+ 'Content-Type': 'text/html'
+ }, body='callback2')
+
+ self.assertTrue(self.waitforfiles(self.testdir + '/node/callback2'),
+ 'promise second call')
+
+ @unittest.expectedFailure
+ def test_node_application_header_name_valid(self):
+ self.load('header_name_valid')
+
+ self.assertNotIn('status', self.get(), 'header name valid')
+
+ @unittest.expectedFailure
+ def test_node_application_header_value_object(self):
+ self.load('header_value_object')
+
+ self.assertIn('X-Header', self.get()['headers'], 'header value object')
+
+ @unittest.expectedFailure
+ def test_node_application_get_header_names(self):
+ self.load('get_header_names')
+
+ self.assertListEqual(self.get()['headers']['X-Names'],
+ ['date', 'x-header'], 'get header names')
+
+ def test_node_application_has_header(self):
+ self.load('has_header')
+
+ self.assertEqual(self.get(headers={
+ 'Host': 'localhost',
+ 'X-Header': 'length'
+ })['headers']['X-Has-Header'], 'false', 'has header length')
+
+ self.assertEqual(self.get(headers={
+ 'Host': 'localhost',
+ 'X-Header': 'Date'
+ })['headers']['X-Has-Header'], 'false', 'has header date')
+
+ def test_node_application_write_multiple(self):
+ self.load('write_multiple')
+
+ self.assertEqual(self.get()['body'], 'writewrite2end', 'write multiple')
+
if __name__ == '__main__':
TestUnitNodeApplication.main()