diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 98b42e02..f2b1c742 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -14810,9 +14810,9 @@ "integrity": "sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==" }, "node_modules/pump": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", - "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.1.tgz", + "integrity": "sha512-2ynnAmUu45oUSq51AQbeugLkMSKaz8FqVpZ6ykTqzOVkzXe8u/ezkGsYrFJqKZx+D9cVxoDrSbR7CeAwxFa5cQ==", "dependencies": { "end-of-stream": "^1.1.0", "once": "^1.3.1" diff --git a/tests/commands/release/export.spec.ts b/tests/commands/release/export.spec.ts new file mode 100644 index 00000000..50307b32 --- /dev/null +++ b/tests/commands/release/export.spec.ts @@ -0,0 +1,76 @@ +import * as stream from 'node:stream'; +import { cleanOutput, runCommand } from '../../helpers'; +import { BalenaAPIMock } from '../../nock/balena-api-mock'; +import { expect } from 'chai'; +import * as mock from 'mock-require'; +import * as sinon from 'sinon'; + +// "itSS" means "it() Skip Standalone" +const itSS = process.env.BALENA_CLI_TEST_TYPE === 'standalone' ? it.skip : it; + +describe('export fleet content to a file', function () { + let api: BalenaAPIMock; + const releaseBundleCreateStub = sinon.stub(); + + this.beforeEach(() => { + api = new BalenaAPIMock(); + mock('@balena/release-bundle', { + create: releaseBundleCreateStub, + }); + }); + + this.afterEach(() => { + // Check all expected api calls have been made and clean up. + api.done(); + mock.stop('@balena/release-bundle'); + }); + + itSS('should export a release to a file', async () => { + api.expectGetWhoAmI(); + api.expectGetRelease(); + releaseBundleCreateStub.resolves(stream.Readable.from('something')); + + const { out, err } = await runCommand( + 'release export badc0ffe -o /tmp/release.tar.gz', + ); + + const lines = cleanOutput(out); + expect(lines[0]).to.contain( + 'Release badc0ffe has been exported to /tmp/release.tar.gz.', + ); + expect(err).to.be.empty; + }); + + itSS('should fail if the create throws an error', async () => { + api.expectGetWhoAmI(); + api.expectGetRelease(); + releaseBundleCreateStub.rejects( + new Error('Something went wrong creating the bundle'), + ); + + const { err } = await runCommand( + 'release export badc0ffe -o /tmp/release.tar.gz', + ); + + expect(cleanOutput(err, true)).to.include( + 'Release badc0ffe could not be exported: Something went wrong creating the bundle', + ); + }); + + itSS('should parse with application slug and version', async () => { + api.expectGetWhoAmI(); + api.expectGetRelease(); + api.expectGetApplication(); + releaseBundleCreateStub.resolves(stream.Readable.from('something')); + + const { out, err } = await runCommand( + 'release export org/superApp -o /tmp/release.tar.gz --version 1.2.3+rev1', + ); + + const lines = cleanOutput(out); + expect(lines[0]).to.contain( + 'Release org/superApp version 1.2.3+rev1 has been exported to /tmp/release.tar.gz.', + ); + expect(err).to.be.empty; + }); +});