Skip to content

Commit

Permalink
test: update tests to check for no-op
Browse files Browse the repository at this point in the history
  • Loading branch information
sonimadhuri committed Oct 28, 2022
1 parent cb705e9 commit 56fb2f4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
54 changes: 54 additions & 0 deletions test/parallel/test-http-set-headers-distinct.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const { createServer, request } = require('http');

const server = createServer(
common.mustCall((req, res) => {
req.headersDistinct = { 'x-req-a': ['zzz'] };

// headersDistinct setter should be a No-Op
assert.deepStrictEqual(req.headersDistinct, {
'transfer-encoding': [
'chunked',
],
'connection': [
'keep-alive',
],
'host': [
`127.0.0.1:${server.address().port}`,
]
});

req.on('end', function() {
res.write('BODY');
res.end();
});

req.resume();
})
);

server.listen(
0,
common.mustCall(() => {
const req = request(
{
host: '127.0.0.1',
port: server.address().port,
path: '/',
method: 'POST',
},
common.mustCall((res) => {
res.on('end', function() {
server.close();
});
res.resume();
})
);

req.write('BODY');
req.end();
})
);
11 changes: 5 additions & 6 deletions test/parallel/test-set-incoming-message-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ require('../common');
const { IncomingMessage } = require('http');
const assert = require('assert');

// Headers setter function set a header correctly
// Headers setter should be a No-Op
{
const im = new IncomingMessage();
im.headers = { key: 'value' };
assert.deepStrictEqual(im.headers, { key: 'value' });
assert.deepStrictEqual(im.headers, {});
}

// Trailers setter function set a header correctly
// Trailers setter should be a No-Op
{
const im = new IncomingMessage();
im.trailers = { key: 'value' };
assert.deepStrictEqual(im.trailers, { key: 'value' });
assert.deepStrictEqual(im.trailers, {});
}

// _addHeaderLines function set a header correctly
{
const im = new IncomingMessage();
im.headers = { key1: 'value1' };
im._addHeaderLines(['key2', 'value2'], 2);
assert.deepStrictEqual(im.headers, { key1: 'value1', key2: 'value2' });
assert.deepStrictEqual(im.headers, { key2: 'value2' });
}

0 comments on commit 56fb2f4

Please sign in to comment.