summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-statfs.js
blob: 5fd34f215bc34a9d33ba334e3d49031f2e37d585 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
const common = require('../common');
const assert = require('node:assert');
const fs = require('node:fs');

function verifyStatFsObject(statfs, isBigint = false) {
  const valueType = isBigint ? 'bigint' : 'number';

  [
    'type', 'bsize', 'blocks', 'bfree', 'bavail', 'files', 'ffree',
  ].forEach((k) => {
    assert.ok(Object.hasOwn(statfs, k));
    assert.strictEqual(typeof statfs[k], valueType,
                       `${k} should be a ${valueType}`);
  });
}

fs.statfs(__filename, common.mustSucceed(function(stats) {
  verifyStatFsObject(stats);
  assert.strictEqual(this, undefined);
}));

fs.statfs(__filename, { bigint: true }, function(err, stats) {
  assert.ifError(err);
  verifyStatFsObject(stats, true);
  assert.strictEqual(this, undefined);
});

// Synchronous
{
  const statFsObj = fs.statfsSync(__filename);
  verifyStatFsObject(statFsObj);
}

// Synchronous Bigint
{
  const statFsBigIntObj = fs.statfsSync(__filename, { bigint: true });
  verifyStatFsObject(statFsBigIntObj, true);
}

[false, 1, {}, [], null, undefined].forEach((input) => {
  assert.throws(
    () => fs.statfs(input, common.mustNotCall()),
    {
      code: 'ERR_INVALID_ARG_TYPE',
      name: 'TypeError'
    }
  );
  assert.throws(
    () => fs.statfsSync(input),
    {
      code: 'ERR_INVALID_ARG_TYPE',
      name: 'TypeError'
    }
  );
});

// Should not throw an error
fs.statfs(__filename, undefined, common.mustCall());