Debian Codegraph @

parse-passwd/test/test.js

raw
1 'use strict';
2
3 require('mocha');
4 var fs = require('fs');
5 var path = require('path');
6 var assert = require('assert');
7 var parse = require('../');
8
9 var fixture = path.join(__dirname, 'fixtures', 'passwd');
10
11 describe('parse-passwd', function() {
12 it('should export a function', function() {
13 assert.equal(typeof parse, 'function');
14 });
15
16 it('should throw an error when invalid args are passed', function(cb) {
17 try {
18 parse();
19 cb(new Error('expected an error'));
20 } catch (err) {
21 assert(err);
22 assert.equal(err.message, 'expected a string');
23 cb();
24 }
25 });
26
27 it('should parse a passwd file', function() {
28 var expected = [
29 {username: 'nobody', password: '*', uid: '-2', gid: '-2', gecos: 'Unprivileged User', homedir: '/var/empty', shell: '/usr/bin/false'},
30 {username: 'root', password: '*', uid: '0', gid: '0', gecos: 'System Administrator', homedir: '/var/root', shell: '/bin/sh'},
31 {username: 'daemon', password: '*', uid: '1', gid: '1', gecos: 'System Services', homedir: '/var/root', shell: '/usr/bin/false'},
32 {username: 'doowb', password: '*', uid: '123', gid: '123', gecos: 'Brian Woodward', homedir: '/Users/doowb', shell: '/bin/bash'}
33 ];
34 var actual = parse(fs.readFileSync(fixture, 'utf8'));
35 assert.deepEqual(actual, expected);
36 });
37 });