fsentry.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const { expect } = require("chai");
  2. const _bitBooleans = [
  3. 'immutable',
  4. 'is_shortcut',
  5. 'is_symlink',
  6. 'is_dir',
  7. ];
  8. const _integers = [
  9. 'created',
  10. 'accessed',
  11. 'modified',
  12. ];
  13. const _strings = [
  14. 'id', 'uid', 'parent_id', 'name',
  15. ]
  16. const verify_fsentry = async (t, o) => {
  17. await t.case('fsentry is valid', async () => {
  18. for ( const k of _strings ) {
  19. await t.case(`${k} is a string`, () => {
  20. expect(typeof o[k]).equal('string');
  21. });
  22. }
  23. if ( o.is_dir ) {
  24. await t.case(`type is null for directories`, () => {
  25. expect(o.type).equal(null);
  26. });
  27. }
  28. if ( ! o.is_dir ) {
  29. await t.case(`type is a string for files`, () => {
  30. expect(typeof o.type).equal('string');
  31. });
  32. }
  33. await t.case('id === uid', () => {
  34. expect(o.id).equal(o.uid);
  35. });
  36. await t.case('uid is string', () => {
  37. expect(typeof o.uid).equal('string');
  38. });
  39. for ( const k of _bitBooleans ) {
  40. await t.case(`${k} is 0 or 1`, () => {
  41. expect(o[k]).oneOf([0, 1], `${k} should be 0 or 1`);
  42. });
  43. }
  44. t.quirk('is_shared is not populated currently');
  45. // expect(o.is_shared).oneOf([true, false]);
  46. for ( const k of _integers ) {
  47. if ( o.is_dir && k === 'accessed' ) {
  48. t.quirk('accessed is null for new directories');
  49. continue;
  50. }
  51. await t.case(`${k} is numeric type`, () => {
  52. expect(typeof o[k]).equal('number');
  53. });
  54. await t.case(`${k} has no fractional component`, () => {
  55. expect(Number.isInteger(o[k])).true;
  56. });
  57. }
  58. await t.case('symlink_path is null or string', () => {
  59. expect(
  60. o.symlink_path === null ||
  61. typeof o.symlink_path === 'string'
  62. ).true;
  63. });
  64. await t.case('owner object has expected properties', () => {
  65. expect(o.owner).to.haveOwnProperty('username');
  66. expect(o.owner).to.haveOwnProperty('email');
  67. });
  68. })
  69. }
  70. module.exports = {
  71. verify_fsentry,
  72. };