Skip to content

Commit 90fabe8

Browse files
committed
FIX: Tests
1 parent bdf2993 commit 90fabe8

2 files changed

Lines changed: 31 additions & 17 deletions

File tree

launcher/src/backend/NodeUpdates.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ export class NodeUpdates {
3737
* @returns {Object} - updates available for services
3838
*/
3939
async checkUpdates() {
40-
if (!this.nodeConnection?.settings?.lane) {
40+
if (!this.nodeConnection.settings?.stereum?.settings?.updates?.lane) {
4141
await this.nodeConnection.findStereumSettings();
4242
}
43-
const lane = this.nodeConnection?.settings?.lane || "stable";
43+
const lane = this.nodeConnection.settings?.stereum?.settings?.updates?.lane || "stable";
4444
let response = await axios.get(`https://stereum.net/downloads/updates${lane == "dev" ? ".dev" : ""}.json`);
4545
if (global.branch === "main") response.data.stereum.push({ name: "HEAD", commit: "main" });
4646
return response.data;

launcher/src/backend/tests/unit/NodeConnection.test.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ test("findStereumSettings failure", async () => {
110110

111111
await nodeConnection.findStereumSettings();
112112

113-
expect(nodeConnection.settings).toBeUndefined();
113+
expect(nodeConnection.settings).toBeNull();
114114
});
115115

116116
test("prepareStereumNode failure ubuntu installpkg", async () => {
@@ -188,6 +188,7 @@ test("prepareStereumNode failure ubuntu install", async () => {
188188
mMock
189189
.mockReturnValueOnce({ rc: 0, stdout: "ubuntu" }) // find OS
190190
.mockReturnValueOnce({ rc: 0 }) // install pkg
191+
.mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings
191192
.mockReturnValueOnce({ rc: 1, stderr: "" }); // install
192193
SSHService.SSHService.mockImplementation(() => {
193194
return {
@@ -203,7 +204,7 @@ test("prepareStereumNode failure ubuntu install", async () => {
203204
expect(e).toEqual(new Error("Can't install ansible role: <stderr empty>"));
204205
});
205206

206-
expect(mMock.mock.calls.length).toBe(4);
207+
expect(mMock.mock.calls.length).toBe(5);
207208
});
208209

209210
test("prepareStereumNode error ubuntu install", async () => {
@@ -214,6 +215,7 @@ test("prepareStereumNode error ubuntu install", async () => {
214215
.mockReturnValueOnce({ rc: 0, stdout: "ubuntu" }) // find OS
215216
.mockReturnValueOnce({ rc: 0 }) // delete ansible roles if exist
216217
.mockReturnValueOnce({ rc: 0 }) // install pkg
218+
.mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings
217219
.mockRejectedValue("connection lost"); // install
218220
SSHService.SSHService.mockImplementation(() => {
219221
return {
@@ -229,7 +231,7 @@ test("prepareStereumNode error ubuntu install", async () => {
229231
expect(e).toEqual(new Error("Can't install ansible roles: connection lost"));
230232
});
231233

232-
expect(mMock.mock.calls.length).toBe(4);
234+
expect(mMock.mock.calls.length).toBe(5);
233235
});
234236

235237
test("prepareStereumNode success", async () => {
@@ -239,8 +241,9 @@ test("prepareStereumNode success", async () => {
239241
mMock
240242
.mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings
241243
.mockReturnValueOnce({ rc: 0, stdout: "ubuntu" }) // find OS
242-
.mockReturnValueOnce({ rc: 0 }) // delete ansible roles if exist
243244
.mockReturnValueOnce({ rc: 0 }) // install pkg
245+
.mockReturnValueOnce({ rc: 0 }) // delete ansible roles if exist
246+
.mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings
244247
.mockReturnValueOnce({ rc: 0 }) // install
245248
.mockReturnValueOnce({ rc: 0 }) // playbook ansible
246249
.mockReturnValueOnce({ rc: 0 }); // playbook ansible
@@ -267,7 +270,7 @@ test("prepareStereumNode success", async () => {
267270
playbookRunRef: expect.any(String),
268271
});
269272

270-
expect(mMock.mock.calls.length).toBe(7);
273+
expect(mMock.mock.calls.length).toBe(8);
271274

272275
expect(mMock.mock.calls[0][0]).toMatch(/cat/);
273276
expect(mMock.mock.calls[0][0]).toMatch(/stereum.yaml/);
@@ -277,10 +280,13 @@ test("prepareStereumNode success", async () => {
277280

278281
expect(mMock.mock.calls[2][0]).toMatch(/apt install/);
279282

280-
expect(mMock.mock.calls[4][0]).toMatch(/git checkout/);
283+
expect(mMock.mock.calls[4][0]).toMatch(/cat/);
284+
expect(mMock.mock.calls[4][0]).toMatch(/stereum.yaml/);
285+
286+
expect(mMock.mock.calls[5][0]).toMatch(/git checkout/);
281287

282-
expect(mMock.mock.calls[5][0]).toMatch(/ansible-playbook/);
283-
expect(mMock.mock.calls[5][0]).toMatch(/ansible-playbook/);
288+
expect(mMock.mock.calls[6][0]).toMatch(/ansible-playbook/);
289+
expect(mMock.mock.calls[6][0]).toMatch(/ansible-playbook/);
284290
});
285291

286292
test("prepareStereumNode error playbook", async () => {
@@ -292,6 +298,7 @@ test("prepareStereumNode error playbook", async () => {
292298
.mockReturnValueOnce({ rc: 0, stdout: "ubuntu" }) // find OS
293299
.mockReturnValueOnce({ rc: 0 }) // delete ansible roles if exist
294300
.mockReturnValueOnce({ rc: 0 }) // install pkg
301+
.mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings
295302
.mockReturnValueOnce({ rc: 0 }) // install
296303
.mockRejectedValue("connection interrupted"); // playbook ansible
297304
SSHService.SSHService.mockImplementation(() => {
@@ -309,27 +316,31 @@ test("prepareStereumNode error playbook", async () => {
309316
expect(e).toEqual(new Error("Can't run setup playbook: Error: Can't run playbook: connection interrupted"));
310317
});
311318

312-
expect(mMock.mock.calls.length).toBe(6);
319+
expect(mMock.mock.calls.length).toBe(7);
313320

314321
expect(mMock.mock.calls[1][0]).toMatch(/cat/);
315322
expect(mMock.mock.calls[1][0]).toMatch(/release/);
316323

317324
expect(mMock.mock.calls[2][0]).toMatch(/apt install/);
318325

319-
expect(mMock.mock.calls[4][0]).toMatch(/git checkout/);
326+
expect(mMock.mock.calls[4][0]).toMatch(/cat/);
327+
expect(mMock.mock.calls[4][0]).toMatch(/stereum.yaml/);
328+
329+
expect(mMock.mock.calls[5][0]).toMatch(/git checkout/);
320330

321-
expect(mMock.mock.calls[5][0]).toMatch(/ansible-playbook/);
331+
expect(mMock.mock.calls[6][0]).toMatch(/ansible-playbook/);
322332
});
323333

324334
test("prepareStereumNode failure playbook", async () => {
325335
jest.mock("../../SSHService");
326336
const SSHService = require("../../SSHService");
327337
const mMock = jest.fn();
328338
mMock
329-
.mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings
339+
.mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests\n lane: stable" }) // find settings
330340
.mockReturnValueOnce({ rc: 0, stdout: "ubuntu" }) // find OS
331341
.mockReturnValueOnce({ rc: 0 }) // delete ansible roles if exist
332342
.mockReturnValueOnce({ rc: 0 }) // install pkg
343+
.mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests\n lane: stable" }) // find settings
333344
.mockReturnValueOnce({ rc: 0 }) // install
334345
.mockReturnValueOnce({ rc: 1, stderr: "asdf" }); // playbook ansible
335346
SSHService.SSHService.mockImplementation(() => {
@@ -347,15 +358,18 @@ test("prepareStereumNode failure playbook", async () => {
347358
expect(e).toEqual(new Error("Can't run setup playbook: Error: Failed running 'setup': asdf"));
348359
});
349360

350-
expect(mMock.mock.calls.length).toBe(6);
361+
expect(mMock.mock.calls.length).toBe(7);
351362
expect(mMock.mock.calls[1][0]).toMatch(/cat/);
352363
expect(mMock.mock.calls[1][0]).toMatch(/release/);
353364

354365
expect(mMock.mock.calls[2][0]).toMatch(/apt install/);
355366

356-
expect(mMock.mock.calls[4][0]).toMatch(/git checkout/);
367+
expect(mMock.mock.calls[4][0]).toMatch(/cat/);
368+
expect(mMock.mock.calls[4][0]).toMatch(/stereum.yaml/);
369+
370+
expect(mMock.mock.calls[5][0]).toMatch(/git checkout/);
357371

358-
expect(mMock.mock.calls[5][0]).toMatch(/ansible-playbook/);
372+
expect(mMock.mock.calls[6][0]).toMatch(/ansible-playbook/);
359373
});
360374

361375
test("playbookStatus error", async () => {

0 commit comments

Comments
 (0)