mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-23 03:06:38 +00:00
test(image-stream): Use local dir instead of tmpdir
This changes the image-stream tests to use a local directory, instead of the OS's tmpdir to avoid issues with sandboxing on Concourse CI. Change-Type: patch
This commit is contained in:
parent
800f0f45e5
commit
bc2ad581ba
3
.gitignore
vendored
3
.gitignore
vendored
@ -11,6 +11,9 @@ pids
|
|||||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
/lib-cov
|
/lib-cov
|
||||||
|
|
||||||
|
# Image stream output directory
|
||||||
|
/tests/image-stream/output
|
||||||
|
|
||||||
# Coverage directory used by tools like istanbul
|
# Coverage directory used by tools like istanbul
|
||||||
/coverage
|
/coverage
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ const m = require('mochainon')
|
|||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
const Bluebird = require('bluebird')
|
const Bluebird = require('bluebird')
|
||||||
const fs = Bluebird.promisifyAll(require('fs'))
|
const fs = Bluebird.promisifyAll(require('fs'))
|
||||||
const os = require('os')
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const imageStream = require('../../lib/sdk/image-stream/index')
|
const imageStream = require('../../lib/sdk/image-stream/index')
|
||||||
|
|
||||||
@ -51,35 +50,41 @@ exports.expectError = function (file, errorMessage, errorDetail) {
|
|||||||
|
|
||||||
exports.extractFromFilePath = function (file, image) {
|
exports.extractFromFilePath = function (file, image) {
|
||||||
it('should be able to extract the image', function () {
|
it('should be able to extract the image', function () {
|
||||||
const output = path.join(os.tmpdir(), path.basename(file))
|
const dirname = path.join(__dirname, 'output')
|
||||||
|
const output = path.join(dirname, path.basename(file))
|
||||||
|
|
||||||
return imageStream.getFromFilePath(file).then(function (results) {
|
return fs.mkdirAsync(dirname)
|
||||||
m.chai.expect(results.path).to.equal(file)
|
.catch({ code: 'EEXIST' }, _.noop)
|
||||||
m.chai.expect(_.isString(results.extension)).to.be.true
|
.then(function () {
|
||||||
m.chai.expect(_.isEmpty(_.trim(results.extension))).to.be.false
|
return imageStream.getFromFilePath(file)
|
||||||
|
})
|
||||||
if (!_.some([
|
.then(function (results) {
|
||||||
results.size.original === fs.statSync(file).size,
|
m.chai.expect(results.path).to.equal(file)
|
||||||
results.size.original === fs.statSync(image).size
|
m.chai.expect(_.isString(results.extension)).to.be.true
|
||||||
])) {
|
m.chai.expect(_.isEmpty(_.trim(results.extension))).to.be.false
|
||||||
throw new Error(`Invalid size: ${results.size.original}`)
|
|
||||||
}
|
if (!_.some([
|
||||||
|
results.size.original === fs.statSync(file).size,
|
||||||
const stream = results.stream
|
results.size.original === fs.statSync(image).size
|
||||||
.pipe(results.transform)
|
])) {
|
||||||
.pipe(fs.createWriteStream(output))
|
throw new Error(`Invalid size: ${results.size.original}`)
|
||||||
|
}
|
||||||
return new Bluebird((resolve, reject) => {
|
|
||||||
stream.on('error', reject)
|
const stream = results.stream
|
||||||
stream.on('close', resolve)
|
.pipe(results.transform)
|
||||||
|
.pipe(fs.createWriteStream(output))
|
||||||
|
|
||||||
|
return new Bluebird((resolve, reject) => {
|
||||||
|
stream.on('error', reject)
|
||||||
|
stream.on('close', resolve)
|
||||||
|
})
|
||||||
|
}).then(function () {
|
||||||
|
return doFilesContainTheSameData(image, output)
|
||||||
|
}).then(function (areEqual) {
|
||||||
|
m.chai.expect(areEqual).to.be.true
|
||||||
|
}).finally(function () {
|
||||||
|
return fs.unlinkAsync(output)
|
||||||
|
.catch({ code: 'ENOENT' }, _.noop)
|
||||||
})
|
})
|
||||||
}).then(function () {
|
|
||||||
return doFilesContainTheSameData(image, output)
|
|
||||||
}).then(function (areEqual) {
|
|
||||||
m.chai.expect(areEqual).to.be.true
|
|
||||||
}).finally(function () {
|
|
||||||
return fs.unlinkAsync(output)
|
|
||||||
.catch({ code: 'ENOENT' }, _.noop)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user