Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use tmpDir in test-fs-utimes #16774

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions test/parallel/test-fs-utimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const assert = require('assert');
const util = require('util');
const fs = require('fs');

common.refreshTmpDir();

let tests_ok = 0;
let tests_run = 0;

Expand Down Expand Up @@ -64,18 +66,15 @@ function expect_ok(syscall, resource, err, atime, mtime) {
}
}

// the tests assume that __filename belongs to the user running the tests
// this should be a fairly safe assumption; testing against a temp file
// would be even better though (node doesn't have such functionality yet)
function testIt(atime, mtime, callback) {

let fd;
//
// test synchronized code paths, these functions throw on failure
//
function syncTests() {
fs.utimesSync(__filename, atime, mtime);
expect_ok('utimesSync', __filename, undefined, atime, mtime);
fs.utimesSync(common.tmpDir, atime, mtime);
expect_ok('utimesSync', common.tmpDir, undefined, atime, mtime);
tests_run++;

// some systems don't have futimes
Expand Down Expand Up @@ -110,17 +109,17 @@ function testIt(atime, mtime, callback) {
//
// test async code paths
//
fs.utimes(__filename, atime, mtime, common.mustCall(function(err) {
expect_ok('utimes', __filename, err, atime, mtime);
fs.utimes(common.tmpDir, atime, mtime, common.mustCall(function(err) {
expect_ok('utimes', common.tmpDir, err, atime, mtime);

fs.utimes('foobarbaz', atime, mtime, common.mustCall(function(err) {
expect_errno('utimes', 'foobarbaz', err, 'ENOENT');

// don't close this fd
if (common.isWindows) {
fd = fs.openSync(__filename, 'r+');
fd = fs.openSync(common.tmpDir, 'r+');
} else {
fd = fs.openSync(__filename, 'r');
fd = fs.openSync(common.tmpDir, 'r');
}

fs.futimes(fd, atime, mtime, common.mustCall(function(err) {
Expand All @@ -140,7 +139,7 @@ function testIt(atime, mtime, callback) {
tests_run++;
}

const stats = fs.statSync(__filename);
const stats = fs.statSync(common.tmpDir);

// run tests
const runTest = common.mustCall(testIt, 6);
Expand Down Expand Up @@ -169,7 +168,6 @@ process.on('exit', function() {


// Ref: https://github.com/nodejs/node/issues/13255
common.refreshTmpDir();
const path = `${common.tmpDir}/test-utimes-precision`;
fs.writeFileSync(path, '');

Expand Down