mkdir.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const { expect } = require("chai");
  2. const { verify_fsentry } = require("./fsentry");
  3. module.exports = {
  4. name: 'mkdir',
  5. do: async t => {
  6. await t.case('recursive mkdir', async () => {
  7. // Can create a chain of directories
  8. const path = 'a/b/c/d/e/f/g';
  9. let result;
  10. await t.case('no exception thrown', async () => {
  11. result = await t.mkdir(path, {
  12. create_missing_parents: true,
  13. });
  14. console.log('result?', result)
  15. });
  16. // Returns the last directory in the chain
  17. // await verify_fsentry(t, result);
  18. await t.case('filename is correct', () => {
  19. expect(result.name).equal('g');
  20. });
  21. await t.case('can stat the directory', async () => {
  22. const stat = await t.stat(path);
  23. // await verify_fsentry(t, stat);
  24. await t.case('filename is correct', () => {
  25. expect(stat.name).equal('g');
  26. });
  27. });
  28. // can stat the first directory in the chain
  29. await t.case('can stat the first directory in the chain', async () => {
  30. const stat = await t.stat('a');
  31. // await verify_fsentry(t, stat);
  32. await t.case('filename is correct', () => {
  33. expect(stat.name).equal('a');
  34. });
  35. });
  36. });
  37. // NOTE: It looks like we removed this behavior and we always create missing parents
  38. // await t.case('fails with missing parent', async () => {
  39. // let threw = false;
  40. // try {
  41. // const result = await t.mkdir('a/b/x/g');
  42. // console.log('unexpected result', result);
  43. // } catch (e) {
  44. // expect(e.response.status).equal(422);
  45. // console.log('response?', e.response.data)
  46. // expect(e.response.data).deep.equal({
  47. // code: 'dest_does_not_exist',
  48. // message: 'Destination was not found.',
  49. // });
  50. // threw = true;
  51. // }
  52. // expect(threw).true;
  53. // });
  54. await t.case('mkdir dedupe name', async () => {
  55. for ( let i = 1; i <= 3; i++ ) {
  56. await t.mkdir('a', { dedupe_name: true });
  57. const stat = await t.stat(`a (${i})`);
  58. expect(stat.name).equal(`a (${i})`);
  59. }
  60. });
  61. }
  62. };