Fix tests to use 7zdec correctly
Some checks failed
continuous-integration/appveyor/branch AppVeyor build failed

This commit is contained in:
Jonatan Nilsson 2022-02-16 11:49:48 +00:00
parent dbcc431e70
commit cbc0f7a37a
4 changed files with 29 additions and 25 deletions

View file

@ -23,6 +23,7 @@ environment:
test_script: test_script:
- sh: | - sh: |
ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
chmod -R 777 /appveyor/projects chmod -R 777 /appveyor/projects
npm install npm install
npm test npm test

View file

@ -88,9 +88,9 @@ export default class Util {
get7zipExecutable() { get7zipExecutable() {
const util = new Util(import.meta.url) const util = new Util(import.meta.url)
if (process.platform === 'win32') { if (process.platform === 'win32') {
return util.getPathFromRoot('../bin/7za.exe') return util.getPathFromRoot('../bin/7zdec.exe')
} }
return util.getPathFromRoot('../bin/7zas') return util.getPathFromRoot('../bin/7zdec')
} }
verifyConfig(config) { verifyConfig(config) {
@ -100,22 +100,19 @@ export default class Util {
} }
extractFile(file, stream = function() {}) { extractFile(file, stream = function() {}) {
return this.runCommand(this.get7zipExecutable(), ['x', file], path.dirname(file), stream) let program = this.get7zipExecutable()
.then(() => { let args = ['x', file]
if (!file.indexOf('.tar.')) return if (file.indexOf('.tar.') > 0) {
program = 'tar'
let tarFile = file.slice(0, file.lastIndexOf('.')) args = ['xvf', file]
return fs.stat(tarFile) }
.catch(function() { return null }) return this.runCommand(program, args, path.dirname(file), stream)
.then((stat) => {
if (!stat) return
return this.extractFile(tarFile)
.then(function() { return fs.rm(tarFile, { force: true }) })
})
})
} }
runCommand(command, options = [], folder = null, stream = function() {}) { runCommand(command, options = [], folder = null, stream = function() {}) {
let baseError = new Error('')
return new Promise(function(res, rej) { return new Promise(function(res, rej) {
let fullcommand = path.join(folder ? folder : '', command) let fullcommand = path.join(folder ? folder : '', command)
if (command.indexOf('/') >= 0 || command.indexOf('\\') >= 0) { if (command.indexOf('/') >= 0 || command.indexOf('\\') >= 0) {
@ -142,12 +139,14 @@ export default class Util {
}) })
processor.on('error', function(err) { processor.on('error', function(err) {
clearInterval(timeOuter) clearInterval(timeOuter)
rej(err) baseError.message = err.message
rej(baseError)
}) })
processor.on('exit', function (code) { processor.on('exit', function (code) {
clearInterval(timeOuter) clearInterval(timeOuter)
if (code !== 0) { if (code !== 0) {
return rej(new Error('Program returned error code: ' + code)) baseError.message = 'Program returned error code: ' + code
return rej(baseError)
} }
res(code) res(code)
}) })

View file

@ -19,6 +19,10 @@ t.timeout(10000).describe('', function() {
let versions = [] let versions = []
let processor let processor
let integrationLog = getLog('test.integration', []) let integrationLog = getLog('test.integration', [])
let compressorPath = util.getPathFromRoot('./7za.exe')
if (process.platform !== 'win32') {
compressorPath = util.getPathFromRoot('./7zas')
}
t.before(function(cb) { t.before(function(cb) {
server = http.createServer(function(req, res) { server = http.createServer(function(req, res) {
@ -222,7 +226,7 @@ t.timeout(10000).describe('', function() {
let index = file('./index.mjs') let index = file('./index.mjs')
await fs.writeFile(index, version_1_stable) await fs.writeFile(index, version_1_stable)
await util.runCommand(util.get7zipExecutable(), ['a', file('./v1-sc.7z'), index], util.getPathFromRoot('./testapp')) await util.runCommand(compressorPath, ['a', file('./v1-sc.7z'), index], util.getPathFromRoot('./testapp'))
processor = startRunner() processor = startRunner()
@ -273,7 +277,7 @@ t.timeout(10000).describe('', function() {
// Create our second version // Create our second version
await fs.writeFile(index, version_2_nolisten) await fs.writeFile(index, version_2_nolisten)
await util.runCommand(util.get7zipExecutable(), ['a', file('./v2-sc.7z'), index], util.getPathFromRoot('./testapp')) await util.runCommand(compressorPath, ['a', file('./v2-sc.7z'), index], util.getPathFromRoot('./testapp'))
const assertNameVersion2 = 'v2_nolisten' const assertNameVersion2 = 'v2_nolisten'
file(`./testapp/${assertNameVersion2}`) file(`./testapp/${assertNameVersion2}`)
@ -366,7 +370,7 @@ t.timeout(10000).describe('', function() {
// Create our third version // Create our third version
await fs.writeFile(index, version_3_crashing) await fs.writeFile(index, version_3_crashing)
await util.runCommand(util.get7zipExecutable(), ['a', file('./v3-sc.7z'), index], util.getPathFromRoot('./testapp')) await util.runCommand(compressorPath, ['a', file('./v3-sc.7z'), index], util.getPathFromRoot('./testapp'))
const assertNameVersion3 = 'v3_crash' const assertNameVersion3 = 'v3_crash'
file(`./testapp/${assertNameVersion3}`) file(`./testapp/${assertNameVersion3}`)
@ -412,7 +416,7 @@ t.timeout(10000).describe('', function() {
// Create our fourth version // Create our fourth version
await fs.writeFile(index, version_4_stable) await fs.writeFile(index, version_4_stable)
await util.runCommand(util.get7zipExecutable(), ['a', file('./v4-sc.7z'), index], util.getPathFromRoot('./testapp')) await util.runCommand(compressorPath, ['a', file('./v4-sc.7z'), index], util.getPathFromRoot('./testapp'))
const assertNameVersion4 = 'v4_stable' const assertNameVersion4 = 'v4_stable'
file(`./testapp/${assertNameVersion4}`) file(`./testapp/${assertNameVersion4}`)

View file

@ -43,13 +43,13 @@ t.describe('#get7zipExecutable()', function() {
console.log('Adding 7zip windows exe path test') console.log('Adding 7zip windows exe path test')
t.test('should return windows executable path', function() { t.test('should return windows executable path', function() {
assert.ok(util.get7zipExecutable().endsWith('\\service-core\\bin\\7za.exe'), `${util.get7zipExecutable()} should end with 7za.exe`) assert.ok(util.get7zipExecutable().endsWith('\\service-core\\bin\\7zdec.exe'), `${util.get7zipExecutable()} should end with 7zdec.exe`)
}) })
} else { } else {
console.log('Adding 7zip linux exe path test') console.log('Adding 7zip linux exe path test')
t.test('should return linux executable path', function() { t.test('should return linux executable path', function() {
assert.ok(util.get7zipExecutable().endsWith('/service-core/bin/7zas'), `${util.get7zipExecutable()} should end with 7zas`) assert.ok(util.get7zipExecutable().endsWith('/service-core/bin/7zdec'), `${util.get7zipExecutable()} should end with 7zdec`)
}) })
} }
}) })
@ -426,8 +426,8 @@ t.describe('#extractFile()', function() {
throw err throw err
} }
assert.match(output, /Extracting archive\:.+example.tar.gz/) assert.match(output, /file1.txt/)
assert.match(output, /1 file, 123 bytes/) assert.match(output, /file2.txt/)
assert.strictEqual(output.indexOf('\r\n'), -1) assert.strictEqual(output.indexOf('\r\n'), -1)
}) })
}) })