Skip to content

Commit

Permalink
test: Add test for using an alternate 7z binary location
Browse files Browse the repository at this point in the history
  • Loading branch information
q2s2t committed Nov 1, 2018
1 parent ad7f1d0 commit 5d04dd4
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 1 deletion.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ Documentation:
☐ $defer
☐ add(archive, [source1, source2]) usage
☐ No benchmark command: It will output based on the system that it is on, "system-static"
☐ No Show information about supported formats command: It will output based on the system that it is on, "system-static"
☐ Hack to use delete() command (delete is a JS reserved word)
☐ use `cherryPick` as argument name for clarity
15 changes: 15 additions & 0 deletions test/func/add.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,19 @@ describe('Functional: add()', function () {
done()
})
})

it('should work with atlernate $path', function (done) {
const archive = `${tmpDir}/headers-and-footers-path.7z`
const source = `${mockDir}/DirHex/`
const seven = add(archive, source, { $path: `${mockDir}/Seven Zip` })
seven.on('end', function () {
// headers
expect(seven.info.get('Creating archive')).to.equal(archive)
expect(seven.info.get('Items to compress')).to.equal('30')
// footers
expect(seven.info.get('Files read from disk')).to.equal('24')
expect(seven.info.get('Archive size')).to.be.a('string')
done()
})
})
})
31 changes: 31 additions & 0 deletions test/func/extract.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,35 @@ describe('Functional: extract()', function () {
done()
})
})

it('should work with atlernate $path', function (done) {
const archiveBase = `${mockDir}/DirNew/ExtArchive.7z`
const archive = `${tmpDir}/extract-flat-exist-path.7z`
const output = `${tmpDir}/extract-flat-exist-path`
copyFileSync(archiveBase, archive)
const seven = extract(archive, output, false, {
r: true,
$path: `${mockDir}/Seven Zip`
})
seven.on('end', function () {
expect(seven.info.get('Files')).to.equal('9')
expect(seven.info.get('Folders')).to.equal('3')
expect(seven.info.get('Path')).to.equal(archive)
const ls = readdirSync(output)
expect(ls).to.contain('DirExt')
expect(ls).to.contain('DirExt')
expect(ls).to.contain('root.md')
expect(ls).to.contain('root.not')
expect(ls).to.contain('root.txt')
expect(ls).to.contain('sub1')
expect(ls).to.contain('sub1.md')
expect(ls).to.contain('sub1.not')
expect(ls).to.contain('sub1.txt')
expect(ls).to.contain('sub2')
expect(ls).to.contain('sub2.md')
expect(ls).to.contain('sub2.not')
expect(ls).to.contain('sub2.txt')
done()
})
})
})
22 changes: 21 additions & 1 deletion test/func/extractFull.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global describe, it */
import { expect } from 'chai'
import { copyFileSync } from 'fs'
import { copyFileSync, readdirSync } from 'fs'
import { extractFull } from '../../lib/commands.js'
import readdirRecursiveSync from 'fs-readdir-recursive'

Expand Down Expand Up @@ -149,4 +149,24 @@ describe('Functional: extractFull()', function () {
done()
})
})

it('should work with atlernate $path', function (done) {
const archiveBase = `${mockDir}/DirNew/ExtArchive.7z`
const archive = `${tmpDir}/extractFull-full-path.7z`
const output = `${tmpDir}/extract-full-path`
copyFileSync(archiveBase, archive)
const seven = extractFull(archive, output, false, {
r: true,
$path: `${mockDir}/Seven Zip`
})
seven.on('end', function () {
expect(seven.info.get('Files')).to.equal('9')
expect(seven.info.get('Folders')).to.equal('3')
expect(seven.info.get('Path')).to.equal(archive)
const ls = readdirRecursiveSync(output)
expect(ls).to.contain('DirExt/root.md')
expect(ls).to.contain('DirExt/sub1/sub1.md')
done()
})
})
})
18 changes: 18 additions & 0 deletions test/func/hash.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,22 @@ describe('Functional: hash()', function () {
done()
})
})

it('should work with atlernate $path', function (done) {
const seven = hash([`${mockDir}/DirExt/sub1/`], {
r: true,
$path: `${mockDir}/Seven Zip`
})
const hashesKnown = [ { hash: undefined, size: NaN, file: 'sub1' },
{ hash: 'FEDC304F', size: 9, file: 'sub1/sub1.txt' },
{ hash: 'FEDC304F', size: 9, file: 'sub1/sub1.not' },
{ hash: 'FEDC304F', size: 9, file: 'sub1/sub1.md' } ]
let hashes = []
seven.on('data', (d) => hashes.push(d))
seven.on('end', function () {
expect(hashes).to.deep.equal(hashesKnown)
expect(seven.info.get('CRC32 for data and names')).to.equal('2363C80A')
done()
})
})
})

0 comments on commit 5d04dd4

Please sign in to comment.