From 919af9f7839c8425e6f978eff837322097c5c45b Mon Sep 17 00:00:00 2001 From: neothethird Date: Fri, 25 May 2018 15:38:12 +0200 Subject: [PATCH] Take a swing at fixing those damn paths --- src/client.js | 14 +++++++------- tests/test-data/file-push.json | 16 ++++++++-------- tests/test-data/files-urls.json | 16 ++++++++-------- tests/unit-tests/test_client.js | 10 +++++----- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/client.js b/src/client.js index 3d700d4..5d8ed0b 100644 --- a/src/client.js +++ b/src/client.js @@ -94,10 +94,10 @@ class Client { } createInstallCommandsFile(cmds, device) { - if (!fs.existsSync(this.path + "/commandfile/")) { - mkdirp.sync(this.path + "/commandfile/"); + if (!fs.existsSync(path.join(this.path, "commandfile"))) { + mkdirp.sync(path.join(this.path, "commandfile")); } - var file = this.path + "/commandfile/" + ubuntuCommandFile + device + common.getRandomInt(1000, 9999); + var file = path.join(this.path, "commandfile", ubuntuCommandFile + device + common.getRandomInt(1000, 9999)); fs.writeFileSync(file, cmds); return file; } @@ -196,7 +196,7 @@ class Client { gpg.forEach((g) => { gpgUrls.push({ url: this.host + "gpg/" + g, - path: this.path + "/gpg" + path: path.join(this.path, "gpg") }); }); return gpgUrls; @@ -207,12 +207,12 @@ class Client { index.files.forEach((file) => { ret.push({ url: this.host + file.path, - path: this.path + "/pool", + path: path.join(this.path, "pool"), checksum: file.checksum }); ret.push({ url: this.host + file.signature, - path: this.path + "/pool" + path: path.join(this.path, "pool") }); }); return ret; @@ -222,7 +222,7 @@ class Client { var files = []; urls.forEach((url) => { files.push({ - src: url.path + "/" + path.basename(url.url), + src: path.join(url.path, path.basename(url.url)), dest: ubuntuPushDir }); }); diff --git a/tests/test-data/file-push.json b/tests/test-data/file-push.json index f2c8680..c34ee51 100644 --- a/tests/test-data/file-push.json +++ b/tests/test-data/file-push.json @@ -1,34 +1,34 @@ [ { "dest": "/cache/recovery/", - "src": "./test/pool/ubports-e5cf0885f061c9615931cf863a43f65d8590aa71027315ad71999252ce118868.tar.xz" + "src": "test/pool/ubports-e5cf0885f061c9615931cf863a43f65d8590aa71027315ad71999252ce118868.tar.xz" }, { "dest": "/cache/recovery/", - "src": "./test/pool/ubports-e5cf0885f061c9615931cf863a43f65d8590aa71027315ad71999252ce118868.tar.xz.asc" + "src": "test/pool/ubports-e5cf0885f061c9615931cf863a43f65d8590aa71027315ad71999252ce118868.tar.xz.asc" }, { "dest": "/cache/recovery/", - "src": "./test/pool/device-f6863fe2f1f8b47cd90f5721af05ccb0ab4d41f2e1cc318075458646eeda28ee.tar.xz" + "src": "test/pool/device-f6863fe2f1f8b47cd90f5721af05ccb0ab4d41f2e1cc318075458646eeda28ee.tar.xz" }, { "dest": "/cache/recovery/", - "src": "./test/pool/device-f6863fe2f1f8b47cd90f5721af05ccb0ab4d41f2e1cc318075458646eeda28ee.tar.xz.asc" + "src": "test/pool/device-f6863fe2f1f8b47cd90f5721af05ccb0ab4d41f2e1cc318075458646eeda28ee.tar.xz.asc" }, { "dest": "/cache/recovery/", - "src": "./test/pool/keyring-4c4e7ef380ebcfa2c31084efa199138e93bfed8fc58aa3eb06bdf75a78af9b57.tar.xz" + "src": "test/pool/keyring-4c4e7ef380ebcfa2c31084efa199138e93bfed8fc58aa3eb06bdf75a78af9b57.tar.xz" }, { "dest": "/cache/recovery/", - "src": "./test/pool/keyring-4c4e7ef380ebcfa2c31084efa199138e93bfed8fc58aa3eb06bdf75a78af9b57.tar.xz.asc" + "src": "test/pool/keyring-4c4e7ef380ebcfa2c31084efa199138e93bfed8fc58aa3eb06bdf75a78af9b57.tar.xz.asc" }, { "dest": "/cache/recovery/", - "src": "./test/pool/version-261.tar.xz" + "src": "test/pool/version-261.tar.xz" }, { "dest": "/cache/recovery/", - "src": "./test/pool/version-261.tar.xz.asc" + "src": "test/pool/version-261.tar.xz.asc" } ] diff --git a/tests/test-data/files-urls.json b/tests/test-data/files-urls.json index 4b3cd5a..96db65e 100644 --- a/tests/test-data/files-urls.json +++ b/tests/test-data/files-urls.json @@ -1,38 +1,38 @@ [ { "checksum": "777b2d05b2a0f26b2a9a302eb7804e7eab9bf536f130ffae2f15455a80bd509b", - "path": "./test/pool", + "path": "test/pool", "url": "https://system-image.ubports.com//pool/ubports-e5cf0885f061c9615931cf863a43f65d8590aa71027315ad71999252ce118868.tar.xz" }, { - "path": "./test/pool", + "path": "test/pool", "url": "https://system-image.ubports.com//pool/ubports-e5cf0885f061c9615931cf863a43f65d8590aa71027315ad71999252ce118868.tar.xz.asc" }, { "checksum": "234d719a32a01bc36d64dbb536fcf27d77957916f8c3851916e4d1e44d732364", - "path": "./test/pool", + "path": "test/pool", "url": "https://system-image.ubports.com//pool/device-f6863fe2f1f8b47cd90f5721af05ccb0ab4d41f2e1cc318075458646eeda28ee.tar.xz" }, { - "path": "./test/pool", + "path": "test/pool", "url": "https://system-image.ubports.com//pool/device-f6863fe2f1f8b47cd90f5721af05ccb0ab4d41f2e1cc318075458646eeda28ee.tar.xz.asc" }, { "checksum": "5b6e870acf8944330acb2a9dad6f5270bd06c377603a3115f805290e989ab421", - "path": "./test/pool", + "path": "test/pool", "url": "https://system-image.ubports.com//pool/keyring-4c4e7ef380ebcfa2c31084efa199138e93bfed8fc58aa3eb06bdf75a78af9b57.tar.xz" }, { - "path": "./test/pool", + "path": "test/pool", "url": "https://system-image.ubports.com//pool/keyring-4c4e7ef380ebcfa2c31084efa199138e93bfed8fc58aa3eb06bdf75a78af9b57.tar.xz.asc" }, { "checksum": "2624df95cbfc0c0dbdd0ff14a7cf6de78802bb38f5dd2a3fa75f0e99586dcba5", - "path": "./test/pool", + "path": "test/pool", "url": "https://system-image.ubports.com//ubports-touch/15.04/devel/bacon/version-261.tar.xz" }, { - "path": "./test/pool", + "path": "test/pool", "url": "https://system-image.ubports.com//ubports-touch/15.04/devel/bacon/version-261.tar.xz.asc" } ] diff --git a/tests/unit-tests/test_client.js b/tests/unit-tests/test_client.js index 8fa412a..ac84b76 100644 --- a/tests/unit-tests/test_client.js +++ b/tests/unit-tests/test_client.js @@ -136,7 +136,7 @@ describe('Client module', function() { it("should create install commands file", function() { const sic = new SystemImageClient(); var file = sic.createInstallCommandsFile(commandfileJson, "bacon"); - expect(file.indexOf("./test/commandfile/ubuntu_commandbacon") != -1).to.eql(true); + expect(file.indexOf("test/commandfile/ubuntu_commandbacon") != -1).to.eql(true); expect(fs.readFileSync(file).toString()).to.eql(commandfileJson); }); // TODO introduce a test case with invalid input @@ -280,10 +280,10 @@ describe('Client module', function() { it("should return gpg urls array", function() { const sic = new SystemImageClient(); expect(sic.getGgpUrlsArray()).to.eql([ - { "path": "./test/gpg", "url": "https://system-image.ubports.com/gpg/image-signing.tar.xz" }, - { "path": "./test/gpg", "url": "https://system-image.ubports.com/gpg/image-signing.tar.xz.asc" }, - { "path": "./test/gpg", "url": "https://system-image.ubports.com/gpg/image-master.tar.xz" }, - { "path": "./test/gpg", "url": "https://system-image.ubports.com/gpg/image-master.tar.xz.asc" } + { "path": "test/gpg", "url": "https://system-image.ubports.com/gpg/image-signing.tar.xz" }, + { "path": "test/gpg", "url": "https://system-image.ubports.com/gpg/image-signing.tar.xz.asc" }, + { "path": "test/gpg", "url": "https://system-image.ubports.com/gpg/image-master.tar.xz" }, + { "path": "test/gpg", "url": "https://system-image.ubports.com/gpg/image-master.tar.xz.asc" } ]); }); });