Skip to content

Commit 1d0a4b3

Browse files
committed
fix(get): improve verbose output, and tests
- remove duplicate info server and user name - use stderr for verbose output
1 parent 9f69606 commit 1d0a4b3

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

commands/get.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,14 @@ async function downloadCollectionOrResource (db, source, target, options) {
206206
const root = resolve(target)
207207

208208
if (options.verbose) {
209-
console.log('Downloading:', source, 'to', root)
210-
console.log(
211-
'Server:',
212-
(db.client.isSecure ? 'https' : 'http') + '://' + db.client.options.host + ':' + db.client.options.port,
213-
'(v' + options.version + ')'
214-
)
215-
console.log('User:', db.client.options.basic_auth.user)
209+
console.error('Downloading:', source, 'to', root)
216210
if (options.include.length > 1 || options.include[0] !== '**') {
217-
console.log('Include:\n', ...options.include, '\n')
211+
console.error('Include:\n', ...options.include, '\n')
218212
}
219213
if (options.exclude.length) {
220-
console.log('Exclude:\n', ...options.exclude, '\n')
214+
console.error('Exclude:\n', ...options.exclude, '\n')
221215
}
222-
console.log(`Downloading up to ${options.threads} resources at a time`)
216+
console.error(`Downloading up to ${options.threads} resources at a time`)
223217
}
224218

225219
// initial file

spec/tests/get.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,21 @@ test('with test collection', async (t) => {
8080
t.test(prepare)
8181

8282
t.test(`can get ${testCollection} as admin`, async (st) => {
83-
const { stderr, stdout } = await run('xst', ['get', testCollection, '.', '--threads', '2'], asAdmin)
83+
const { stderr, stdout } = await run('xst', ['get', testCollection, '.'], asAdmin)
84+
if (stderr) {
85+
return st.fail(stderr)
86+
}
87+
st.plan(3)
88+
89+
st.notOk(stdout, 'no output')
90+
st.deepEqual(readdirSync(testCollectionName), expectedDirectoryListing, 'all files were downloaded')
91+
st.deepEqual(readdirSync(testCollectionName + '/subcollection'), ['b'], 'subcollection contents were downloaded')
92+
93+
await removeLocalDownload()
94+
})
95+
96+
t.test(`can get ${testCollection} as admin with just one thread`, async (st) => {
97+
const { stderr, stdout } = await run('xst', ['get', testCollection, '.', '--threads', '1'], asAdmin)
8498
if (stderr) {
8599
return st.fail(stderr)
86100
}
@@ -94,7 +108,7 @@ test('with test collection', async (t) => {
94108
})
95109

96110
t.test(`cannot get ${testCollection} as guest`, async (st) => {
97-
const { stderr, stdout } = await run('xst', ['get', testCollection, '.', '--threads', '2'])
111+
const { stderr, stdout } = await run('xst', ['get', testCollection, '.'])
98112
if (stdout) {
99113
await removeLocalDownload()
100114
return st.ok(stderr)
@@ -108,17 +122,17 @@ test('with test collection', async (t) => {
108122
})
109123

110124
t.test(`'xst get --verbose ${testCollection}' as admin`, async (st) => {
111-
const { stderr, stdout } = await run('xst', ['get', '--verbose', testCollection, '.', '--threads', '2'], asAdmin)
125+
const { stderr, stdout } = await run('xst', ['get', '--verbose', testCollection, '.'], asAdmin)
112126
st.plan(9)
113-
st.equal(stderr, 'Connecting to https://localhost:8443 as admin\n', stderr)
127+
const verboseLines = stderr.split('\n')
128+
st.equal(verboseLines[0], 'Connecting to https://localhost:8443 as admin', verboseLines[0])
129+
st.ok(verboseLines[1].startsWith('Downloading: /db/get-test to'), verboseLines[1])
130+
st.equal(verboseLines[2], 'Downloading up to 4 resources at a time', verboseLines[2])
131+
st.equal(verboseLines[3], '', verboseLines[3])
132+
st.equal(verboseLines.length, 4, 'all expected lines in verbose output')
114133

115134
const lines = stdout.split('\n')
116135

117-
st.ok(lines[0].startsWith('Downloading: /db/get-test to '))
118-
// Server: https://localhost:8443 (v6.1.0-SNAPSHOT)
119-
st.ok(/Server: [^ ]+ \(v\d+\.\d+.\d+(-[\w\d]+)?\)/.exec(lines[1]))
120-
st.equal(lines[2], 'User: admin')
121-
st.equal(lines.length, 16, 'all expected lines in verbose output')
122136
// files are not downloaded in reproducible order
123137
st.equal(
124138
lines.filter((l) => /^ created directory [/\w]+\/get-test/.exec(l)).length,

0 commit comments

Comments
 (0)