ssh-client-wrapper 2.2.4 → 2.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/fork.js +12 -12
- package/lib/index.js +11 -12
- package/lib/rsyncExec.js +9 -9
- package/lib/sshExec.js +23 -23
- package/lib/util.js +18 -18
- package/package.json +1 -2
- package/test/interface.js +48 -49
- package/test/rsyncExec.js +72 -73
- package/test/sshExec.js +40 -40
- package/test/testUtil/testFiles.js +7 -8
- package/test/util.js +12 -13
package/test/interface.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
process.on("unhandledRejection", console.dir); //eslint-disable-line no-console
|
|
2
|
+
process.on("unhandledRejection", console.dir); // eslint-disable-line no-console
|
|
3
3
|
Error.traceLimit = 100000;
|
|
4
4
|
|
|
5
|
-
//setup test framework
|
|
5
|
+
// setup test framework
|
|
6
6
|
const chai = require("chai");
|
|
7
7
|
const { expect } = require("chai");
|
|
8
8
|
const sinon = require("sinon");
|
|
@@ -11,7 +11,7 @@ chai.use(require("chai-as-promised"));
|
|
|
11
11
|
|
|
12
12
|
const rewire = require("rewire");
|
|
13
13
|
|
|
14
|
-
//testee
|
|
14
|
+
// testee
|
|
15
15
|
const SshClientWrapper = rewire("../lib/index.js");
|
|
16
16
|
|
|
17
17
|
const sshExec = sinon.stub();
|
|
@@ -21,25 +21,24 @@ const ls = sinon.stub();
|
|
|
21
21
|
const send = sinon.stub();
|
|
22
22
|
const recv = sinon.stub();
|
|
23
23
|
|
|
24
|
-
//eslint-disable-next-line no-underscore-dangle
|
|
24
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
25
25
|
SshClientWrapper.__set__({
|
|
26
26
|
sshExec, canConnect, disconnect, ls, send, recv
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
describe("test for
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
//eslint-disable-next-line no-new
|
|
29
|
+
describe("test for interface", () => {
|
|
30
|
+
describe("test for constructor", () => {
|
|
31
|
+
it("should throw error when instanciate with non-empty string host", () => {
|
|
32
|
+
expect(() => {
|
|
33
|
+
// eslint-disable-next-line no-new
|
|
35
34
|
new SshClientWrapper({});
|
|
36
35
|
}).to.throw("host is required");
|
|
37
|
-
expect(()=>{
|
|
38
|
-
//eslint-disable-next-line no-new
|
|
36
|
+
expect(() => {
|
|
37
|
+
// eslint-disable-next-line no-new
|
|
39
38
|
new SshClientWrapper({ host: "" });
|
|
40
39
|
}).to.throw("empty host is not allowed");
|
|
41
40
|
});
|
|
42
|
-
it("should successfully instanciate only with host prop", ()=>{
|
|
41
|
+
it("should successfully instanciate only with host prop", () => {
|
|
43
42
|
expect(new SshClientWrapper({ host: "hoge" })).to.have.property("exec");
|
|
44
43
|
expect(new SshClientWrapper({ host: "hoge" })).to.have.property("ls");
|
|
45
44
|
expect(new SshClientWrapper({ host: "hoge" })).to.have.property("send");
|
|
@@ -48,11 +47,11 @@ describe("test for interface", ()=>{
|
|
|
48
47
|
expect(new SshClientWrapper({ host: "hoge" })).to.have.property("disconnect");
|
|
49
48
|
});
|
|
50
49
|
});
|
|
51
|
-
describe("test for public method", ()=>{
|
|
50
|
+
describe("test for public method", () => {
|
|
52
51
|
let ssh;
|
|
53
52
|
const hostInfoOrg = { host: "hoge" };
|
|
54
53
|
const hostInfo = { ...hostInfoOrg, masterPty: null, rsyncVersion: null };
|
|
55
|
-
beforeEach(()=>{
|
|
54
|
+
beforeEach(() => {
|
|
56
55
|
ssh = new SshClientWrapper(hostInfoOrg);
|
|
57
56
|
sshExec.reset();
|
|
58
57
|
canConnect.reset();
|
|
@@ -61,113 +60,113 @@ describe("test for interface", ()=>{
|
|
|
61
60
|
send.reset();
|
|
62
61
|
recv.reset();
|
|
63
62
|
});
|
|
64
|
-
describe("test for exec", ()=>{
|
|
65
|
-
it("should call sshExec with cmd", ()=>{
|
|
63
|
+
describe("test for exec", () => {
|
|
64
|
+
it("should call sshExec with cmd", () => {
|
|
66
65
|
ssh.exec("ls");
|
|
67
66
|
expect(sshExec).to.be.calledWith(hostInfo, "ls", 0, null);
|
|
68
67
|
});
|
|
69
|
-
it("should call sshExec with cmd and timeout", ()=>{
|
|
68
|
+
it("should call sshExec with cmd and timeout", () => {
|
|
70
69
|
ssh.exec("ls", 10);
|
|
71
70
|
expect(sshExec).to.be.calledWith(hostInfo, "ls", 10, null);
|
|
72
71
|
});
|
|
73
|
-
it("should call sshExec with cmd, timeout and call back function", ()=>{
|
|
74
|
-
const cb = ()=>{};
|
|
72
|
+
it("should call sshExec with cmd, timeout and call back function", () => {
|
|
73
|
+
const cb = () => {};
|
|
75
74
|
ssh.exec("ls", 10, cb);
|
|
76
75
|
expect(sshExec).to.be.calledWith(hostInfo, "ls", 10, cb);
|
|
77
76
|
});
|
|
78
|
-
it("should reject if cmd is not string (number)", ()=>{
|
|
77
|
+
it("should reject if cmd is not string (number)", () => {
|
|
79
78
|
return expect(ssh.exec(0)).to.be.rejectedWith("cmd must be string");
|
|
80
79
|
});
|
|
81
|
-
it("should reject if cmd is not string (null)", ()=>{
|
|
80
|
+
it("should reject if cmd is not string (null)", () => {
|
|
82
81
|
return expect(ssh.exec(null)).to.be.rejectedWith("cmd must be string");
|
|
83
82
|
});
|
|
84
|
-
it("should reject if cmd is empty string", ()=>{
|
|
83
|
+
it("should reject if cmd is empty string", () => {
|
|
85
84
|
return expect(ssh.exec("")).to.be.rejectedWith("cmd must be string");
|
|
86
85
|
});
|
|
87
86
|
});
|
|
88
|
-
describe("test for ls", ()=>{
|
|
89
|
-
it("should call ls without timeout", ()=>{
|
|
87
|
+
describe("test for ls", () => {
|
|
88
|
+
it("should call ls without timeout", () => {
|
|
90
89
|
ssh.ls("hoge");
|
|
91
90
|
expect(ls).to.be.calledWith(hostInfo, "hoge", [], 0);
|
|
92
91
|
});
|
|
93
|
-
it("should call ls with option", ()=>{
|
|
92
|
+
it("should call ls with option", () => {
|
|
94
93
|
ssh.ls("hoge", ["-l", "-r", "-t"]);
|
|
95
94
|
expect(ls).to.be.calledWith(hostInfo, "hoge", ["-l", "-r", "-t"], 0);
|
|
96
95
|
});
|
|
97
|
-
it("should call ls with option and timeout", ()=>{
|
|
96
|
+
it("should call ls with option and timeout", () => {
|
|
98
97
|
ssh.ls("hoge", ["-l", "-r", "-t"], 10);
|
|
99
98
|
expect(ls).to.be.calledWith(hostInfo, "hoge", ["-l", "-r", "-t"], 10);
|
|
100
99
|
});
|
|
101
100
|
});
|
|
102
|
-
describe("test for send", ()=>{
|
|
103
|
-
it("should call send with src and dst", ()=>{
|
|
101
|
+
describe("test for send", () => {
|
|
102
|
+
it("should call send with src and dst", () => {
|
|
104
103
|
ssh.send(["src"], "dst");
|
|
105
104
|
expect(send).to.be.calledWith(hostInfo, ["src"], "dst", [], 0);
|
|
106
105
|
});
|
|
107
|
-
it("should call send with src, dst, and opt", ()=>{
|
|
106
|
+
it("should call send with src, dst, and opt", () => {
|
|
108
107
|
ssh.send(["src"], "dst", ["--dry-run", "--delete"]);
|
|
109
108
|
expect(send).to.be.calledWith(hostInfo, ["src"], "dst", ["--dry-run", "--delete"], 0);
|
|
110
109
|
});
|
|
111
|
-
it("should call send with src, dst, opt, and timeout", ()=>{
|
|
110
|
+
it("should call send with src, dst, opt, and timeout", () => {
|
|
112
111
|
ssh.send(["src"], "dst", ["--dry-run", "--delete"], 10);
|
|
113
112
|
expect(send).to.be.calledWith(hostInfo, ["src"], "dst", ["--dry-run", "--delete"], 10);
|
|
114
113
|
});
|
|
115
|
-
it("should be rejected if src is not array of string", ()=>{
|
|
114
|
+
it("should be rejected if src is not array of string", () => {
|
|
116
115
|
return expect(ssh.send(1)).to.be.rejectedWith("src must be array of string");
|
|
117
116
|
});
|
|
118
|
-
it("should be rejected if src has only empty string element", ()=>{
|
|
117
|
+
it("should be rejected if src has only empty string element", () => {
|
|
119
118
|
return expect(ssh.send(["", ""])).to.be.rejectedWith("src must contain non-empty string");
|
|
120
119
|
});
|
|
121
|
-
it("should be rejected if src has only empty string element", ()=>{
|
|
120
|
+
it("should be rejected if src has only empty string element", () => {
|
|
122
121
|
return expect(ssh.send([""])).to.be.rejectedWith("src must contain non-empty string");
|
|
123
122
|
});
|
|
124
|
-
it("should be called if src includes empty string ", ()=>{
|
|
123
|
+
it("should be called if src includes empty string ", () => {
|
|
125
124
|
ssh.send(["src", ""], "dst");
|
|
126
125
|
expect(send).to.be.calledWith(hostInfo, ["src", ""], "dst", [], 0);
|
|
127
126
|
});
|
|
128
|
-
it("should be rejected if dst is not string", ()=>{
|
|
127
|
+
it("should be rejected if dst is not string", () => {
|
|
129
128
|
return expect(ssh.send(["src"], 0)).to.be.rejectedWith("dst must be string");
|
|
130
129
|
});
|
|
131
|
-
it("should be rejected if dst is empty string", ()=>{
|
|
130
|
+
it("should be rejected if dst is empty string", () => {
|
|
132
131
|
return expect(ssh.send(["src"], "")).to.be.rejectedWith("dst must be non-empty string");
|
|
133
132
|
});
|
|
134
|
-
it("should be rejected if opt is not array of string", ()=>{
|
|
133
|
+
it("should be rejected if opt is not array of string", () => {
|
|
135
134
|
return expect(ssh.send(["src"], "dst", [null])).to.be.rejectedWith("opt must be array of string");
|
|
136
135
|
});
|
|
137
136
|
});
|
|
138
|
-
describe("test for recv", ()=>{
|
|
139
|
-
it("should call recv with src and dst", ()=>{
|
|
137
|
+
describe("test for recv", () => {
|
|
138
|
+
it("should call recv with src and dst", () => {
|
|
140
139
|
ssh.recv(["src"], "dst");
|
|
141
140
|
expect(recv).to.be.calledWith(hostInfo, ["src"], "dst", [], 0);
|
|
142
141
|
});
|
|
143
|
-
it("should call recv with src, dst, and opt", ()=>{
|
|
142
|
+
it("should call recv with src, dst, and opt", () => {
|
|
144
143
|
ssh.recv(["src"], "dst", ["--dry-run", "--delete"]);
|
|
145
144
|
expect(recv).to.be.calledWith(hostInfo, ["src"], "dst", ["--dry-run", "--delete"], 0);
|
|
146
145
|
});
|
|
147
|
-
it("should call recv with src, dst, opt, and timeout", ()=>{
|
|
146
|
+
it("should call recv with src, dst, opt, and timeout", () => {
|
|
148
147
|
ssh.recv(["src"], "dst", ["--dry-run", "--delete"], 10);
|
|
149
148
|
expect(recv).to.be.calledWith(hostInfo, ["src"], "dst", ["--dry-run", "--delete"], 10);
|
|
150
149
|
});
|
|
151
|
-
it("should be rejected if src is not array of string", ()=>{
|
|
150
|
+
it("should be rejected if src is not array of string", () => {
|
|
152
151
|
return expect(ssh.recv(1)).to.be.rejectedWith("src must be array of string");
|
|
153
152
|
});
|
|
154
|
-
it("should be rejected if src has only empty string element", ()=>{
|
|
153
|
+
it("should be rejected if src has only empty string element", () => {
|
|
155
154
|
return expect(ssh.recv(["", ""])).to.be.rejectedWith("src must contain non-empty string");
|
|
156
155
|
});
|
|
157
|
-
it("should be rejected if src has only empty string element", ()=>{
|
|
156
|
+
it("should be rejected if src has only empty string element", () => {
|
|
158
157
|
return expect(ssh.recv([""])).to.be.rejectedWith("src must contain non-empty string");
|
|
159
158
|
});
|
|
160
|
-
it("should be called if src includes empty string ", ()=>{
|
|
159
|
+
it("should be called if src includes empty string ", () => {
|
|
161
160
|
ssh.recv(["src", ""], "dst");
|
|
162
161
|
expect(recv).to.be.calledWith(hostInfo, ["src", ""], "dst", [], 0);
|
|
163
162
|
});
|
|
164
|
-
it("should be rejected if dst is not string", ()=>{
|
|
163
|
+
it("should be rejected if dst is not string", () => {
|
|
165
164
|
return expect(ssh.recv(["src"], 0)).to.be.rejectedWith("dst must be string");
|
|
166
165
|
});
|
|
167
|
-
it("should be rejected if dst is empty string", ()=>{
|
|
166
|
+
it("should be rejected if dst is empty string", () => {
|
|
168
167
|
return expect(ssh.recv(["src"], "")).to.be.rejectedWith("dst must be non-empty string");
|
|
169
168
|
});
|
|
170
|
-
it("should be rejected if opt is not array of string", ()=>{
|
|
169
|
+
it("should be rejected if opt is not array of string", () => {
|
|
171
170
|
return expect(ssh.recv(["src"], "dst", [null])).to.be.rejectedWith("opt must be array of string");
|
|
172
171
|
});
|
|
173
172
|
});
|