11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('node:assert');
41cb0ef41Sopenharmony_ciconst fs = require('node:fs');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_cifunction verifyStatFsObject(statfs, isBigint = false) {
71cb0ef41Sopenharmony_ci  const valueType = isBigint ? 'bigint' : 'number';
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci  [
101cb0ef41Sopenharmony_ci    'type', 'bsize', 'blocks', 'bfree', 'bavail', 'files', 'ffree',
111cb0ef41Sopenharmony_ci  ].forEach((k) => {
121cb0ef41Sopenharmony_ci    assert.ok(Object.hasOwn(statfs, k));
131cb0ef41Sopenharmony_ci    assert.strictEqual(typeof statfs[k], valueType,
141cb0ef41Sopenharmony_ci                       `${k} should be a ${valueType}`);
151cb0ef41Sopenharmony_ci  });
161cb0ef41Sopenharmony_ci}
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_cifs.statfs(__filename, common.mustSucceed(function(stats) {
191cb0ef41Sopenharmony_ci  verifyStatFsObject(stats);
201cb0ef41Sopenharmony_ci  assert.strictEqual(this, undefined);
211cb0ef41Sopenharmony_ci}));
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_cifs.statfs(__filename, { bigint: true }, function(err, stats) {
241cb0ef41Sopenharmony_ci  assert.ifError(err);
251cb0ef41Sopenharmony_ci  verifyStatFsObject(stats, true);
261cb0ef41Sopenharmony_ci  assert.strictEqual(this, undefined);
271cb0ef41Sopenharmony_ci});
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci// Synchronous
301cb0ef41Sopenharmony_ci{
311cb0ef41Sopenharmony_ci  const statFsObj = fs.statfsSync(__filename);
321cb0ef41Sopenharmony_ci  verifyStatFsObject(statFsObj);
331cb0ef41Sopenharmony_ci}
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci// Synchronous Bigint
361cb0ef41Sopenharmony_ci{
371cb0ef41Sopenharmony_ci  const statFsBigIntObj = fs.statfsSync(__filename, { bigint: true });
381cb0ef41Sopenharmony_ci  verifyStatFsObject(statFsBigIntObj, true);
391cb0ef41Sopenharmony_ci}
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci[false, 1, {}, [], null, undefined].forEach((input) => {
421cb0ef41Sopenharmony_ci  assert.throws(
431cb0ef41Sopenharmony_ci    () => fs.statfs(input, common.mustNotCall()),
441cb0ef41Sopenharmony_ci    {
451cb0ef41Sopenharmony_ci      code: 'ERR_INVALID_ARG_TYPE',
461cb0ef41Sopenharmony_ci      name: 'TypeError'
471cb0ef41Sopenharmony_ci    }
481cb0ef41Sopenharmony_ci  );
491cb0ef41Sopenharmony_ci  assert.throws(
501cb0ef41Sopenharmony_ci    () => fs.statfsSync(input),
511cb0ef41Sopenharmony_ci    {
521cb0ef41Sopenharmony_ci      code: 'ERR_INVALID_ARG_TYPE',
531cb0ef41Sopenharmony_ci      name: 'TypeError'
541cb0ef41Sopenharmony_ci    }
551cb0ef41Sopenharmony_ci  );
561cb0ef41Sopenharmony_ci});
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci// Should not throw an error
591cb0ef41Sopenharmony_cifs.statfs(__filename, undefined, common.mustCall());
60