11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci// The following tests validate base functionality for the fs.promises 61cb0ef41Sopenharmony_ci// FileHandle.appendFile method. 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst fs = require('fs'); 91cb0ef41Sopenharmony_ciconst { open } = fs.promises; 101cb0ef41Sopenharmony_ciconst path = require('path'); 111cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 121cb0ef41Sopenharmony_ciconst assert = require('assert'); 131cb0ef41Sopenharmony_ciconst tmpDir = tmpdir.path; 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_citmpdir.refresh(); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciasync function validateAppendBuffer() { 181cb0ef41Sopenharmony_ci const filePath = path.resolve(tmpDir, 'tmp-append-file-buffer.txt'); 191cb0ef41Sopenharmony_ci const fileHandle = await open(filePath, 'a'); 201cb0ef41Sopenharmony_ci const buffer = Buffer.from('a&Dp'.repeat(100), 'utf8'); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci await fileHandle.appendFile(buffer); 231cb0ef41Sopenharmony_ci const appendedFileData = fs.readFileSync(filePath); 241cb0ef41Sopenharmony_ci assert.deepStrictEqual(appendedFileData, buffer); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci await fileHandle.close(); 271cb0ef41Sopenharmony_ci} 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ciasync function validateAppendString() { 301cb0ef41Sopenharmony_ci const filePath = path.resolve(tmpDir, 'tmp-append-file-string.txt'); 311cb0ef41Sopenharmony_ci const fileHandle = await open(filePath, 'a'); 321cb0ef41Sopenharmony_ci const string = 'x~yz'.repeat(100); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci await fileHandle.appendFile(string); 351cb0ef41Sopenharmony_ci const stringAsBuffer = Buffer.from(string, 'utf8'); 361cb0ef41Sopenharmony_ci const appendedFileData = fs.readFileSync(filePath); 371cb0ef41Sopenharmony_ci assert.deepStrictEqual(appendedFileData, stringAsBuffer); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci await fileHandle.close(); 401cb0ef41Sopenharmony_ci} 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_civalidateAppendBuffer() 431cb0ef41Sopenharmony_ci .then(validateAppendString) 441cb0ef41Sopenharmony_ci .then(common.mustCall()); 45