fsentry.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. if ( k === 'is_dir' ) {
  41. await t.case(`is_dir is true or false`, () => {
  42. expect(o[k]).oneOf([true, false], `${k} should be true or false`);
  43. });
  44. continue;
  45. }
  46. await t.case(`${k} is 0 or 1`, () => {
  47. expect(o[k]).oneOf([0, 1], `${k} should be 0 or 1`);
  48. });
  49. }
  50. t.quirk('is_shared is not populated currently');
  51. // expect(o.is_shared).oneOf([true, false]);
  52. for ( const k of _integers ) {
  53. if ( o.is_dir && k === 'accessed' ) {
  54. t.quirk('accessed is null for new directories');
  55. continue;
  56. }
  57. await t.case(`${k} is numeric type`, () => {
  58. expect(typeof o[k]).equal('number');
  59. });
  60. await t.case(`${k} has no fractional component`, () => {
  61. expect(Number.isInteger(o[k])).true;
  62. });
  63. }
  64. await t.case('symlink_path is null or string', () => {
  65. expect(
  66. o.symlink_path === null ||
  67. typeof o.symlink_path === 'string'
  68. ).true;
  69. });
  70. await t.case('owner object has expected properties', () => {
  71. expect(o.owner).to.haveOwnProperty('username');
  72. expect(o.owner).to.haveOwnProperty('email');
  73. });
  74. })
  75. }
  76. module.exports = {
  77. verify_fsentry,
  78. };