-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94e5160
commit d59af8d
Showing
2 changed files
with
102 additions
and
66 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 |
---|---|---|
@@ -1,88 +1,116 @@ | ||
import { | ||
bucketAndKeyParamsFromPath, | ||
buildDirectoryPath, | ||
getDirectorySegmentsFromPath, | ||
getParentDirectoryPath, | ||
join, | ||
} from './paths' | ||
|
||
describe('join', () => { | ||
it('a', () => { | ||
expect(join('bucket/dir/', '/path/to/file.txt')).toEqual( | ||
'bucket/dir/path/to/file.txt' | ||
) | ||
}) | ||
it('b', () => { | ||
expect(join('bucket/dir/', '')).toEqual('bucket/dir/') | ||
}) | ||
it('b', () => { | ||
expect(join('bucket/dir/', '/')).toEqual('bucket/dir/') | ||
describe('paths', () => { | ||
describe('join', () => { | ||
it('a', () => { | ||
expect(join('bucket/dir/', '/path/to/file.txt')).toEqual( | ||
'bucket/dir/path/to/file.txt' | ||
) | ||
}) | ||
it('b', () => { | ||
expect(join('bucket/dir/', '')).toEqual('bucket/dir/') | ||
}) | ||
it('b', () => { | ||
expect(join('bucket/dir/', '/')).toEqual('bucket/dir/') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('buildDirPath', () => { | ||
it('a', () => { | ||
expect(buildDirectoryPath('bucket/dir/', '/path/to/dir')).toEqual( | ||
'bucket/dir/path/to/dir/' | ||
) | ||
}) | ||
it('b', () => { | ||
expect(buildDirectoryPath('bucket/dir/', '')).toEqual('bucket/dir/') | ||
}) | ||
it('c', () => { | ||
expect(buildDirectoryPath('bucket/dir/', '/')).toEqual('bucket/dir/') | ||
describe('buildDirPath', () => { | ||
it('a', () => { | ||
expect(buildDirectoryPath('bucket/dir/', '/path/to/dir')).toEqual( | ||
'bucket/dir/path/to/dir/' | ||
) | ||
}) | ||
it('b', () => { | ||
expect(buildDirectoryPath('bucket/dir/', '')).toEqual('bucket/dir/') | ||
}) | ||
it('c', () => { | ||
expect(buildDirectoryPath('bucket/dir/', '/')).toEqual('bucket/dir/') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('getParentDirectoryPath', () => { | ||
it('a', () => { | ||
expect(getParentDirectoryPath('bucket/dir/')).toEqual('bucket/') | ||
}) | ||
it('b', () => { | ||
expect(getParentDirectoryPath('bucket/dir')).toEqual('bucket/') | ||
}) | ||
it('c', () => { | ||
expect(getParentDirectoryPath('/')).toEqual('/') | ||
}) | ||
it('d', () => { | ||
expect(getParentDirectoryPath('')).toEqual('/') | ||
describe('getParentDirectoryPath', () => { | ||
it('a', () => { | ||
expect(getParentDirectoryPath('bucket/dir/')).toEqual('bucket/') | ||
}) | ||
it('b', () => { | ||
expect(getParentDirectoryPath('bucket/dir')).toEqual('bucket/') | ||
}) | ||
it('c', () => { | ||
expect(getParentDirectoryPath('/')).toEqual('/') | ||
}) | ||
it('d', () => { | ||
expect(getParentDirectoryPath('')).toEqual('/') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('bucketAndKeyParamsFromPath', () => { | ||
it('works for file', () => { | ||
expect(bucketAndKeyParamsFromPath('bucket/path/to/file.txt')).toEqual({ | ||
bucket: 'bucket', | ||
key: 'path/to/file.txt', | ||
describe('getDirectorySegmentsFromPath', () => { | ||
it('directory path', () => { | ||
expect(getDirectorySegmentsFromPath('bucket/dir/')).toEqual([ | ||
'bucket', | ||
'dir', | ||
]) | ||
}) | ||
it('file path', () => { | ||
expect(getDirectorySegmentsFromPath('bucket/dir/foo')).toEqual([ | ||
'bucket', | ||
'dir', | ||
]) | ||
}) | ||
it('malformed path', () => { | ||
expect(getDirectorySegmentsFromPath('/bucket/dir/foo')).toEqual([ | ||
'bucket', | ||
'dir', | ||
]) | ||
expect(getDirectorySegmentsFromPath('//bucket/dir/foo')).toEqual([ | ||
'bucket', | ||
'dir', | ||
]) | ||
}) | ||
}) | ||
|
||
it('works for file with hash in path', () => { | ||
expect( | ||
bucketAndKeyParamsFromPath('bucket/path#/to#hash/file#hash.txt') | ||
).toEqual({ | ||
bucket: 'bucket', | ||
key: 'path%23/to%23hash/file%23hash.txt', | ||
describe('bucketAndKeyParamsFromPath', () => { | ||
it('works for file', () => { | ||
expect(bucketAndKeyParamsFromPath('bucket/path/to/file.txt')).toEqual({ | ||
bucket: 'bucket', | ||
key: 'path/to/file.txt', | ||
}) | ||
}) | ||
}) | ||
|
||
it('works for directory', () => { | ||
expect(bucketAndKeyParamsFromPath('bucket/path/to/directory/')).toEqual({ | ||
bucket: 'bucket', | ||
key: 'path/to/directory/', | ||
it('works for file with hash in path', () => { | ||
expect( | ||
bucketAndKeyParamsFromPath('bucket/path#/to#hash/file#hash.txt') | ||
).toEqual({ | ||
bucket: 'bucket', | ||
key: 'path%23/to%23hash/file%23hash.txt', | ||
}) | ||
}) | ||
}) | ||
|
||
it('works for empty', () => { | ||
expect(bucketAndKeyParamsFromPath('bucket')).toEqual({ | ||
bucket: 'bucket', | ||
key: '', | ||
it('works for directory', () => { | ||
expect(bucketAndKeyParamsFromPath('bucket/path/to/directory/')).toEqual({ | ||
bucket: 'bucket', | ||
key: 'path/to/directory/', | ||
}) | ||
}) | ||
|
||
it('works for empty', () => { | ||
expect(bucketAndKeyParamsFromPath('bucket')).toEqual({ | ||
bucket: 'bucket', | ||
key: '', | ||
}) | ||
}) | ||
}) | ||
|
||
it('works for empty with trailing', () => { | ||
expect(bucketAndKeyParamsFromPath('bucket/')).toEqual({ | ||
bucket: 'bucket', | ||
key: '', | ||
it('works for empty with trailing', () => { | ||
expect(bucketAndKeyParamsFromPath('bucket/')).toEqual({ | ||
bucket: 'bucket', | ||
key: '', | ||
}) | ||
}) | ||
}) | ||
}) |
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