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/rsyncExec.js
CHANGED
|
@@ -14,19 +14,19 @@ const exec = util.promisify(require("node:child_process").exec);
|
|
|
14
14
|
* debug.disable();
|
|
15
15
|
**/
|
|
16
16
|
|
|
17
|
-
process.on("unhandledRejection", console.dir); //eslint-disable-line no-console
|
|
17
|
+
process.on("unhandledRejection", console.dir); // eslint-disable-line no-console
|
|
18
18
|
Error.traceLimit = 100000;
|
|
19
19
|
|
|
20
|
-
//setup test framework
|
|
20
|
+
// setup test framework
|
|
21
21
|
const chai = require("chai");
|
|
22
22
|
const { expect } = require("chai");
|
|
23
23
|
chai.use(require("chai-fs"));
|
|
24
24
|
chai.use(require("chai-as-promised"));
|
|
25
25
|
|
|
26
|
-
//testee
|
|
26
|
+
// testee
|
|
27
27
|
const { checkRsyncVersion, send, recv } = require("../lib/rsyncExec.js");
|
|
28
28
|
|
|
29
|
-
//test helpers
|
|
29
|
+
// test helpers
|
|
30
30
|
const { sshExec, disconnect } = require("../lib/sshExec.js");
|
|
31
31
|
const hostInfo = require("./testUtil/hostInfo.js");
|
|
32
32
|
const {
|
|
@@ -42,116 +42,115 @@ const {
|
|
|
42
42
|
remoteFiles
|
|
43
43
|
} = require("./testUtil/testFiles");
|
|
44
44
|
|
|
45
|
-
const formatLsOutput = (array)=>{
|
|
45
|
+
const formatLsOutput = (array) => {
|
|
46
46
|
const rt = [];
|
|
47
47
|
for (const e of array) {
|
|
48
48
|
rt.push(...e.split("\n"));
|
|
49
49
|
}
|
|
50
|
-
return rt.filter((e)=>{
|
|
50
|
+
return rt.filter((e) => {
|
|
51
51
|
return e !== "";
|
|
52
52
|
});
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
describe("test checkRsyncVersion", async ()=>{
|
|
55
|
+
// actual test start from here
|
|
56
|
+
describe("test checkRsyncVersion", async () => {
|
|
58
57
|
const { major, minor, patch } = await checkRsyncVersion(1);
|
|
59
58
|
const versionString = `${major}.${minor}.${patch}`;
|
|
60
|
-
console.log(`==== test with rsync version ${versionString} ====`); //eslint-disable-line no-console
|
|
59
|
+
console.log(`==== test with rsync version ${versionString} ====`); // eslint-disable-line no-console
|
|
61
60
|
const { stdout } = await exec("rsync --version |grep 'version'");
|
|
62
61
|
expect(stdout).to.match(new RegExp(versionString));
|
|
63
62
|
});
|
|
64
63
|
|
|
65
|
-
describe("test rsync exec", function() {
|
|
66
|
-
this.timeout(10000);//eslint-disable-line no-invalid-this
|
|
64
|
+
describe("test rsync exec", function () {
|
|
65
|
+
this.timeout(10000);// eslint-disable-line no-invalid-this
|
|
67
66
|
const rt = [];
|
|
68
|
-
const output = (data)=>{
|
|
67
|
+
const output = (data) => {
|
|
69
68
|
rt.push(data);
|
|
70
69
|
};
|
|
71
70
|
let remoteHome;
|
|
72
|
-
before(async ()=>{
|
|
73
|
-
await sshExec(hostInfo, "pwd", 0, (data)=>{
|
|
71
|
+
before(async () => {
|
|
72
|
+
await sshExec(hostInfo, "pwd", 0, (data) => {
|
|
74
73
|
remoteHome = data.trim();
|
|
75
74
|
});
|
|
76
75
|
});
|
|
77
|
-
beforeEach(async ()=>{
|
|
76
|
+
beforeEach(async () => {
|
|
78
77
|
await clearRemoteTestFiles(hostInfo);
|
|
79
78
|
await createRemoteFiles(hostInfo);
|
|
80
79
|
await clearLocalTestFiles();
|
|
81
80
|
await createLocalFiles();
|
|
82
81
|
rt.splice(0, rt.length);
|
|
83
82
|
});
|
|
84
|
-
after(async ()=>{
|
|
83
|
+
after(async () => {
|
|
85
84
|
if (!process.env.TEST_KEEP_FILES) {
|
|
86
85
|
await clearRemoteTestFiles(hostInfo);
|
|
87
86
|
await clearLocalTestFiles();
|
|
88
87
|
}
|
|
89
88
|
await disconnect(hostInfo);
|
|
90
89
|
});
|
|
91
|
-
describe("#send", async ()=>{
|
|
92
|
-
describe("send single file", ()=>{
|
|
93
|
-
it("should accept relative src file and relative dst dir name", async ()=>{
|
|
90
|
+
describe("#send", async () => {
|
|
91
|
+
describe("send single file", () => {
|
|
92
|
+
it("should accept relative src file and relative dst dir name", async () => {
|
|
94
93
|
await send(hostInfo, [localFiles[0]], remoteEmptyDir, [], 0);
|
|
95
94
|
|
|
96
95
|
await sshExec(hostInfo, `ls ${remoteEmptyDir}`, 0, output);
|
|
97
96
|
expect(formatLsOutput(rt)).to.have.members(["foo"]);
|
|
98
97
|
});
|
|
99
|
-
it("should accept absolute src file and relative dst dir name", async ()=>{
|
|
98
|
+
it("should accept absolute src file and relative dst dir name", async () => {
|
|
100
99
|
await send(hostInfo, [path.resolve(localFiles[3])], remoteEmptyDir, [], 0);
|
|
101
100
|
|
|
102
101
|
await sshExec(hostInfo, `ls ${remoteEmptyDir}`, 0, output);
|
|
103
102
|
expect(formatLsOutput(rt)).to.have.members(["piyo"]);
|
|
104
103
|
});
|
|
105
|
-
it("should accept relative src file and absolute dst dir name", async ()=>{
|
|
104
|
+
it("should accept relative src file and absolute dst dir name", async () => {
|
|
106
105
|
await send(hostInfo, [localFiles[0]], `${path.posix.join(remoteHome, remoteEmptyDir)}/`, [], 0);
|
|
107
106
|
|
|
108
107
|
await sshExec(hostInfo, `ls ${remoteEmptyDir}`, 0, output);
|
|
109
108
|
expect(formatLsOutput(rt)).to.have.members(["foo"]);
|
|
110
109
|
});
|
|
111
|
-
it("should accept absolute src file and absolute dst dir name", async ()=>{
|
|
110
|
+
it("should accept absolute src file and absolute dst dir name", async () => {
|
|
112
111
|
await send(hostInfo, [path.resolve(localFiles[0])], path.posix.join(remoteHome, remoteEmptyDir), [], 0);
|
|
113
112
|
|
|
114
113
|
await sshExec(hostInfo, `ls ${remoteEmptyDir}`, 0, output);
|
|
115
114
|
expect(formatLsOutput(rt)).to.have.members(["foo"]);
|
|
116
115
|
});
|
|
117
|
-
it("should accept relative src file and relative dst file name", async ()=>{
|
|
116
|
+
it("should accept relative src file and relative dst file name", async () => {
|
|
118
117
|
await send(hostInfo, [localFiles[0]], path.posix.join(remoteEmptyDir, "hoge"), [], 0);
|
|
119
118
|
|
|
120
119
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, "hoge")}`, 0, output);
|
|
121
|
-
expect(formatLsOutput(rt.map((e)=>{
|
|
120
|
+
expect(formatLsOutput(rt.map((e) => {
|
|
122
121
|
return path.posix.basename(e);
|
|
123
122
|
}))).to.have.members(["hoge"]);
|
|
124
123
|
});
|
|
125
|
-
it("should accept absolute src file and relative dst file name", async ()=>{
|
|
124
|
+
it("should accept absolute src file and relative dst file name", async () => {
|
|
126
125
|
await send(hostInfo, [path.resolve(localFiles[0])], path.posix.join(remoteEmptyDir, "hoge"), [], 0);
|
|
127
126
|
|
|
128
127
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, "hoge")}`, 0, output);
|
|
129
|
-
expect(formatLsOutput(rt.map((e)=>{
|
|
128
|
+
expect(formatLsOutput(rt.map((e) => {
|
|
130
129
|
return path.posix.basename(e);
|
|
131
130
|
}))).to.have.members(["hoge"]);
|
|
132
131
|
});
|
|
133
|
-
it("should accept relative src file and absolute dst file name", async ()=>{
|
|
132
|
+
it("should accept relative src file and absolute dst file name", async () => {
|
|
134
133
|
await send(hostInfo, [localFiles[0]], path.posix.join(remoteHome, remoteEmptyDir, "hoge"), [], 0);
|
|
135
134
|
|
|
136
135
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, "hoge")}`, 0, output);
|
|
137
|
-
expect(formatLsOutput(rt.map((e)=>{
|
|
136
|
+
expect(formatLsOutput(rt.map((e) => {
|
|
138
137
|
return path.posix.basename(e);
|
|
139
138
|
}))).to.have.members(["hoge"]);
|
|
140
139
|
});
|
|
141
|
-
it("should accept absolute src file and absolute dst file name", async ()=>{
|
|
140
|
+
it("should accept absolute src file and absolute dst file name", async () => {
|
|
142
141
|
await send(hostInfo, [path.resolve(localFiles[0])], path.posix.join(remoteHome, remoteEmptyDir, "hoge"), [], 0);
|
|
143
142
|
|
|
144
143
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, "hoge")}`, 0, output);
|
|
145
|
-
expect(formatLsOutput(rt.map((e)=>{
|
|
144
|
+
expect(formatLsOutput(rt.map((e) => {
|
|
146
145
|
return path.posix.basename(e);
|
|
147
146
|
}))).to.have.members(["hoge"]);
|
|
148
147
|
});
|
|
149
148
|
|
|
150
|
-
it("should overwrite existing file", async ()=>{
|
|
149
|
+
it("should overwrite existing file", async () => {
|
|
151
150
|
const target = path.posix.join(remoteEmptyDir, "hoge");
|
|
152
151
|
await send(hostInfo, [localFiles[0]], target, [], 0);
|
|
153
152
|
await sshExec(hostInfo, `ls ${target}`, 0, output);
|
|
154
|
-
expect(formatLsOutput(rt.map((e)=>{
|
|
153
|
+
expect(formatLsOutput(rt.map((e) => {
|
|
155
154
|
return path.posix.basename(e);
|
|
156
155
|
}))).to.have.members(["hoge"]);
|
|
157
156
|
rt.splice(0, rt.length);
|
|
@@ -161,7 +160,7 @@ describe("test rsync exec", function() {
|
|
|
161
160
|
await fs.utimes(localFiles[1], time, time);
|
|
162
161
|
await send(hostInfo, [localFiles[1]], target, [], 0);
|
|
163
162
|
await sshExec(hostInfo, `ls ${target}`, 0, output);
|
|
164
|
-
expect(formatLsOutput(rt.map((e)=>{
|
|
163
|
+
expect(formatLsOutput(rt.map((e) => {
|
|
165
164
|
return path.posix.basename(e);
|
|
166
165
|
}))).to.have.members(["hoge"]);
|
|
167
166
|
|
|
@@ -170,8 +169,8 @@ describe("test rsync exec", function() {
|
|
|
170
169
|
expect(formatLsOutput(rt)).to.have.members(["ARssh_testLocalDir/bar"]);
|
|
171
170
|
});
|
|
172
171
|
});
|
|
173
|
-
describe("send directory tree", ()=>{
|
|
174
|
-
it("should accept relative src dirname and relative dst dirname", async ()=>{
|
|
172
|
+
describe("send directory tree", () => {
|
|
173
|
+
it("should accept relative src dirname and relative dst dirname", async () => {
|
|
175
174
|
await send(hostInfo, [localRoot], remoteEmptyDir, [], 0);
|
|
176
175
|
|
|
177
176
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, localRoot)}`, 0, output);
|
|
@@ -181,7 +180,7 @@ describe("test rsync exec", function() {
|
|
|
181
180
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, localRoot, "hoge")}`, 0, output);
|
|
182
181
|
expect(formatLsOutput(rt)).to.have.members(["piyo", "puyo", "poyo"]);
|
|
183
182
|
});
|
|
184
|
-
it("should accept absolute src dirname and relative dst dirname", async ()=>{
|
|
183
|
+
it("should accept absolute src dirname and relative dst dirname", async () => {
|
|
185
184
|
await send(hostInfo, [path.resolve(localRoot)], remoteEmptyDir, [], 0);
|
|
186
185
|
|
|
187
186
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, localRoot)}`, 0, output);
|
|
@@ -191,7 +190,7 @@ describe("test rsync exec", function() {
|
|
|
191
190
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, localRoot, "hoge")}`, 0, output);
|
|
192
191
|
expect(formatLsOutput(rt)).to.have.members(["piyo", "puyo", "poyo"]);
|
|
193
192
|
});
|
|
194
|
-
it("should accept relative src dirname and absolute dst dirname", async ()=>{
|
|
193
|
+
it("should accept relative src dirname and absolute dst dirname", async () => {
|
|
195
194
|
await send(hostInfo, [localRoot], path.posix.join(remoteHome, remoteEmptyDir), [], 0);
|
|
196
195
|
|
|
197
196
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, localRoot)}`, 0, output);
|
|
@@ -201,7 +200,7 @@ describe("test rsync exec", function() {
|
|
|
201
200
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, localRoot, "hoge")}`, 0, output);
|
|
202
201
|
expect(formatLsOutput(rt)).to.have.members(["piyo", "puyo", "poyo"]);
|
|
203
202
|
});
|
|
204
|
-
it("should accept absolute src dirname and absolute dst dirname", async ()=>{
|
|
203
|
+
it("should accept absolute src dirname and absolute dst dirname", async () => {
|
|
205
204
|
await send(hostInfo, [path.resolve(localRoot)], path.posix.join(remoteHome, remoteEmptyDir), [], 0);
|
|
206
205
|
|
|
207
206
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, localRoot)}`, 0, output);
|
|
@@ -211,8 +210,8 @@ describe("test rsync exec", function() {
|
|
|
211
210
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, localRoot, "hoge")}`, 0, output);
|
|
212
211
|
expect(formatLsOutput(rt)).to.have.members(["piyo", "puyo", "poyo"]);
|
|
213
212
|
});
|
|
214
|
-
//only option need special treatment in rsyncExec. it's hard to set in WHEEL
|
|
215
|
-
it.skip("[not implemented] should send directory tree if only filter matched", async ()=>{
|
|
213
|
+
// only option need special treatment in rsyncExec. it's hard to set in WHEEL
|
|
214
|
+
it.skip("[not implemented] should send directory tree if only filter matched", async () => {
|
|
216
215
|
await send(hostInfo, [localRoot], remoteEmptyDir, [`--include=${localRoot}`, `--include=${localRoot}/ba*`, `--include=${localRoot}/hoge/*`, "--exclude=*"], [], 0);
|
|
217
216
|
|
|
218
217
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, localRoot)}`, 0, output);
|
|
@@ -222,13 +221,13 @@ describe("test rsync exec", function() {
|
|
|
222
221
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, localRoot, "hoge")}`, 0, output);
|
|
223
222
|
expect(formatLsOutput(rt)).to.have.members(["piyo", "puyo", "poyo"]);
|
|
224
223
|
});
|
|
225
|
-
it("should send directory tree if exclude filter not matched", async ()=>{
|
|
224
|
+
it("should send directory tree if exclude filter not matched", async () => {
|
|
226
225
|
await send(hostInfo, [localRoot], remoteEmptyDir, ["--exclude=ba*", "--exclude=hoge*}"], [], 0);
|
|
227
226
|
|
|
228
227
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, localRoot)}`, 0, output);
|
|
229
228
|
expect(formatLsOutput(rt)).to.have.members(["foo", "hoge", "huga"]);
|
|
230
229
|
});
|
|
231
|
-
it.skip("[not implemented] should send directory tree if only filter matched but exclude filter not matched", async ()=>{
|
|
230
|
+
it.skip("[not implemented] should send directory tree if only filter matched but exclude filter not matched", async () => {
|
|
232
231
|
await send(hostInfo, [localRoot], remoteEmptyDir, "*/{ba*,hoge/*}", "**/poyo", [], 0);
|
|
233
232
|
|
|
234
233
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, localRoot)}`, 0, output);
|
|
@@ -238,96 +237,96 @@ describe("test rsync exec", function() {
|
|
|
238
237
|
await sshExec(hostInfo, `ls ${path.posix.join(remoteEmptyDir, localRoot, "hoge")}`, 0, output);
|
|
239
238
|
expect(formatLsOutput(rt)).to.have.members(["piyo", "puyo"]);
|
|
240
239
|
});
|
|
241
|
-
it("shoud not send empty directory with -m option", async ()=>{
|
|
240
|
+
it("shoud not send empty directory with -m option", async () => {
|
|
242
241
|
await send(hostInfo, [localEmptyDir], remoteEmptyDir, ["-m"], [], 0);
|
|
243
242
|
|
|
244
243
|
await sshExec(hostInfo, `ls ${remoteEmptyDir}`, 0, output);
|
|
245
244
|
expect(rt).to.have.lengthOf(0);
|
|
246
245
|
});
|
|
247
|
-
it("should send files which match glob pattern", async ()=>{
|
|
246
|
+
it("should send files which match glob pattern", async () => {
|
|
248
247
|
await send(hostInfo, [path.join(localRoot, "b*")], remoteEmptyDir, [], 0);
|
|
249
248
|
|
|
250
249
|
await sshExec(hostInfo, `ls ${remoteEmptyDir}`, 0, output);
|
|
251
250
|
expect(formatLsOutput(rt)).to.have.members(["bar", "baz"]);
|
|
252
251
|
});
|
|
253
252
|
});
|
|
254
|
-
describe("error case", ()=>{
|
|
255
|
-
it("should not send directory to existing file path", ()=>{
|
|
253
|
+
describe("error case", () => {
|
|
254
|
+
it("should not send directory to existing file path", () => {
|
|
256
255
|
return expect(send(hostInfo, [localRoot], path.posix.join(remoteRoot, "foo"), [], 0)).to.be.rejected;
|
|
257
256
|
});
|
|
258
257
|
});
|
|
259
258
|
});
|
|
260
|
-
describe("#recv", async ()=>{
|
|
261
|
-
describe("recieve single file", ()=>{
|
|
262
|
-
it("should accept relative src file and relative dst dir name", async ()=>{
|
|
259
|
+
describe("#recv", async () => {
|
|
260
|
+
describe("recieve single file", () => {
|
|
261
|
+
it("should accept relative src file and relative dst dir name", async () => {
|
|
263
262
|
await recv(hostInfo, [remoteFiles[3]], localEmptyDir, [], 0);
|
|
264
263
|
|
|
265
264
|
const rt2 = await fs.readdir(localEmptyDir);
|
|
266
265
|
expect(rt2).to.have.members(["piyo"]);
|
|
267
266
|
});
|
|
268
|
-
it("should accept absolute src file and relative dst dir name", async ()=>{
|
|
267
|
+
it("should accept absolute src file and relative dst dir name", async () => {
|
|
269
268
|
await recv(hostInfo, [path.posix.join(remoteHome, remoteFiles[3])], localEmptyDir, [], 0);
|
|
270
269
|
|
|
271
270
|
const rt2 = await fs.readdir(localEmptyDir);
|
|
272
271
|
expect(rt2).to.have.members(["piyo"]);
|
|
273
272
|
});
|
|
274
|
-
it("should accept relative src file and absolute dst dir name", async ()=>{
|
|
273
|
+
it("should accept relative src file and absolute dst dir name", async () => {
|
|
275
274
|
await recv(hostInfo, [remoteFiles[3]], path.resolve(localEmptyDir), [], 0);
|
|
276
275
|
|
|
277
276
|
const rt2 = await fs.readdir(localEmptyDir);
|
|
278
277
|
expect(rt2).to.have.members(["piyo"]);
|
|
279
278
|
});
|
|
280
|
-
it("should accept absolute src file and absolute dst dir name", async ()=>{
|
|
279
|
+
it("should accept absolute src file and absolute dst dir name", async () => {
|
|
281
280
|
await recv(hostInfo, [path.posix.join(remoteHome, remoteFiles[3])], path.resolve(localEmptyDir), [], 0);
|
|
282
281
|
|
|
283
282
|
const rt2 = await fs.readdir(localEmptyDir);
|
|
284
283
|
expect(rt2).to.have.members(["piyo"]);
|
|
285
284
|
});
|
|
286
|
-
it("should accept relative src file and relative dst file name", async ()=>{
|
|
285
|
+
it("should accept relative src file and relative dst file name", async () => {
|
|
287
286
|
await recv(hostInfo, [remoteFiles[0]], path.join(localEmptyDir, "hoge"), [], 0);
|
|
288
287
|
|
|
289
288
|
const rt2 = await fs.readdir(localEmptyDir);
|
|
290
289
|
expect(rt2).to.have.members(["hoge"]);
|
|
291
290
|
});
|
|
292
|
-
it("should accept absolute src file and relative dst file name", async ()=>{
|
|
291
|
+
it("should accept absolute src file and relative dst file name", async () => {
|
|
293
292
|
await recv(hostInfo, [path.posix.join(remoteHome, remoteFiles[0])], path.join(localEmptyDir, "hoge"), [], 0);
|
|
294
293
|
|
|
295
294
|
const rt2 = await fs.readdir(localEmptyDir);
|
|
296
295
|
expect(rt2).to.have.members(["hoge"]);
|
|
297
296
|
});
|
|
298
|
-
it("should accept relative src file and absolute dst file name", async ()=>{
|
|
297
|
+
it("should accept relative src file and absolute dst file name", async () => {
|
|
299
298
|
await recv(hostInfo, [remoteFiles[0]], path.resolve(localEmptyDir, "hoge"), [], 0);
|
|
300
299
|
|
|
301
300
|
const rt2 = await fs.readdir(localEmptyDir);
|
|
302
301
|
expect(rt2).to.have.members(["hoge"]);
|
|
303
302
|
});
|
|
304
|
-
it("should accept absolute src file and absolute dst file name", async ()=>{
|
|
303
|
+
it("should accept absolute src file and absolute dst file name", async () => {
|
|
305
304
|
await recv(hostInfo, [path.posix.join(remoteHome, remoteFiles[0])], path.resolve(localEmptyDir, "hoge"), [], 0);
|
|
306
305
|
|
|
307
306
|
const rt2 = await fs.readdir(localEmptyDir);
|
|
308
307
|
expect(rt2).to.have.members(["hoge"]);
|
|
309
308
|
});
|
|
310
|
-
it("should accept glob pattern as src", async ()=>{
|
|
309
|
+
it("should accept glob pattern as src", async () => {
|
|
311
310
|
await recv(hostInfo, [path.posix.join(remoteRoot, "b*")], path.resolve(localEmptyDir), [], 0);
|
|
312
311
|
|
|
313
312
|
const rt2 = await fs.readdir(localEmptyDir);
|
|
314
313
|
expect(rt2).to.have.members(["bar", "baz"]);
|
|
315
314
|
});
|
|
316
|
-
it("should accept glob pattern as src", async ()=>{
|
|
315
|
+
it("should accept glob pattern as src", async () => {
|
|
317
316
|
await recv(hostInfo, [path.posix.join(remoteRoot, "*/p[iu]yo")], path.resolve(localEmptyDir), [], 0);
|
|
318
317
|
|
|
319
318
|
const rt2 = await fs.readdir(localEmptyDir);
|
|
320
319
|
expect(rt2).to.have.members(["piyo", "puyo"]);
|
|
321
320
|
});
|
|
322
|
-
it.skip("[temporarily disabled number 23 was thrown] should accept glob pattern as src", async ()=>{
|
|
321
|
+
it.skip("[temporarily disabled number 23 was thrown] should accept glob pattern as src", async () => {
|
|
323
322
|
await recv(hostInfo, [path.posix.join(remoteRoot, "hoge/p[iu]yo"), path.posix.join(remoteRoot, "foo")], path.resolve(localEmptyDir), [], 0);
|
|
324
323
|
|
|
325
324
|
const rt2 = await fs.readdir(localEmptyDir);
|
|
326
325
|
expect(rt2).to.have.members(["piyo", "puyo", "foo"]);
|
|
327
326
|
});
|
|
328
327
|
});
|
|
329
|
-
describe("recieve directory tree", ()=>{
|
|
330
|
-
it("should get directory tree which match specified glob", async ()=>{
|
|
328
|
+
describe("recieve directory tree", () => {
|
|
329
|
+
it("should get directory tree which match specified glob", async () => {
|
|
331
330
|
await recv(hostInfo, [path.posix.join(remoteRoot, "?o*")], localEmptyDir, [], 0);
|
|
332
331
|
|
|
333
332
|
let rt2 = await fs.readdir(localEmptyDir);
|
|
@@ -335,7 +334,7 @@ describe("test rsync exec", function() {
|
|
|
335
334
|
rt2 = await fs.readdir(path.join(localEmptyDir, "hoge"));
|
|
336
335
|
expect(rt2).to.have.members(["piyo", "puyo", "poyo"]);
|
|
337
336
|
});
|
|
338
|
-
it("should accept relative src dirname and relative dst dirname", async ()=>{
|
|
337
|
+
it("should accept relative src dirname and relative dst dirname", async () => {
|
|
339
338
|
await recv(hostInfo, [remoteRoot], localEmptyDir, [], 0);
|
|
340
339
|
|
|
341
340
|
let rt2 = await fs.readdir(path.posix.join(localEmptyDir, remoteRoot));
|
|
@@ -343,7 +342,7 @@ describe("test rsync exec", function() {
|
|
|
343
342
|
rt2 = await fs.readdir(path.join(localEmptyDir, remoteRoot, "hoge"));
|
|
344
343
|
expect(rt2).to.have.members(["piyo", "puyo", "poyo"]);
|
|
345
344
|
});
|
|
346
|
-
it("should accept absolute src dirname and relative dst dirname", async ()=>{
|
|
345
|
+
it("should accept absolute src dirname and relative dst dirname", async () => {
|
|
347
346
|
await recv(hostInfo, [path.posix.join(remoteHome, remoteRoot)], localEmptyDir, [], 0);
|
|
348
347
|
|
|
349
348
|
let rt2 = await fs.readdir(path.posix.join(localEmptyDir, remoteRoot));
|
|
@@ -351,7 +350,7 @@ describe("test rsync exec", function() {
|
|
|
351
350
|
rt2 = await fs.readdir(path.join(localEmptyDir, remoteRoot, "hoge"));
|
|
352
351
|
expect(rt2).to.have.members(["piyo", "puyo", "poyo"]);
|
|
353
352
|
});
|
|
354
|
-
it("should accept relative src dirname and absolute dst dirname", async ()=>{
|
|
353
|
+
it("should accept relative src dirname and absolute dst dirname", async () => {
|
|
355
354
|
await recv(hostInfo, [remoteRoot], path.resolve(localEmptyDir), [], 0);
|
|
356
355
|
|
|
357
356
|
let rt2 = await fs.readdir(path.posix.join(localEmptyDir, remoteRoot));
|
|
@@ -359,7 +358,7 @@ describe("test rsync exec", function() {
|
|
|
359
358
|
rt2 = await fs.readdir(path.join(localEmptyDir, remoteRoot, "hoge"));
|
|
360
359
|
expect(rt2).to.have.members(["piyo", "puyo", "poyo"]);
|
|
361
360
|
});
|
|
362
|
-
it("should accept absolute src dirname and absolute dst dirname", async ()=>{
|
|
361
|
+
it("should accept absolute src dirname and absolute dst dirname", async () => {
|
|
363
362
|
await recv(hostInfo, [path.posix.join(remoteHome, remoteRoot)], path.resolve(localEmptyDir), [], 0);
|
|
364
363
|
|
|
365
364
|
let rt2 = await fs.readdir(path.posix.join(localEmptyDir, remoteRoot));
|
|
@@ -367,7 +366,7 @@ describe("test rsync exec", function() {
|
|
|
367
366
|
rt2 = await fs.readdir(path.join(localEmptyDir, remoteRoot, "hoge"));
|
|
368
367
|
expect(rt2).to.have.members(["piyo", "puyo", "poyo"]);
|
|
369
368
|
});
|
|
370
|
-
it.skip("[not implemented] should recv files which matches only filter", async ()=>{
|
|
369
|
+
it.skip("[not implemented] should recv files which matches only filter", async () => {
|
|
371
370
|
await recv(hostInfo, [remoteRoot], localEmptyDir, "*/{ba*,hoge/*}", [], 0);
|
|
372
371
|
|
|
373
372
|
let rt2 = await fs.readdir(path.posix.join(localEmptyDir, remoteRoot));
|
|
@@ -375,13 +374,13 @@ describe("test rsync exec", function() {
|
|
|
375
374
|
rt2 = await fs.readdir(path.join(localEmptyDir, remoteRoot, "hoge"));
|
|
376
375
|
expect(rt2).to.have.members(["piyo", "puyo", "poyo"]);
|
|
377
376
|
});
|
|
378
|
-
it("should not recv files which matches exclude filter", async ()=>{
|
|
377
|
+
it("should not recv files which matches exclude filter", async () => {
|
|
379
378
|
await recv(hostInfo, [remoteRoot], localEmptyDir, ["--exclude=*/ba*", "--exclude=hoge"], [], 0);
|
|
380
379
|
|
|
381
380
|
const rt2 = await fs.readdir(path.posix.join(localEmptyDir, remoteRoot));
|
|
382
381
|
expect(rt2).to.have.members(["foo", "huga"]);
|
|
383
382
|
});
|
|
384
|
-
it.skip("[not implemented] should recv files which matches only filter but should not recv which matches exclude filter", async ()=>{
|
|
383
|
+
it.skip("[not implemented] should recv files which matches only filter but should not recv which matches exclude filter", async () => {
|
|
385
384
|
await recv(hostInfo, [remoteRoot], localEmptyDir, "*/{ba*,hoge/*}", "**/piyo", [], 0);
|
|
386
385
|
|
|
387
386
|
let rt2 = await fs.readdir(path.posix.join(localEmptyDir, remoteRoot));
|
|
@@ -390,16 +389,16 @@ describe("test rsync exec", function() {
|
|
|
390
389
|
expect(rt2).to.have.members(["puyo", "poyo"]);
|
|
391
390
|
});
|
|
392
391
|
});
|
|
393
|
-
describe("degradation check", ()=>{
|
|
394
|
-
it("should recieve multiple files from remote machine", async ()=>{
|
|
392
|
+
describe("degradation check", () => {
|
|
393
|
+
it("should recieve multiple files from remote machine", async () => {
|
|
395
394
|
await recv(hostInfo, [path.posix.join(remoteRoot, "foo"),
|
|
396
395
|
path.posix.join(remoteRoot, "bar"), path.posix.join(remoteRoot, "baz")], localEmptyDir, [], 0);
|
|
397
396
|
const rt2 = await fs.readdir(localEmptyDir);
|
|
398
397
|
expect(rt2).to.have.members(["foo", "bar", "baz"]);
|
|
399
398
|
});
|
|
400
399
|
});
|
|
401
|
-
describe("error case", ()=>{
|
|
402
|
-
it("should not send directory to existing file path", ()=>{
|
|
400
|
+
describe("error case", () => {
|
|
401
|
+
it("should not send directory to existing file path", () => {
|
|
403
402
|
return expect(recv(hostInfo, [remoteRoot], localFiles[0], [], 0)).to.be.rejected;
|
|
404
403
|
});
|
|
405
404
|
});
|
package/test/sshExec.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const path = require("path");
|
|
3
3
|
|
|
4
|
-
process.on("unhandledRejection", console.dir); //eslint-disable-line no-console
|
|
4
|
+
process.on("unhandledRejection", console.dir); // eslint-disable-line no-console
|
|
5
5
|
Error.traceLimit = 100000;
|
|
6
6
|
|
|
7
|
-
//setup test framework
|
|
7
|
+
// setup test framework
|
|
8
8
|
const chai = require("chai");
|
|
9
9
|
const { expect } = require("chai");
|
|
10
10
|
const sinon = require("sinon");
|
|
@@ -13,126 +13,126 @@ chai.use(require("chai-as-promised"));
|
|
|
13
13
|
|
|
14
14
|
const sshout = sinon.stub();
|
|
15
15
|
|
|
16
|
-
//testee
|
|
16
|
+
// testee
|
|
17
17
|
const { sshExec, canConnect, disconnect, ls } = require("../lib/sshExec.js");
|
|
18
18
|
|
|
19
|
-
//test helpers
|
|
19
|
+
// test helpers
|
|
20
20
|
const hostInfo = require("./testUtil/hostInfo.js");
|
|
21
21
|
const { clearRemoteTestFiles, clearLocalTestFiles, createRemoteFiles, nonExisting, remoteRoot, remoteEmptyDir } = require("./testUtil/testFiles.js");
|
|
22
22
|
|
|
23
|
-
describe("test for ssh execution", function() {
|
|
24
|
-
this.timeout(65000);//eslint-disable-line no-invalid-this
|
|
25
|
-
beforeEach(async ()=>{
|
|
23
|
+
describe("test for ssh execution", function () {
|
|
24
|
+
this.timeout(65000);// eslint-disable-line no-invalid-this
|
|
25
|
+
beforeEach(async () => {
|
|
26
26
|
sshout.reset();
|
|
27
27
|
await clearRemoteTestFiles(hostInfo);
|
|
28
28
|
});
|
|
29
|
-
after(async ()=>{
|
|
29
|
+
after(async () => {
|
|
30
30
|
if (!process.env.TEST_KEEP_FILES) {
|
|
31
31
|
await clearRemoteTestFiles(hostInfo);
|
|
32
32
|
await clearLocalTestFiles();
|
|
33
33
|
}
|
|
34
34
|
await disconnect(hostInfo);
|
|
35
35
|
});
|
|
36
|
-
describe("#exec", ()=>{
|
|
36
|
+
describe("#exec", () => {
|
|
37
37
|
const testText = "hoge";
|
|
38
|
-
it("should execute single command with stdout", async ()=>{
|
|
38
|
+
it("should execute single command with stdout", async () => {
|
|
39
39
|
const rt = await sshExec(hostInfo, `echo ${testText}`, 0, sshout);
|
|
40
40
|
expect(rt).to.equal(0);
|
|
41
41
|
expect(sshout).to.be.called;
|
|
42
42
|
|
|
43
43
|
expect(sshout).to.be.calledWithMatch(/^hoge/);
|
|
44
44
|
});
|
|
45
|
-
it("should execute single command with stderr", async ()=>{
|
|
45
|
+
it("should execute single command with stderr", async () => {
|
|
46
46
|
const rt = await sshExec(hostInfo, `echo ${testText} >&2`, 0, sshout);
|
|
47
47
|
expect(rt).to.equal(0);
|
|
48
48
|
expect(sshout).to.be.called;
|
|
49
49
|
expect(sshout).to.be.calledWithMatch(/^hoge/);
|
|
50
50
|
});
|
|
51
|
-
//please note that exec() resolves with non-zero value
|
|
52
|
-
//(126 permisssion deny or 127 file not found)
|
|
53
|
-
//but does not reject in following 2 cases
|
|
54
|
-
it("should not execute command which do not have exec permission", async ()=>{
|
|
51
|
+
// please note that exec() resolves with non-zero value
|
|
52
|
+
// (126 permisssion deny or 127 file not found)
|
|
53
|
+
// but does not reject in following 2 cases
|
|
54
|
+
it("should not execute command which do not have exec permission", async () => {
|
|
55
55
|
await sshExec(hostInfo, "echo echo hoge >hoge");
|
|
56
56
|
await sshExec(hostInfo, "chmod ugo-x hoge");
|
|
57
57
|
const rt = await sshExec(hostInfo, "./hoge");
|
|
58
58
|
expect(rt).to.equal(126);
|
|
59
59
|
});
|
|
60
|
-
it("should resolve with 127 if command is not found", async ()=>{
|
|
60
|
+
it("should resolve with 127 if command is not found", async () => {
|
|
61
61
|
const rt = await sshExec(hostInfo, `./${nonExisting}`);
|
|
62
62
|
expect(rt).to.equal(127);
|
|
63
63
|
});
|
|
64
|
-
it("should be rejected if timeout expired", async ()=>{
|
|
64
|
+
it("should be rejected if timeout expired", async () => {
|
|
65
65
|
return expect(sshExec(hostInfo, "sleep 60", 1)).to.be.rejectedWith("watchdog timer expired");
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
|
-
describe("#canConnect", ()=>{
|
|
68
|
+
describe("#canConnect", () => {
|
|
69
69
|
let hostInfo2;
|
|
70
|
-
beforeEach(async ()=>{
|
|
70
|
+
beforeEach(async () => {
|
|
71
71
|
await disconnect(hostInfo);
|
|
72
72
|
hostInfo2 = { ...hostInfo };
|
|
73
73
|
hostInfo2.masterPty = null;
|
|
74
74
|
});
|
|
75
|
-
afterEach(async ()=>{
|
|
75
|
+
afterEach(async () => {
|
|
76
76
|
await disconnect(hostInfo2);
|
|
77
77
|
});
|
|
78
|
-
it("should be resolved with true", async ()=>{
|
|
78
|
+
it("should be resolved with true", async () => {
|
|
79
79
|
return expect(await canConnect(hostInfo2, 5)).to.be.true;
|
|
80
80
|
});
|
|
81
|
-
it("should be rejected if user does not exist", async ()=>{
|
|
81
|
+
it("should be rejected if user does not exist", async () => {
|
|
82
82
|
hostInfo2.user = "xxxx";
|
|
83
83
|
return expect(canConnect(hostInfo2, 2)).to.be.rejected;
|
|
84
84
|
});
|
|
85
|
-
it("should be rejected if password is wrong", async ()=>{
|
|
85
|
+
it("should be rejected if password is wrong", async () => {
|
|
86
86
|
hostInfo2.password = "xxxx";
|
|
87
87
|
return expect(canConnect(hostInfo2, 2)).to.be.rejected;
|
|
88
88
|
});
|
|
89
|
-
it("should be rejected if host does not exist", async ()=>{
|
|
89
|
+
it("should be rejected if host does not exist", async () => {
|
|
90
90
|
hostInfo2.host = "foo.bar.example.com";
|
|
91
91
|
return expect(canConnect(hostInfo2, 2)).to.be.rejectedWith(255);
|
|
92
92
|
});
|
|
93
|
-
it("should be rejected if host(ip address) does not exist", async ()=>{
|
|
93
|
+
it("should be rejected if host(ip address) does not exist", async () => {
|
|
94
94
|
hostInfo2.host = "192.0.2.1";
|
|
95
|
-
hostInfo2.ConnectTimeout = 8; //please note each test will be timed out in 20 seconds
|
|
95
|
+
hostInfo2.ConnectTimeout = 8; // please note each test will be timed out in 20 seconds
|
|
96
96
|
return expect(canConnect(hostInfo2, 2)).to.be.rejectedWith(255);
|
|
97
97
|
});
|
|
98
|
-
it("should be rejected if port number is out of range(-1)", async ()=>{
|
|
98
|
+
it("should be rejected if port number is out of range(-1)", async () => {
|
|
99
99
|
hostInfo2.port = -1;
|
|
100
100
|
return expect(canConnect(hostInfo2, 2)).to.be.rejectedWith("invalid port specified -1");
|
|
101
101
|
});
|
|
102
|
-
it("should be rejected if port number is out of range(65536)", async ()=>{
|
|
102
|
+
it("should be rejected if port number is out of range(65536)", async () => {
|
|
103
103
|
hostInfo2.port = 65536;
|
|
104
104
|
return expect(canConnect(hostInfo2, 2)).to.be.rejectedWith("invalid port specified 65536");
|
|
105
105
|
});
|
|
106
106
|
});
|
|
107
|
-
describe("#ls", ()=>{
|
|
108
|
-
beforeEach(async ()=>{
|
|
107
|
+
describe("#ls", () => {
|
|
108
|
+
beforeEach(async () => {
|
|
109
109
|
await createRemoteFiles(hostInfo);
|
|
110
110
|
});
|
|
111
|
-
it("should return array of file and directory names in the specified directory", async ()=>{
|
|
111
|
+
it("should return array of file and directory names in the specified directory", async () => {
|
|
112
112
|
expect(await ls(hostInfo, remoteRoot, [], 0)).to.have.members(["foo", "bar", "baz", "hoge", "huga"]);
|
|
113
113
|
});
|
|
114
|
-
it("should return array which has only specified file", async ()=>{
|
|
114
|
+
it("should return array which has only specified file", async () => {
|
|
115
115
|
expect(await ls(hostInfo, path.posix.join(remoteRoot, "foo"), [], 0)).to.eql([path.posix.join(remoteRoot, "foo")]);
|
|
116
116
|
});
|
|
117
|
-
it("should return 'No such file or directory' if non-existing path is specified", async ()=>{
|
|
117
|
+
it("should return 'No such file or directory' if non-existing path is specified", async () => {
|
|
118
118
|
expect(await ls(hostInfo, path.posix.join(remoteRoot, nonExisting), [], 0)).to.match(/No such file or directory/);
|
|
119
119
|
});
|
|
120
|
-
it("should return only matched filenames, if glob is specified", async ()=>{
|
|
121
|
-
expect(await ls(hostInfo, path.posix.join(remoteRoot, "b*"), [], 0)).to.have.members(["bar", "baz"].map((e)=>{
|
|
120
|
+
it("should return only matched filenames, if glob is specified", async () => {
|
|
121
|
+
expect(await ls(hostInfo, path.posix.join(remoteRoot, "b*"), [], 0)).to.have.members(["bar", "baz"].map((e) => {
|
|
122
122
|
return path.posix.join(remoteRoot, e);
|
|
123
123
|
}));
|
|
124
124
|
});
|
|
125
|
-
it("should return only matched filenames src contains multipl glob pattern", async ()=>{
|
|
126
|
-
expect(await ls(hostInfo, path.posix.join(remoteRoot, "h*", "p[iu]yo"), [], 0)).to.have.members(["piyo", "puyo"].map((e)=>{
|
|
125
|
+
it("should return only matched filenames src contains multipl glob pattern", async () => {
|
|
126
|
+
expect(await ls(hostInfo, path.posix.join(remoteRoot, "h*", "p[iu]yo"), [], 0)).to.have.members(["piyo", "puyo"].map((e) => {
|
|
127
127
|
return path.posix.join(remoteRoot, "hoge", e);
|
|
128
128
|
}));
|
|
129
129
|
});
|
|
130
|
-
it("should return only matched filenames, if specified glob contains /", async ()=>{
|
|
131
|
-
expect(await ls(hostInfo, path.posix.join(remoteRoot, "hoge/*yo"), [], 0)).to.have.members(["piyo", "puyo", "poyo"].map((e)=>{
|
|
130
|
+
it("should return only matched filenames, if specified glob contains /", async () => {
|
|
131
|
+
expect(await ls(hostInfo, path.posix.join(remoteRoot, "hoge/*yo"), [], 0)).to.have.members(["piyo", "puyo", "poyo"].map((e) => {
|
|
132
132
|
return path.posix.join(remoteRoot, "hoge", e);
|
|
133
133
|
}));
|
|
134
134
|
});
|
|
135
|
-
it("should return empty array if specified target is empty directory", async ()=>{
|
|
135
|
+
it("should return empty array if specified target is empty directory", async () => {
|
|
136
136
|
expect(await ls(hostInfo, remoteEmptyDir, [], 0)).to.be.an("array").that.is.empty;
|
|
137
137
|
});
|
|
138
138
|
});
|