Skip to content

Commit

Permalink
Update cli tests and add age parameter to list.
Browse files Browse the repository at this point in the history
  • Loading branch information
saul-jb committed Apr 11, 2024
1 parent 06ba63e commit d75d3d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
15 changes: 10 additions & 5 deletions packages/cli/src/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ export const command = 'list'

export const desc = 'List all items.'

export const builder = createBuilder({})
export const builder = createBuilder({
age: {
type: 'number',
default: 60000
}
})

const formatSize = (size: number): string => {
if (size > Math.pow(1000, 3)) {
Expand Down Expand Up @@ -73,19 +78,17 @@ export const handler = createHandler<typeof builder>(async function * (argv) {
blocks: number
size: number
}> => {
const age = 60000

if (argv.client == null) {
throw new Error('Failed to connect to daemon.')
}

const [[{ status, blocks, size }], [agedStateData], [{ peers }]] = await Promise.all([
argv.client.getState([cid]),
argv.client.getState([cid], { age }),
argv.client.getState([cid], { age: argv.age }),
argv.client.countPeers([cid])
])

const speed = agedStateData.size / (age / 1000)
const speed = agedStateData.size / (argv.age / 1000)

if (status === 'COMPLETED') {
completed.count++
Expand Down Expand Up @@ -118,6 +121,8 @@ export const handler = createHandler<typeof builder>(async function * (argv) {
'CID'.padEnd(62)
].join('')

yield ''

yield * pipe(
getDataFuncs,
i => parallel(i, { ordered: false, concurrency: 5 }),
Expand Down
18 changes: 9 additions & 9 deletions packages/cli/test/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ describe('list', () => {
]

it('text', async () => {
const params = mockParams({ list: items, countPeers: [{ cid, peers: 1 }], getState: [{ cid, status: 'COMPLETED', size: 50, blocks: 5 }] }, { group: 'group-abc' })
const params = mockParams({ list: items, countPeers: [{ cid, peers: 1 }], getState: [{ cid, status: 'COMPLETED', size: 50, blocks: 5 }] }, { group: 'group-abc', age: 5000 })

const response = await all(handler(params))

const expected = [
[
'Name'.padEnd(20),
'Name'.padEnd(50),
'Size'.padEnd(27),
'Speed'.padEnd(27),
'Blocks'.padEnd(20),
Expand All @@ -42,14 +42,13 @@ describe('list', () => {
'R-Strategy'.padEnd(12),
'CID'.padEnd(62)
].join(''),
'/',
' my-dir/',
'',
[
' file ',
'50 B/500 B (10%) ',
'10 B/s (45 s) ',
'5/50 (10%) ',
'COMPLETED ',
'/my-dir/file'.padEnd(50),
'50 B/500 B (10%)'.padEnd(27),
'10 B/s (45 s)'.padEnd(27),
'5/50 (10%)'.padEnd(20),
'COMPLETED'.padEnd(15),
'1 0 1 ',
'QmaCpDMG false all ',
'QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN '
Expand Down Expand Up @@ -79,6 +78,7 @@ describe('list', () => {
getState: [{ cid, status: 'COMPLETED', size: 50, blocks: 5 }]
}, {
group: 'group-abc',
age: 5000,
json: true
})

Expand Down

0 comments on commit d75d3d3

Please sign in to comment.