fix(parse): revert to 0.2 API (#10)
This commit is contained in:
parent
0031c2a9b7
commit
32f4d42e59
@ -5,14 +5,8 @@ import trimStart from 'lodash/trimStart'
|
||||
|
||||
const sanitizePath = (...paths) => filter(map(paths, s => s && filter(map(s.split('/'), trim)).join('/'))).join('/')
|
||||
|
||||
export const parse = url => {
|
||||
if (typeof url === 'object') {
|
||||
url = url.url
|
||||
}
|
||||
|
||||
const remote = {url}
|
||||
|
||||
const [type, rest] = url.split('://')
|
||||
export const parse = remote => {
|
||||
const [type, rest] = remote.url.split('://')
|
||||
if (type === 'file') {
|
||||
remote.type = 'local'
|
||||
remote.path = `/${trimStart(rest, '/')}` // the leading slash has been forgotten on client side first implementation
|
||||
|
@ -11,36 +11,34 @@ import { parse, format } from './'
|
||||
// Data used for both parse and format (i.e. correctly formatted).
|
||||
const data = {
|
||||
file: {
|
||||
url: 'file:///var/lib/xoa/backup',
|
||||
type: 'local',
|
||||
path: '/var/lib/xoa/backup'
|
||||
in: {
|
||||
url: 'file:///var/lib/xoa/backup',
|
||||
name: 'fileRemote'
|
||||
},
|
||||
out: {
|
||||
url: 'file:///var/lib/xoa/backup',
|
||||
type: 'local',
|
||||
path: '/var/lib/xoa/backup',
|
||||
name: 'fileRemote'
|
||||
},
|
||||
url: 'file:///var/lib/xoa/backup'
|
||||
},
|
||||
SMB: {
|
||||
url: 'smb://Administrator:password@toto\\\\192.168.100.225\\smb\0',
|
||||
type: 'smb',
|
||||
host: '192.168.100.225\\smb',
|
||||
path: '',
|
||||
domain: 'toto',
|
||||
username: 'Administrator',
|
||||
password: 'password'
|
||||
},
|
||||
'SMB with @ sign in password': {
|
||||
url: 'smb://Administrator:pass@word@toto\\\\192.168.100.225\\smb\0',
|
||||
type: 'smb',
|
||||
host: '192.168.100.225\\smb',
|
||||
path: '',
|
||||
domain: 'toto',
|
||||
username: 'Administrator',
|
||||
password: 'pass@word'
|
||||
},
|
||||
'SMB with colon in password': {
|
||||
url: 'smb://Administrator:pass:word@toto\\\\192.168.100.225\\smb\0',
|
||||
type: 'smb',
|
||||
host: '192.168.100.225\\smb',
|
||||
path: '',
|
||||
domain: 'toto',
|
||||
username: 'Administrator',
|
||||
password: 'pass:word'
|
||||
in: {
|
||||
url: 'smb://Administrator:pas:sw@ord@toto\\\\192.168.100.225\\smb\0',
|
||||
name: 'smbRemote'
|
||||
},
|
||||
out: {
|
||||
url: 'smb://Administrator:pas:sw@ord@toto\\\\192.168.100.225\\smb\0',
|
||||
type: 'smb',
|
||||
host: '192.168.100.225\\smb',
|
||||
path: '',
|
||||
domain: 'toto',
|
||||
username: 'Administrator',
|
||||
password: 'pas:sw@ord',
|
||||
name: 'smbRemote'
|
||||
},
|
||||
url: 'smb://Administrator:pas:sw@ord@toto\\\\192.168.100.225\\smb\0'
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,9 +46,17 @@ const parseData = {
|
||||
...data,
|
||||
|
||||
'file with missing leading slash (#7)': {
|
||||
url: 'file://var/lib/xoa/backup',
|
||||
type: 'local',
|
||||
path: '/var/lib/xoa/backup'
|
||||
in: {
|
||||
url: 'file://var/lib/xoa/backup',
|
||||
name: 'fileRemote'
|
||||
},
|
||||
out: {
|
||||
url: 'file://var/lib/xoa/backup',
|
||||
type: 'local',
|
||||
path: '/var/lib/xoa/backup',
|
||||
name: 'fileRemote'
|
||||
},
|
||||
url: 'file:///var/lib/xoa/backup'
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +68,7 @@ describe('format', () => {
|
||||
for (const name in formatData) {
|
||||
const datum = formatData[name]
|
||||
it(name, () => {
|
||||
expect(format(datum)).to.equal(datum.url)
|
||||
expect(format({...datum.out})).to.equal(datum.url)
|
||||
})
|
||||
}
|
||||
})
|
||||
@ -71,7 +77,7 @@ describe('parse', () => {
|
||||
for (const name in parseData) {
|
||||
const datum = parseData[name]
|
||||
it(name, () => {
|
||||
expect(parse(datum)).to.eql(datum)
|
||||
expect(parse({...datum.in})).to.eql(datum.out)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user