-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(storage-transfer): convert ava tests to mocha #1202
Changes from all commits
1dd0508
02a9435
9c1bb2c
846f982
57fa580
f7acfc4
70f8064
715dfb2
24b7082
654090b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,49 +16,46 @@ | |
/* eslint no-empty: 0 */ | ||
'use strict'; | ||
|
||
const {Storage} = require(`@google-cloud/storage`); | ||
const {Storage} = require('@google-cloud/storage'); | ||
const storage = new Storage(); | ||
const test = require(`ava`); | ||
const tools = require(`@google-cloud/nodejs-repo-tools`); | ||
const uuid = require(`uuid`); | ||
const assert = require('assert'); | ||
const tools = require('@google-cloud/nodejs-repo-tools'); | ||
const uuid = require('uuid'); | ||
|
||
const program = require(`../transfer`); | ||
const program = require('../transfer'); | ||
|
||
const firstBucketName = `nodejs-docs-samples-test-${uuid.v4()}`; | ||
const secondBucketName = `nodejs-docs-samples-test-${uuid.v4()}`; | ||
|
||
let jobName; | ||
const date = `2222/08/11`; | ||
const time = `15:30`; | ||
const description = `this is a test`; | ||
const status = `DISABLED`; | ||
const date = '2222/08/11'; | ||
const time = '15:30'; | ||
const description = 'this is a test'; | ||
const status = 'DISABLED'; | ||
|
||
test.before(tools.checkCredentials); | ||
test.before(async () => { | ||
before(async () => { | ||
tools.checkCredentials(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have just dropped that line from all the samples, and the console stubbing. It's fine. Should we drop it here too? |
||
tools.stubConsole(); | ||
|
||
const bucketOptions = { | ||
entity: 'allUsers', | ||
role: storage.acl.WRITER_ROLE, | ||
}; | ||
await storage.createBucket(firstBucketName).then(data => { | ||
const bucket = data[0]; | ||
return bucket.acl.add(bucketOptions); | ||
}); | ||
await storage.createBucket(secondBucketName).then(data => { | ||
const bucket = data[0]; | ||
return bucket.acl.add(bucketOptions); | ||
}); | ||
const [bucket1] = await storage.createBucket(firstBucketName); | ||
await bucket1.acl.add(bucketOptions); | ||
const [bucket2] = await storage.createBucket(secondBucketName); | ||
await bucket2.acl.add(bucketOptions); | ||
}); | ||
|
||
test.after.always(async () => { | ||
after(async () => { | ||
tools.restoreConsole(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, we just dropped this |
||
const bucketOne = storage.bucket(firstBucketName); | ||
const bucketTwo = storage.bucket(secondBucketName); | ||
try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for readability, could this be: // Attempt to do the delete twice, and swallow any errors
for (let i=0; i<2; i++) {
await bucketOne.deleteFiles({force: true}).catch(console.warn);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you dare adding |
||
bucketOne.deleteFiles({force: true}); | ||
} catch (err) {} // ignore error | ||
try { | ||
// Intentially, try a second time. | ||
bucketOne.deleteFiles({force: true}); | ||
} catch (err) {} // ignore error | ||
try { | ||
|
@@ -75,7 +72,7 @@ test.after.always(async () => { | |
} catch (err) {} // ignore error | ||
}); | ||
|
||
test.cb.serial(`should create a storage transfer job`, t => { | ||
it('should create a storage transfer job', done => { | ||
const options = { | ||
srcBucket: firstBucketName, | ||
destBucket: secondBucketName, | ||
|
@@ -85,65 +82,80 @@ test.cb.serial(`should create a storage transfer job`, t => { | |
}; | ||
|
||
program.createTransferJob(options, (err, transferJob) => { | ||
t.ifError(err); | ||
assert.ifError(err); | ||
jobName = transferJob.name; | ||
t.is(transferJob.name.indexOf(`transferJobs/`), 0); | ||
t.is(transferJob.description, description); | ||
t.is(transferJob.status, `ENABLED`); | ||
t.true( | ||
console.log.calledWith(`Created transfer job: %s`, transferJob.name) | ||
assert.strictEqual(transferJob.name.indexOf('transferJobs/'), 0); | ||
assert.strictEqual(transferJob.description, description); | ||
assert.strictEqual(transferJob.status, 'ENABLED'); | ||
assert.strictEqual( | ||
console.log.calledWith('Created transfer job: %s', transferJob.name), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhh, I see why the console.log stubbing now. |
||
true | ||
); | ||
setTimeout(t.end, 2000); | ||
done(); | ||
}); | ||
}); | ||
|
||
test.cb.serial(`should get a transferJob`, t => { | ||
it('should get a transferJob', done => { | ||
program.getTransferJob(jobName, (err, transferJob) => { | ||
t.ifError(err); | ||
t.is(transferJob.name, jobName); | ||
t.is(transferJob.description, description); | ||
t.is(transferJob.status, `ENABLED`); | ||
t.true(console.log.calledWith(`Found transfer job: %s`, transferJob.name)); | ||
setTimeout(t.end, 2000); | ||
assert.ifError(err); | ||
assert.strictEqual(transferJob.name, jobName); | ||
assert.strictEqual(transferJob.description, description); | ||
assert.strictEqual(transferJob.status, 'ENABLED'); | ||
assert.strictEqual( | ||
console.log.calledWith('Found transfer job: %s', transferJob.name), | ||
true | ||
); | ||
done(); | ||
}); | ||
}); | ||
|
||
test.cb.serial(`should update a transferJob`, t => { | ||
it('should update a transferJob', done => { | ||
var options = { | ||
job: jobName, | ||
field: `status`, | ||
field: 'status', | ||
value: status, | ||
}; | ||
|
||
program.updateTransferJob(options, (err, transferJob) => { | ||
t.ifError(err); | ||
t.is(transferJob.name, jobName); | ||
t.is(transferJob.description, description); | ||
t.is(transferJob.status, status); | ||
t.true( | ||
console.log.calledWith(`Updated transfer job: %s`, transferJob.name) | ||
assert.ifError(err); | ||
assert.strictEqual(transferJob.name, jobName); | ||
assert.strictEqual(transferJob.description, description); | ||
assert.strictEqual(transferJob.status, status); | ||
assert.strictEqual( | ||
console.log.calledWith('Updated transfer job: %s', transferJob.name), | ||
true | ||
); | ||
setTimeout(t.end, 2000); | ||
done(); | ||
}); | ||
}); | ||
|
||
test.cb.serial(`should list transferJobs`, t => { | ||
it('should list transferJobs', done => { | ||
program.listTransferJobs((err, transferJobs) => { | ||
t.ifError(err); | ||
t.true(transferJobs.some(transferJob => transferJob.name === jobName)); | ||
t.true( | ||
transferJobs.some(transferJob => transferJob.description === description) | ||
assert.ifError(err); | ||
assert.strictEqual( | ||
transferJobs.some(transferJob => transferJob.name === jobName), | ||
true | ||
); | ||
assert.strictEqual( | ||
transferJobs.some(transferJob => transferJob.description === description), | ||
true | ||
); | ||
assert.strictEqual( | ||
transferJobs.some(transferJob => transferJob.status === status), | ||
true | ||
); | ||
assert.strictEqual( | ||
console.log.calledWith('Found %d jobs!', transferJobs.length), | ||
true | ||
); | ||
t.true(transferJobs.some(transferJob => transferJob.status === status)); | ||
t.true(console.log.calledWith(`Found %d jobs!`, transferJobs.length)); | ||
setTimeout(t.end, 2000); | ||
done(); | ||
}); | ||
}); | ||
|
||
test.cb.serial(`should list transferJobs`, t => { | ||
it('should list transferOperations', done => { | ||
program.listTransferOperations(jobName, (err, operations) => { | ||
t.ifError(err); | ||
t.true(Array.isArray(operations)); | ||
t.end(); | ||
assert.ifError(err); | ||
assert.strictEqual(Array.isArray(operations), true); | ||
done(); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So no need to block on this feedback, but I would rather just use
mocha --timeout=10000
across the board here. That way if a new test gets added to thetest
directory, you don't have to worry about it having the right prefix.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to change it, I'll do it in a separate PR for all the folders.