test-parser.js
1 var Parser = require('../lib/parser'), 2 parseListEntry = Parser.parseListEntry; 3 4 var path = require('path'), 5 assert = require('assert'), 6 inspect = require('util').inspect; 7 8 var group = path.basename(__filename, '.js') + '/'; 9 10 [ 11 { source: 'drwxr-xr-x 10 root root 4096 Dec 21 2012 usr', 12 expected: { 13 type: 'd', 14 name: 'usr', 15 target: undefined, 16 sticky: false, 17 rights: { user: 'rwx', group: 'rx', other: 'rx' }, 18 acl: false, 19 owner: 'root', 20 group: 'root', 21 size: 4096, 22 date: new Date('2012-12-21T00:00') 23 }, 24 what: 'Normal directory' 25 }, 26 { source: 'drwxrwxrwx 1 owner group 0 Aug 31 2012 e-books', 27 expected: { 28 type: 'd', 29 name: 'e-books', 30 target: undefined, 31 sticky: false, 32 rights: { user: 'rwx', group: 'rwx', other: 'rwx' }, 33 acl: false, 34 owner: 'owner', 35 group: 'group', 36 size: 0, 37 date: new Date('2012-08-31T00:00') 38 }, 39 what: 'Normal directory #2' 40 }, 41 { source: '-rw-rw-rw- 1 owner group 7045120 Sep 02 2012 music.mp3', 42 expected: { 43 type: '-', 44 name: 'music.mp3', 45 target: undefined, 46 sticky: false, 47 rights: { user: 'rw', group: 'rw', other: 'rw' }, 48 acl: false, 49 owner: 'owner', 50 group: 'group', 51 size: 7045120, 52 date: new Date('2012-09-02T00:00') 53 }, 54 what: 'Normal file' 55 }, 56 { source: '-rw-rw-rw-+ 1 owner group 7045120 Sep 02 2012 music.mp3', 57 expected: { 58 type: '-', 59 name: 'music.mp3', 60 target: undefined, 61 sticky: false, 62 rights: { user: 'rw', group: 'rw', other: 'rw' }, 63 acl: true, 64 owner: 'owner', 65 group: 'group', 66 size: 7045120, 67 date: new Date('2012-09-02T00:00') 68 }, 69 what: 'File with ACL set' 70 }, 71 { source: 'drwxrwxrwt 7 root root 4096 May 19 2012 tmp', 72 expected: { 73 type: 'd', 74 name: 'tmp', 75 target: undefined, 76 sticky: true, 77 rights: { user: 'rwx', group: 'rwx', other: 'rwx' }, 78 acl: false, 79 owner: 'root', 80 group: 'root', 81 size: 4096, 82 date: new Date('2012-05-19T00:00') 83 }, 84 what: 'Directory with sticky bit and executable for others' 85 }, 86 { source: 'drwxrwx--t 7 root root 4096 May 19 2012 tmp', 87 expected: { 88 type: 'd', 89 name: 'tmp', 90 target: undefined, 91 sticky: true, 92 rights: { user: 'rwx', group: 'rwx', other: 'x' }, 93 acl: false, 94 owner: 'root', 95 group: 'root', 96 size: 4096, 97 date: new Date('2012-05-19T00:00') 98 }, 99 what: 'Directory with sticky bit and executable for others #2' 100 }, 101 { source: 'drwxrwxrwT 7 root root 4096 May 19 2012 tmp', 102 expected: { 103 type: 'd', 104 name: 'tmp', 105 target: undefined, 106 sticky: true, 107 rights: { user: 'rwx', group: 'rwx', other: 'rw' }, 108 acl: false, 109 owner: 'root', 110 group: 'root', 111 size: 4096, 112 date: new Date('2012-05-19T00:00') 113 }, 114 what: 'Directory with sticky bit and not executable for others' 115 }, 116 { source: 'drwxrwx--T 7 root root 4096 May 19 2012 tmp', 117 expected: { 118 type: 'd', 119 name: 'tmp', 120 target: undefined, 121 sticky: true, 122 rights: { user: 'rwx', group: 'rwx', other: '' }, 123 acl: false, 124 owner: 'root', 125 group: 'root', 126 size: 4096, 127 date: new Date('2012-05-19T00:00') 128 }, 129 what: 'Directory with sticky bit and not executable for others #2' 130 }, 131 { source: 'total 871', 132 expected: null, 133 what: 'Ignored line' 134 }, 135 ].forEach(function(v) { 136 var result = parseListEntry(v.source), 137 msg = '[' + group + v.what + ']: parsed output mismatch.\n' 138 + 'Saw: ' + inspect(result) + '\n' 139 + 'Expected: ' + inspect(v.expected); 140 assert.deepEqual(result, v.expected, msg); 141 });