diff --git a/package-lock.json b/package-lock.json index 75af6542..228837d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1222,7 +1222,7 @@ "fetch-ponyfill": "^4.0.0", "fetch-readablestream": "^0.2.0", "lodash": "^4.6.1", - "node-web-streams": "github:resin-io-modules/node-web-streams#emit-errors", + "node-web-streams": "github:resin-io-modules/node-web-streams#46f98300b69090bde3f6b4983877ccfe283a892c", "progress-stream": "^2.0.0", "qs": "^6.3.0", "rindle": "^1.3.1" @@ -1358,7 +1358,7 @@ "lodash": "^4.13.1", "resin-cli-form": "^1.4.1", "resin-cli-visuals": "^1.2.8", - "resin-discoverable-services": "git+https://github.com/resin-io-modules/resin-discoverable-services.git#find-on-all-interfaces", + "resin-discoverable-services": "git+https://github.com/resin-io-modules/resin-discoverable-services.git#afca9e4700ec5ef82aa897f14bd5a46f06518061", "resin-semver": "^1.4.0", "revalidator": "^0.3.1", "rindle": "^1.3.0", @@ -1609,7 +1609,7 @@ "deep-equal": "^1.0.1", "dns-equal": "^1.0.0", "dns-txt": "^2.0.2", - "multicast-dns": "git+https://github.com/resin-io-modules/multicast-dns.git#listen-on-all-interfaces", + "multicast-dns": "git+https://github.com/resin-io-modules/multicast-dns.git#a15c63464eb43e8925b187ed5cb9de6892e8aacc", "multicast-dns-service-types": "^1.1.0" } }, @@ -4049,8 +4049,7 @@ "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -4210,7 +4209,6 @@ "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -4229,7 +4227,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -4323,7 +4320,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -4409,8 +4405,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -4446,7 +4441,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -4510,14 +4504,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, @@ -8785,7 +8777,7 @@ "dev": true, "requires": { "bluebird": "^3.0.0", - "bonjour": "git+https://github.com/resin-io/bonjour.git#fixed-mdns", + "bonjour": "git+https://github.com/resin-io/bonjour.git#e018851dc823b4b3f670f658f71d0c1c7f3e637c", "ip": "^1.1.4", "lodash": "^4.17.4" } @@ -10262,9 +10254,9 @@ } }, "ts-node": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.2.0.tgz", - "integrity": "sha512-m8XQwUurkbYqXrKqr3WHCW310utRNvV5OnRVeISeea7LoCWVcdfeB/Ntl8JYWFh+WRoUAdBgESrzKochQt7sMw==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.3.0.tgz", + "integrity": "sha512-dyNS/RqyVTDcmNM4NIBAeDMpsAdaQ+ojdf0GOLqE6nwJOgzEkdRNzJywhDfwnuvB10oa6NLVG1rUJQCpRN7qoQ==", "dev": true, "requires": { "arg": "^4.1.0", @@ -10797,8 +10789,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -10841,8 +10832,7 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", @@ -10853,8 +10843,7 @@ "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -10971,8 +10960,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -10984,7 +10972,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -11014,7 +11001,6 @@ "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -11033,7 +11019,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -11127,7 +11112,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -11213,8 +11197,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -11250,7 +11233,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -11270,7 +11252,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -11314,14 +11295,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, diff --git a/package.json b/package.json index d3f9b6b2..d8524b18 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "test": "npm run lint && npm run test:build && JUNIT_REPORT_PATH=report.xml istanbul cover _mocha && npm run coverage", "test:build": "npm run typescript:test-build && npm run coffeescript:test && npm run testitems:copy && npm run migrations:copy-test && npm run packagejson:copy", "coverage": "istanbul report text && istanbul report html", - "test:fast": "npm run test:build && mocha", + "test:fast": "mocha --opts test/fast-mocha.opts", "test:debug": "npm run test:build && mocha --inspect-brk", "prettify": "prettier --config ./node_modules/resin-lint/config/.prettierrc --write \"{src,test,typings}/**/*.ts\"", "typescript:test-build": "tsc --project tsconfig.json", @@ -112,6 +112,7 @@ "terser": "^3.14.1", "tmp": "^0.1.0", "ts-loader": "^5.3.0", + "ts-node": "^8.3.0", "typed-error": "^2.0.0", "typescript": "^3.5.1", "webpack": "^4.25.0", diff --git a/test/20-compose-volume.ts b/test/20-compose-volume.ts new file mode 100644 index 00000000..c2f9a87c --- /dev/null +++ b/test/20-compose-volume.ts @@ -0,0 +1,123 @@ +import { expect } from 'chai'; +import { stub } from 'sinon'; + +import Volume from '../src/compose/volume'; +import logTypes = require('../src/lib/log-types'); + +const fakeLogger = { + logSystemMessage: stub(), + logSystemEvent: stub(), +}; +const fakeDocker = { + createVolume: stub(), +}; + +const opts: any = { logger: fakeLogger, docker: fakeDocker }; + +describe('Compose volumes', () => { + describe('Parsing volumes', () => { + it('should correctly parse docker volumes', () => { + const volume = Volume.fromDockerVolume(opts, { + Driver: 'local', + Labels: { + 'io.balena.supervised': 'true', + }, + Mountpoint: '/var/lib/docker/volumes/1032480_one_volume/_data', + Name: '1032480_one_volume', + Options: {}, + Scope: 'local', + }); + + expect(volume) + .to.have.property('appId') + .that.equals(1032480); + expect(volume) + .to.have.property('name') + .that.equals('one_volume'); + expect(volume) + .to.have.property('config') + .that.has.property('labels') + .that.deep.equals({ + 'io.balena.supervised': 'true', + }); + expect(volume) + .to.have.property('config') + .that.has.property('driverOpts') + .that.deep.equals({}); + }); + + it('should correctly parse compose volumes', () => { + const volume = Volume.fromComposeObject( + 'one_volume', + 1032480, + { + driver_opts: { + opt1: 'test', + }, + labels: { + 'my-label': 'test-label', + }, + }, + opts, + ); + + expect(volume) + .to.have.property('appId') + .that.equals(1032480); + expect(volume) + .to.have.property('name') + .that.equals('one_volume'); + expect(volume) + .to.have.property('config') + .that.has.property('labels') + .that.deep.equals({ + 'io.balena.supervised': 'true', + 'my-label': 'test-label', + }); + expect(volume) + .to.have.property('config') + .that.has.property('driverOpts') + .that.deep.equals({ + opt1: 'test', + }); + }); + }); + + describe('Generating docker options', () => { + afterEach(() => { + fakeDocker.createVolume.reset(); + fakeLogger.logSystemEvent.reset(); + fakeLogger.logSystemMessage.reset(); + }); + it('should correctly generate docker options', async () => { + const volume = Volume.fromComposeObject( + 'one_volume', + 1032480, + { + driver_opts: { + opt1: 'test', + }, + labels: { + 'my-label': 'test-label', + }, + }, + opts, + ); + + await volume.create(); + expect( + fakeDocker.createVolume.calledWith({ + Labels: { + 'my-label': 'test-label', + 'io.balena.supervised': 'true', + }, + Options: { + opt1: 'test', + }, + }), + ); + + expect(fakeLogger.logSystemEvent.calledWith(logTypes.createVolume)); + }); + }); +}); diff --git a/test/fast-mocha.opts b/test/fast-mocha.opts new file mode 100644 index 00000000..d10cc2d2 --- /dev/null +++ b/test/fast-mocha.opts @@ -0,0 +1,5 @@ +--exit +--require ts-node/register/transpile-only +--require coffeescript/register +--timeout 30000 +test/*.{ts,coffee}