fs-readdir.json 1.9 KB

123456789101112131415161718192021222324
  1. {
  2. "name": "verify-fs-readdir",
  3. "nodes": [
  4. {"id": "n1", "name": "Trigger", "type": "click-trigger", "position": {"x": 0, "y": 0}, "config": {}},
  5. {"id": "n2", "name": "List", "type": "code", "position": {"x": 0, "y": 100},
  6. "config": {"code": "const dir = '/tmp/sb-readdir-test';\nsmartbotic.fs.mkdir(dir);\nsmartbotic.fs.writeFile(dir + '/one.txt', smartbotic.utils.base64Encode('hello'));\nsmartbotic.fs.writeFile(dir + '/two.txt', smartbotic.utils.base64Encode('worldwide'));\nsmartbotic.fs.mkdir(dir + '/sub');\n\nconst listing = smartbotic.fs.readdir(dir);\nconst missing = smartbotic.fs.readdir('/tmp/sb-readdir-does-not-exist');\nconst notDir = smartbotic.fs.readdir(dir + '/one.txt');\n\nconst names = listing.entries.map(function (e) { return e.name; }).sort();\nconst one = listing.entries.filter(function (e) { return e.name === 'one.txt'; })[0];\nconst sub = listing.entries.filter(function (e) { return e.name === 'sub'; })[0];\n\nsmartbotic.fs.unlink(dir + '/one.txt');\nsmartbotic.fs.unlink(dir + '/two.txt');\n\nreturn {\n ok: listing.success,\n names: names,\n oneSize: one.size,\n oneHasMtime: one.modifiedAt > 1600000000000,\n subIsDirectory: sub.isDirectory,\n oneIsDirectory: one.isDirectory,\n missingRejected: missing.success === false,\n notDirRejected: notDir.success === false,\n hasWorkflowId: typeof context.workflowId === 'string' && context.workflowId.length > 0\n};"}}
  7. ],
  8. "connections": [
  9. {"sourceNodeId": "n1", "sourceOutput": "main", "targetNodeId": "n2", "targetInput": "data"}
  10. ],
  11. "expect": {
  12. "n2": {"status": "completed", "output": {"result": {
  13. "ok": true,
  14. "names": ["one.txt", "sub", "two.txt"],
  15. "oneSize": 5,
  16. "oneHasMtime": true,
  17. "subIsDirectory": true,
  18. "oneIsDirectory": false,
  19. "missingRejected": true,
  20. "notDirRejected": true,
  21. "hasWorkflowId": true
  22. }}}
  23. }
  24. }