-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor archive type checks to be more DRY
This should be an in-place refactor without any additional behaviors or side effects. Fixes #6147
- Loading branch information
Showing
5 changed files
with
47 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import expect from 'expect.js'; | ||
import typeFromFilename, { ZIP, TAR } from '../type_from_filename'; | ||
|
||
describe('kibana cli', function () { | ||
describe('type_from_filename', function () { | ||
it('returns ZIP for .zip filename', function () { | ||
const type = typeFromFilename('wat.zip'); | ||
expect(type).to.equal(ZIP); | ||
}); | ||
it('returns TAR for .tar.gz filename', function () { | ||
const type = typeFromFilename('wat.tar.gz'); | ||
expect(type).to.equal(TAR); | ||
}); | ||
it('returns undefined for unknown file type', function () { | ||
const type = typeFromFilename('wat.unknown'); | ||
expect(type).to.equal(undefined); | ||
}); | ||
it('accepts paths', function () { | ||
const type = typeFromFilename('/some/path/to/wat.zip'); | ||
expect(type).to.equal(ZIP); | ||
}); | ||
it('accepts urls', function () { | ||
const type = typeFromFilename('http://example.com/wat.zip'); | ||
expect(type).to.equal(ZIP); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const TAR = '.tar.gz'; | ||
export const ZIP = '.zip'; | ||
|
||
export default function typeFromFilename(filename) { | ||
if (/\.zip$/i.test(filename)) { | ||
return ZIP; | ||
} | ||
if (/\.tar\.gz$/i.test(filename)) { | ||
return TAR; | ||
} | ||
} |