11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst path = require('path'); 51cb0ef41Sopenharmony_ciconst fs = require('fs'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 81cb0ef41Sopenharmony_citmpdir.refresh(); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci// Test creating and reading hard link 111cb0ef41Sopenharmony_ciconst srcPath = path.join(tmpdir.path, 'hardlink-target.txt'); 121cb0ef41Sopenharmony_ciconst dstPath = path.join(tmpdir.path, 'link1.js'); 131cb0ef41Sopenharmony_cifs.writeFileSync(srcPath, 'hello world'); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_cifunction callback(err) { 161cb0ef41Sopenharmony_ci assert.ifError(err); 171cb0ef41Sopenharmony_ci const dstContent = fs.readFileSync(dstPath, 'utf8'); 181cb0ef41Sopenharmony_ci assert.strictEqual(dstContent, 'hello world'); 191cb0ef41Sopenharmony_ci} 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_cifs.link(srcPath, dstPath, common.mustCall(callback)); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci// test error outputs 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci[false, 1, [], {}, null, undefined].forEach((i) => { 261cb0ef41Sopenharmony_ci assert.throws( 271cb0ef41Sopenharmony_ci () => fs.link(i, '', common.mustNotCall()), 281cb0ef41Sopenharmony_ci { 291cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 301cb0ef41Sopenharmony_ci name: 'TypeError' 311cb0ef41Sopenharmony_ci } 321cb0ef41Sopenharmony_ci ); 331cb0ef41Sopenharmony_ci assert.throws( 341cb0ef41Sopenharmony_ci () => fs.link('', i, common.mustNotCall()), 351cb0ef41Sopenharmony_ci { 361cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 371cb0ef41Sopenharmony_ci name: 'TypeError' 381cb0ef41Sopenharmony_ci } 391cb0ef41Sopenharmony_ci ); 401cb0ef41Sopenharmony_ci assert.throws( 411cb0ef41Sopenharmony_ci () => fs.linkSync(i, ''), 421cb0ef41Sopenharmony_ci { 431cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 441cb0ef41Sopenharmony_ci name: 'TypeError' 451cb0ef41Sopenharmony_ci } 461cb0ef41Sopenharmony_ci ); 471cb0ef41Sopenharmony_ci assert.throws( 481cb0ef41Sopenharmony_ci () => fs.linkSync('', i), 491cb0ef41Sopenharmony_ci { 501cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 511cb0ef41Sopenharmony_ci name: 'TypeError' 521cb0ef41Sopenharmony_ci } 531cb0ef41Sopenharmony_ci ); 541cb0ef41Sopenharmony_ci}); 55