mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-24 11:46:31 +00:00
148 lines
3.8 KiB
TypeScript
148 lines
3.8 KiB
TypeScript
/*
|
|
* Copyright 2017 balena.io
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
import { expect } from 'chai';
|
|
import * as _ from 'lodash';
|
|
|
|
import * as fileExtensions from '../../lib/shared/file-extensions';
|
|
|
|
describe('Shared: fileExtensions', function() {
|
|
describe('.getFileExtensions()', function() {
|
|
_.forEach(
|
|
[
|
|
// No extension
|
|
{
|
|
file: 'path/to/filename',
|
|
extensions: [],
|
|
},
|
|
|
|
// Type: 'archive'
|
|
{
|
|
file: 'path/to/filename.zip',
|
|
extensions: ['zip'],
|
|
},
|
|
{
|
|
file: 'path/to/filename.etch',
|
|
extensions: ['etch'],
|
|
},
|
|
|
|
// Type: 'compressed'
|
|
{
|
|
file: 'path/to/filename.img.gz',
|
|
extensions: ['img', 'gz'],
|
|
},
|
|
{
|
|
file: 'path/to/filename.img.bz2',
|
|
extensions: ['img', 'bz2'],
|
|
},
|
|
{
|
|
file: 'path/to/filename.img.xz',
|
|
extensions: ['img', 'xz'],
|
|
},
|
|
{
|
|
file: 'path/to/filename.img.xz.gz',
|
|
extensions: ['img', 'xz', 'gz'],
|
|
},
|
|
|
|
// Type: 'image'
|
|
{
|
|
file: 'path/to/filename.img',
|
|
extensions: ['img'],
|
|
},
|
|
{
|
|
file: 'path/to/filename.iso',
|
|
extensions: ['iso'],
|
|
},
|
|
{
|
|
file: 'path/to/filename.dsk',
|
|
extensions: ['dsk'],
|
|
},
|
|
{
|
|
file: 'path/to/filename.hddimg',
|
|
extensions: ['hddimg'],
|
|
},
|
|
{
|
|
file: 'path/to/filename.raw',
|
|
extensions: ['raw'],
|
|
},
|
|
{
|
|
file: 'path/to/filename.dmg',
|
|
extensions: ['dmg'],
|
|
},
|
|
],
|
|
testCase => {
|
|
it(`should return ${testCase.extensions} for ${testCase.file}`, function() {
|
|
expect(fileExtensions.getFileExtensions(testCase.file)).to.deep.equal(
|
|
testCase.extensions,
|
|
);
|
|
});
|
|
},
|
|
);
|
|
|
|
it('should always return lowercase extensions', function() {
|
|
const filePath = 'foo.IMG.gZ';
|
|
expect(fileExtensions.getFileExtensions(filePath)).to.deep.equal([
|
|
'img',
|
|
'gz',
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe('.getLastFileExtension()', function() {
|
|
it('should return undefined if the file path has no extension', function() {
|
|
expect(fileExtensions.getLastFileExtension('foo')).to.equal(null);
|
|
});
|
|
|
|
it('should return the extension if there is only one extension', function() {
|
|
expect(fileExtensions.getLastFileExtension('foo.img')).to.equal('img');
|
|
});
|
|
|
|
it('should return the last extension if there are two extensions', function() {
|
|
expect(fileExtensions.getLastFileExtension('foo.img.gz')).to.equal('gz');
|
|
});
|
|
|
|
it('should return the last extension if there are three extensions', function() {
|
|
expect(fileExtensions.getLastFileExtension('foo.bar.img.gz')).to.equal(
|
|
'gz',
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('.getPenultimateFileExtension()', function() {
|
|
it('should return undefined in the file path has no extension', function() {
|
|
expect(fileExtensions.getPenultimateFileExtension('foo')).to.equal(null);
|
|
});
|
|
|
|
it('should return undefined if there is only one extension', function() {
|
|
expect(fileExtensions.getPenultimateFileExtension('foo.img')).to.equal(
|
|
null,
|
|
);
|
|
});
|
|
|
|
it('should return the penultimate extension if there are two extensions', function() {
|
|
expect(fileExtensions.getPenultimateFileExtension('foo.img.gz')).to.equal(
|
|
'img',
|
|
);
|
|
});
|
|
|
|
it('should return the penultimate extension if there are three extensions', function() {
|
|
expect(
|
|
fileExtensions.getPenultimateFileExtension('foo.bar.img.gz'),
|
|
).to.equal('img');
|
|
});
|
|
});
|
|
});
|