ssh-client-wrapper 2.11.0 → 2.12.4

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/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,43 +11,44 @@ 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();
18
18
  const canConnect = sinon.stub();
19
19
  const disconnect = sinon.stub();
20
- const ls = sinon.stub();
21
20
  const send = sinon.stub();
22
21
  const recv = sinon.stub();
23
22
 
24
- // eslint-disable-next-line no-underscore-dangle
23
+ //eslint-disable-next-line no-underscore-dangle
25
24
  SshClientWrapper.__set__({
26
- sshExec, canConnect, disconnect, ls, send, recv
25
+ sshExec, canConnect, disconnect, send, recv, expect
27
26
  });
28
27
 
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
28
+ describe("test for interface", ()=>{
29
+ describe("test for constructor", ()=>{
30
+ it("should throw error when instanciate with non-empty string host", ()=>{
31
+ expect(()=>{
32
+ //eslint-disable-next-line no-new
34
33
  new SshClientWrapper({});
35
34
  }).to.throw("host is required");
36
- expect(() => {
37
- // eslint-disable-next-line no-new
35
+ expect(()=>{
36
+ //eslint-disable-next-line no-new
38
37
  new SshClientWrapper({ host: "" });
39
38
  }).to.throw("empty host is not allowed");
40
39
  });
41
- it("should successfully instanciate only with host prop", () => {
40
+ it("should successfully instanciate only with host prop", ()=>{
42
41
  expect(new SshClientWrapper({ host: "hoge" })).to.have.property("exec");
42
+ expect(new SshClientWrapper({ host: "hoge" })).to.have.property("execAndGetOutput");
43
43
  expect(new SshClientWrapper({ host: "hoge" })).to.have.property("ls");
44
+ expect(new SshClientWrapper({ host: "hoge" })).to.have.property("expect");
44
45
  expect(new SshClientWrapper({ host: "hoge" })).to.have.property("send");
45
46
  expect(new SshClientWrapper({ host: "hoge" })).to.have.property("recv");
46
47
  expect(new SshClientWrapper({ host: "hoge" })).to.have.property("canConnect");
47
48
  expect(new SshClientWrapper({ host: "hoge" })).to.have.property("disconnect");
48
49
  });
49
50
  });
50
- describe("test for public method", () => {
51
+ describe("test for public method", ()=>{
51
52
  let ssh;
52
53
  const hostInfoOrg = {
53
54
  host: "hoge",
@@ -56,122 +57,121 @@ describe("test for interface", () => {
56
57
  retryDuration: 1000
57
58
  };
58
59
  const hostInfo = { ...hostInfoOrg, masterPty: null, rsyncVersion: null };
59
- beforeEach(() => {
60
+ beforeEach(()=>{
60
61
  ssh = new SshClientWrapper(hostInfoOrg);
61
62
  sshExec.reset();
62
63
  canConnect.reset();
63
64
  disconnect.reset();
64
- ls.reset();
65
65
  send.reset();
66
66
  recv.reset();
67
67
  });
68
- describe("test for exec", () => {
69
- it("should call sshExec with cmd", () => {
68
+ describe("test for exec", ()=>{
69
+ it("should call sshExec with cmd", ()=>{
70
70
  ssh.exec("ls");
71
71
  expect(sshExec).to.be.calledWith(hostInfo, "ls", 0, null);
72
72
  });
73
- it("should call sshExec with cmd and timeout", () => {
73
+ it("should call sshExec with cmd and timeout", ()=>{
74
74
  ssh.exec("ls", 10);
75
75
  expect(sshExec).to.be.calledWith(hostInfo, "ls", 10, null);
76
76
  });
77
- it("should call sshExec with cmd, timeout and call back function", () => {
78
- const cb = () => {};
77
+ it("should call sshExec with cmd, timeout and call back function", ()=>{
78
+ const cb = ()=>{};
79
79
  ssh.exec("ls", 10, cb);
80
80
  expect(sshExec).to.be.calledWith(hostInfo, "ls", 10, cb);
81
81
  });
82
- it("should reject if cmd is not string (number)", () => {
82
+ it("should reject if cmd is not string (number)", ()=>{
83
83
  return expect(ssh.exec(0)).to.be.rejectedWith("cmd must be string");
84
84
  });
85
- it("should reject if cmd is not string (null)", () => {
85
+ it("should reject if cmd is not string (null)", ()=>{
86
86
  return expect(ssh.exec(null)).to.be.rejectedWith("cmd must be string");
87
87
  });
88
- it("should reject if cmd is empty string", () => {
88
+ it("should reject if cmd is empty string", ()=>{
89
89
  return expect(ssh.exec("")).to.be.rejectedWith("cmd must be string");
90
90
  });
91
91
  });
92
- describe("test for ls", () => {
93
- it("should call ls without timeout", () => {
92
+ describe("test for ls", ()=>{
93
+ it("should call ls without timeout", ()=>{
94
94
  ssh.ls("hoge");
95
- expect(ls).to.be.calledWith(hostInfo, "hoge", [], 0);
95
+ expect(sshExec).to.be.calledWith(hostInfo, "ls hoge", 0);
96
96
  });
97
- it("should call ls with option", () => {
97
+ it("should call ls with option", ()=>{
98
98
  ssh.ls("hoge", ["-l", "-r", "-t"]);
99
- expect(ls).to.be.calledWith(hostInfo, "hoge", ["-l", "-r", "-t"], 0);
99
+ expect(sshExec).to.be.calledWith(hostInfo, "ls -l -r -t hoge", 0);
100
100
  });
101
- it("should call ls with option and timeout", () => {
101
+ it("should call ls with option and timeout", ()=>{
102
102
  ssh.ls("hoge", ["-l", "-r", "-t"], 10);
103
- expect(ls).to.be.calledWith(hostInfo, "hoge", ["-l", "-r", "-t"], 10);
103
+ expect(sshExec).to.be.calledWith(hostInfo, "ls -l -r -t hoge", 10);
104
104
  });
105
105
  });
106
- describe("test for send", () => {
107
- it("should call send with src and dst", () => {
106
+ describe("test for send", ()=>{
107
+ it("should call send with src and dst", ()=>{
108
108
  ssh.send(["src"], "dst");
109
109
  expect(send).to.be.calledWith(hostInfo, ["src"], "dst", [], 0);
110
110
  });
111
- it("should call send with src, dst, and opt", () => {
111
+ it("should call send with src, dst, and opt", ()=>{
112
112
  ssh.send(["src"], "dst", ["--dry-run", "--delete"]);
113
113
  expect(send).to.be.calledWith(hostInfo, ["src"], "dst", ["--dry-run", "--delete"], 0);
114
114
  });
115
- it("should call send with src, dst, opt, and timeout", () => {
115
+ it("should call send with src, dst, opt, and timeout", ()=>{
116
116
  ssh.send(["src"], "dst", ["--dry-run", "--delete"], 10);
117
117
  expect(send).to.be.calledWith(hostInfo, ["src"], "dst", ["--dry-run", "--delete"], 10);
118
118
  });
119
- it("should be rejected if src is not array of string", () => {
119
+ it("should be rejected if src is not array of string", ()=>{
120
120
  return expect(ssh.send(1)).to.be.rejectedWith("src must be array of string");
121
121
  });
122
- it("should be rejected if src has only empty string element", () => {
122
+ it("should be rejected if src has only empty string element", ()=>{
123
123
  return expect(ssh.send(["", ""])).to.be.rejectedWith("src must contain non-empty string");
124
124
  });
125
- it("should be rejected if src has only empty string element", () => {
125
+ it("should be rejected if src has only empty string element", ()=>{
126
126
  return expect(ssh.send([""])).to.be.rejectedWith("src must contain non-empty string");
127
127
  });
128
- it("should be called if src includes empty string ", () => {
128
+ it("should be called if src includes empty string ", ()=>{
129
129
  ssh.send(["src", ""], "dst");
130
130
  expect(send).to.be.calledWith(hostInfo, ["src", ""], "dst", [], 0);
131
131
  });
132
- it("should be rejected if dst is not string", () => {
132
+ it("should be rejected if dst is not string", ()=>{
133
133
  return expect(ssh.send(["src"], 0)).to.be.rejectedWith("dst must be string");
134
134
  });
135
- it("should be rejected if dst is empty string", () => {
135
+ it("should be rejected if dst is empty string", ()=>{
136
136
  return expect(ssh.send(["src"], "")).to.be.rejectedWith("dst must be non-empty string");
137
137
  });
138
- it("should be rejected if opt is not array of string", () => {
138
+ it("should be rejected if opt is not array of string", ()=>{
139
139
  return expect(ssh.send(["src"], "dst", [null])).to.be.rejectedWith("opt must be array of string");
140
140
  });
141
141
  });
142
- describe("test for recv", () => {
143
- it("should call recv with src and dst", () => {
142
+ describe("test for recv", ()=>{
143
+ it("should call recv with src and dst", ()=>{
144
144
  ssh.recv(["src"], "dst");
145
145
  expect(recv).to.be.calledWith(hostInfo, ["src"], "dst", [], 0);
146
146
  });
147
- it("should call recv with src, dst, and opt", () => {
147
+ it("should call recv with src, dst, and opt", ()=>{
148
148
  ssh.recv(["src"], "dst", ["--dry-run", "--delete"]);
149
149
  expect(recv).to.be.calledWith(hostInfo, ["src"], "dst", ["--dry-run", "--delete"], 0);
150
150
  });
151
- it("should call recv with src, dst, opt, and timeout", () => {
151
+ it("should call recv with src, dst, opt, and timeout", ()=>{
152
152
  ssh.recv(["src"], "dst", ["--dry-run", "--delete"], 10);
153
153
  expect(recv).to.be.calledWith(hostInfo, ["src"], "dst", ["--dry-run", "--delete"], 10);
154
154
  });
155
- it("should be rejected if src is not array of string", () => {
155
+ it("should be rejected if src is not array of string", ()=>{
156
156
  return expect(ssh.recv(1)).to.be.rejectedWith("src must be array of string");
157
157
  });
158
- it("should be rejected if src has only empty string element", () => {
158
+ it("should be rejected if src has only empty string element", ()=>{
159
159
  return expect(ssh.recv(["", ""])).to.be.rejectedWith("src must contain non-empty string");
160
160
  });
161
- it("should be rejected if src has only empty string element", () => {
161
+ it("should be rejected if src has only empty string element", ()=>{
162
162
  return expect(ssh.recv([""])).to.be.rejectedWith("src must contain non-empty string");
163
163
  });
164
- it("should be called if src includes empty string ", () => {
164
+ it("should be called if src includes empty string ", ()=>{
165
165
  ssh.recv(["src", ""], "dst");
166
166
  expect(recv).to.be.calledWith(hostInfo, ["src", ""], "dst", [], 0);
167
167
  });
168
- it("should be rejected if dst is not string", () => {
168
+ it("should be rejected if dst is not string", ()=>{
169
169
  return expect(ssh.recv(["src"], 0)).to.be.rejectedWith("dst must be string");
170
170
  });
171
- it("should be rejected if dst is empty string", () => {
171
+ it("should be rejected if dst is empty string", ()=>{
172
172
  return expect(ssh.recv(["src"], "")).to.be.rejectedWith("dst must be non-empty string");
173
173
  });
174
- it("should be rejected if opt is not array of string", () => {
174
+ it("should be rejected if opt is not array of string", ()=>{
175
175
  return expect(ssh.recv(["src"], "dst", [null])).to.be.rejectedWith("opt must be array of string");
176
176
  });
177
177
  });