summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-promises-readfile.js
diff options
context:
space:
mode:
authorTimothy Gu <timothygu99@gmail.com>2018-06-24 01:11:53 -0400
committerTimothy Gu <timothygu99@gmail.com>2018-07-04 12:14:53 -0400
commit5057dd40a1791898d7b2fed176fe3201cf9d4145 (patch)
treeda82ec59cb38361e5db5e3d726de8881234389e6 /test/parallel/test-fs-promises-readfile.js
parentc01601e1fede7d13b590adcef03721f4d3a6b511 (diff)
downloadandroid-node-v8-5057dd40a1791898d7b2fed176fe3201cf9d4145.tar.gz
android-node-v8-5057dd40a1791898d7b2fed176fe3201cf9d4145.tar.bz2
android-node-v8-5057dd40a1791898d7b2fed176fe3201cf9d4145.zip
fs: support pseudofiles in promises.readFile
PR-URL: https://github.com/nodejs/node/pull/21497 Fixes: https://github.com/nodejs/node/issues/21331 Refs: http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html Refs: https://groups.google.com/forum/#!topic/nodejs-dev/rxZ_RoH1Gn0 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'test/parallel/test-fs-promises-readfile.js')
-rw-r--r--test/parallel/test-fs-promises-readfile.js44
1 files changed, 31 insertions, 13 deletions
diff --git a/test/parallel/test-fs-promises-readfile.js b/test/parallel/test-fs-promises-readfile.js
index 4334673c30..b1186ad217 100644
--- a/test/parallel/test-fs-promises-readfile.js
+++ b/test/parallel/test-fs-promises-readfile.js
@@ -12,17 +12,35 @@ const fn = path.join(tmpdir.path, 'large-file');
common.crashOnUnhandledRejection();
-// Creating large buffer with random content
-const buffer = Buffer.from(
- Array.apply(null, { length: 16834 * 2 })
- .map(Math.random)
- .map((number) => (number * (1 << 8)))
-);
-
-// Writing buffer to a file then try to read it
-writeFile(fn, buffer)
- .then(() => readFile(fn))
- .then((readBuffer) => {
- assert.strictEqual(readBuffer.equals(buffer), true);
- })
+async function validateReadFile() {
+ // Creating large buffer with random content
+ const buffer = Buffer.from(
+ Array.apply(null, { length: 16834 * 2 })
+ .map(Math.random)
+ .map((number) => (number * (1 << 8)))
+ );
+
+ // Writing buffer to a file then try to read it
+ await writeFile(fn, buffer);
+ const readBuffer = await readFile(fn);
+ assert.strictEqual(readBuffer.equals(buffer), true);
+}
+
+async function validateReadFileProc() {
+ // Test to make sure reading a file under the /proc directory works. Adapted
+ // from test-fs-read-file-sync-hostname.js.
+ // Refs:
+ // - https://groups.google.com/forum/#!topic/nodejs-dev/rxZ_RoH1Gn0
+ // - https://github.com/nodejs/node/issues/21331
+
+ // Test is Linux-specific.
+ if (!common.isLinux)
+ return;
+
+ const hostname = await readFile('/proc/sys/kernel/hostname');
+ assert.ok(hostname.length > 0);
+}
+
+validateReadFile()
+ .then(() => validateReadFileProc())
.then(common.mustCall());