From 925f55c71b1e3a7ce9c47c831eb3192e2e0f49da Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 30 Nov 2019 14:47:05 -0800 Subject: [PATCH] test: replace internal API test with public API test The internal freelist `hasItems()` test use the internal API directly. This commit changes them to use the API as it is exposed publicly. It tests the same code paths, but does it without needing `--expose-internals`. Refs: https://github.com/nodejs/node/pull/27588#pullrequestreview-234284081 --- test/parallel/test-freelist.js | 10 ---------- test/parallel/test-http-common.js | 18 +++++++++++++++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/test/parallel/test-freelist.js b/test/parallel/test-freelist.js index d0ec3d1e8e7f9b..eb43308dbe59cc 100644 --- a/test/parallel/test-freelist.js +++ b/test/parallel/test-freelist.js @@ -28,13 +28,3 @@ assert.strictEqual(flist1.free({ id: 'test5' }), false); assert.strictEqual(flist1.alloc().id, 'test3'); assert.strictEqual(flist1.alloc().id, 'test2'); assert.strictEqual(flist1.alloc().id, 'test1'); - -// Check list has elements -const flist2 = new FreeList('flist2', 2, Object); -assert.strictEqual(flist2.hasItems(), false); - -flist2.free({ id: 'test1' }); -assert.strictEqual(flist2.hasItems(), true); - -flist2.alloc(); -assert.strictEqual(flist2.hasItems(), false); diff --git a/test/parallel/test-http-common.js b/test/parallel/test-http-common.js index 1629856ce57d09..565acc6cb111b3 100644 --- a/test/parallel/test-http-common.js +++ b/test/parallel/test-http-common.js @@ -1,9 +1,11 @@ 'use strict'; require('../common'); const assert = require('assert'); -const httpCommon = require('_http_common'); -const checkIsHttpToken = httpCommon._checkIsHttpToken; -const checkInvalidHeaderChar = httpCommon._checkInvalidHeaderChar; +const { + _checkInvalidHeaderChar: checkInvalidHeaderChar, + _checkIsHttpToken: checkIsHttpToken, + parsers +} = require('_http_common'); // checkIsHttpToken assert(checkIsHttpToken('t')); @@ -31,3 +33,13 @@ assert.strictEqual(checkInvalidHeaderChar('tt'), false); assert.strictEqual(checkInvalidHeaderChar('ttt'), false); assert.strictEqual(checkInvalidHeaderChar('tttt'), false); assert.strictEqual(checkInvalidHeaderChar('ttttt'), false); + +// parsers +{ + const dummyParser = { id: 'fhqwhgads' }; + assert.strictEqual(parsers.hasItems(), false); + assert.strictEqual(parsers.free(dummyParser), true); + assert.strictEqual(parsers.hasItems(), true); + assert.strictEqual(parsers.alloc(), dummyParser); + assert.strictEqual(parsers.hasItems(), false); +}