1 |
|
2 |
|
3 |
|
4 | var netrc = require("..")
|
5 | , should = require("should")
|
6 | , fs = require("fs");
|
7 |
|
8 | var valid = fs.readFileSync(__dirname+"/fixtures/netrc-valid", "utf-8")
|
9 | , invalid = fs.readFileSync(__dirname+"/fixtures/netrc-invalid", "utf-8")
|
10 | , validWithComment = fs.readFileSync(__dirname+"/fixtures/netrc-valid-w-comment", "utf-8");
|
11 |
|
12 | describe("netrc", function() {
|
13 |
|
14 | describe("read", function() {
|
15 | it("should parse a valid file", function() {
|
16 | var machines = netrc(__dirname+"/fixtures/netrc-valid");
|
17 | should.exist(machines);
|
18 | machines.should.have.property("github.com");
|
19 | machines["github.com"].should.have.property("login");
|
20 | machines["github.com"].login.should.eql("CamShaft");
|
21 | machines["github.com"].should.have.property("password");
|
22 | machines["github.com"].password.should.eql("123");
|
23 | });
|
24 |
|
25 | it("should parse a valid file with comments", function() {
|
26 | var machines = netrc(__dirname+"/fixtures/netrc-valid-w-comment");
|
27 | should.exist(machines);
|
28 | machines.should.have.property("github.com");
|
29 | machines["github.com"].should.have.property("login");
|
30 | machines["github.com"].login.should.eql("CamShaft");
|
31 | machines["github.com"].should.have.property("password");
|
32 | machines["github.com"].password.should.eql("123");
|
33 | });
|
34 |
|
35 | it("should not parse an invalid string", function() {
|
36 | var machines = netrc(__dirname+"/fixtures/netrc-invalid");
|
37 | should.exist(machines);
|
38 | Object.keys(machines).length.should.eql(0);
|
39 | });
|
40 | });
|
41 |
|
42 | describe("parse", function() {
|
43 | it("should parse a valid string", function() {
|
44 | var machines = netrc.parse(valid);
|
45 | should.exist(machines);
|
46 | machines.should.have.property("github.com");
|
47 | machines["github.com"].should.have.property("login");
|
48 | machines["github.com"].login.should.eql("CamShaft");
|
49 | machines["github.com"].should.have.property("password");
|
50 | machines["github.com"].password.should.eql("123");
|
51 | });
|
52 |
|
53 | it("should parse a valid string (pulled from file with comments)", function() {
|
54 | var machines = netrc.parse(validWithComment);
|
55 | should.exist(machines);
|
56 | machines.should.have.property("github.com");
|
57 | machines["github.com"].should.have.property("login");
|
58 | machines["github.com"].login.should.eql("CamShaft");
|
59 | machines["github.com"].should.have.property("password");
|
60 | machines["github.com"].password.should.eql("123");
|
61 | });
|
62 |
|
63 | it("should not parse an invalid string", function() {
|
64 | var machines = netrc.parse(invalid);
|
65 | should.exist(machines);
|
66 | Object.keys(machines).length.should.eql(0);
|
67 | });
|
68 | });
|
69 |
|
70 | describe('format', function(){
|
71 | it('should generate text that parses to the original', function(){
|
72 | var machines = netrc.parse(valid);
|
73 |
|
74 | var text = netrc.format(machines);
|
75 | should.exist(text);
|
76 | text.should.include('machine github.com');
|
77 | text.should.include('login CamShaft');
|
78 | text.should.include('password 123');
|
79 |
|
80 | var parsed = netrc.parse(text);
|
81 | parsed.should.have.property('github.com');
|
82 | parsed["github.com"].should.have.property("login");
|
83 | parsed["github.com"].login.should.eql("CamShaft");
|
84 | parsed["github.com"].should.have.property("password");
|
85 | parsed["github.com"].password.should.eql("123");
|
86 | });
|
87 | });
|
88 |
|
89 | });
|