|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +constcommon=require('../common'); |
| 4 | +consttmpdir=require('../common/tmpdir'); |
| 5 | +constassert=require('assert'); |
| 6 | +constfs=require('fs'); |
| 7 | +constpath=require('path'); |
| 8 | +const{ promises }=fs; |
| 9 | + |
| 10 | +common.crashOnUnhandledRejection(); |
| 11 | + |
| 12 | +// Validate the path argument. |
| 13 | +[false,1,{},[],null,undefined].forEach((i)=>{ |
| 14 | +consterr={type: TypeError,code: 'ERR_INVALID_ARG_TYPE'}; |
| 15 | + |
| 16 | +common.expectsError(()=>fs.lchown(i,1,1,common.mustNotCall()),err); |
| 17 | +common.expectsError(()=>fs.lchownSync(i,1,1),err); |
| 18 | +promises.lchown(false,1,1) |
| 19 | +.then(common.mustNotCall()) |
| 20 | +.catch(common.expectsError(err)); |
| 21 | +}); |
| 22 | + |
| 23 | +// Validate the uid and gid arguments. |
| 24 | +[false,'test',{},[],null,undefined].forEach((i)=>{ |
| 25 | +consterr={type: TypeError,code: 'ERR_INVALID_ARG_TYPE'}; |
| 26 | + |
| 27 | +common.expectsError( |
| 28 | +()=>fs.lchown('not_a_file_that_exists',i,1,common.mustNotCall()), |
| 29 | +err |
| 30 | +); |
| 31 | +common.expectsError( |
| 32 | +()=>fs.lchown('not_a_file_that_exists',1,i,common.mustNotCall()), |
| 33 | +err |
| 34 | +); |
| 35 | +common.expectsError(()=>fs.lchownSync('not_a_file_that_exists',i,1),err); |
| 36 | +common.expectsError(()=>fs.lchownSync('not_a_file_that_exists',1,i),err); |
| 37 | + |
| 38 | +promises.lchown('not_a_file_that_exists',i,1) |
| 39 | +.then(common.mustNotCall()) |
| 40 | +.catch(common.expectsError(err)); |
| 41 | + |
| 42 | +promises.lchown('not_a_file_that_exists',1,i) |
| 43 | +.then(common.mustNotCall()) |
| 44 | +.catch(common.expectsError(err)); |
| 45 | +}); |
| 46 | + |
| 47 | +// Validate the callback argument. |
| 48 | +[false,1,'test',{},[],null,undefined].forEach((i)=>{ |
| 49 | +common.expectsError(()=>fs.lchown('not_a_file_that_exists',1,1,i),{ |
| 50 | +type: TypeError, |
| 51 | +code: 'ERR_INVALID_CALLBACK' |
| 52 | +}); |
| 53 | +}); |
| 54 | + |
| 55 | +if(!common.isWindows){ |
| 56 | +consttestFile=path.join(tmpdir.path,path.basename(__filename)); |
| 57 | +constuid=process.geteuid(); |
| 58 | +constgid=process.getegid(); |
| 59 | + |
| 60 | +tmpdir.refresh(); |
| 61 | +fs.copyFileSync(__filename,testFile); |
| 62 | +fs.lchownSync(testFile,uid,gid); |
| 63 | +fs.lchown(testFile,uid,gid,common.mustCall(async(err)=>{ |
| 64 | +assert.ifError(err); |
| 65 | +awaitpromises.lchown(testFile,uid,gid); |
| 66 | +})); |
| 67 | +} |
0 commit comments