-
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
Start storagetransfer samples. #168
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Copyright 2015-2016, Google, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
var uuid = require('node-uuid'); | ||
var program = require('../transfer'); | ||
var Storage = require('@google-cloud/storage'); | ||
|
||
var storage = Storage(); | ||
var firstBucketName = 'nodejs-docs-samples-test-' + uuid.v4(); | ||
var secondBucketName = 'nodejs-docs-samples-test-' + uuid.v4(); | ||
|
||
describe('storage:transfer', function () { | ||
var jobName; | ||
var date = '2222/08/11'; | ||
var time = '15:30'; | ||
var description = 'this is a test'; | ||
var status = 'DISABLED'; | ||
|
||
before(function (done) { | ||
storage.createBucket(firstBucketName, function (err) { | ||
if (err) { | ||
return done(err); | ||
} | ||
storage.createBucket(secondBucketName, done); | ||
}); | ||
}); | ||
|
||
after(function (done) { | ||
storage.bucket(firstBucketName).deleteFiles({ force: true }, function (err) { | ||
if (err) { | ||
return done(err); | ||
} | ||
storage.bucket(firstBucketName).delete(function (err) { | ||
if (err) { | ||
return done(err); | ||
} | ||
storage.bucket(secondBucketName).deleteFiles({ force: true }, function (err) { | ||
if (err) { | ||
return done(err); | ||
} | ||
storage.bucket(secondBucketName).delete(done); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('createTransferJob', function () { | ||
it('should create a storage transfer job', function (done) { | ||
program.createTransferJob(firstBucketName, secondBucketName, date, time, description, function (err, transferJob) { | ||
assert.ifError(err); | ||
jobName = transferJob.name; | ||
assert.equal(transferJob.name.indexOf('transferJobs/'), 0); | ||
assert.equal(transferJob.description, description); | ||
assert.equal(transferJob.status, 'ENABLED'); | ||
assert(console.log.calledWith('Created transfer job: %s', transferJob.name)); | ||
setTimeout(done, 2000); | ||
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. Is there a cleaner way to implement this delay? 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. That's as short as it gets. |
||
}); | ||
}); | ||
}); | ||
|
||
describe('getTransferJob', function () { | ||
it('should get a transferJob', function (done) { | ||
program.getTransferJob(jobName, function (err, transferJob) { | ||
assert.ifError(err); | ||
assert.equal(transferJob.name, jobName); | ||
assert.equal(transferJob.description, description); | ||
assert.equal(transferJob.status, 'ENABLED'); | ||
assert(console.log.calledWith('Found transfer job: %s', transferJob.name)); | ||
setTimeout(done, 2000); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('updateTransferJob', function () { | ||
it('should update a transferJob', function (done) { | ||
program.updateTransferJob(jobName, 'status', status, function (err, transferJob) { | ||
assert.ifError(err); | ||
assert.equal(transferJob.name, jobName); | ||
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. Should we create an object (with the correct job properties) and use 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. Nah, I don't want to validate that the Storage Transfer API is responding with all of the correct fields. Ideally they have their own tests for that. This assertion is sufficient to say yes, the sample used the client library to hit a service and we got a response back the looks okay. Now, if the sample itself were using some other fields, then maybe we'd want to verify them. |
||
assert.equal(transferJob.description, description); | ||
assert.equal(transferJob.status, status); | ||
assert(console.log.calledWith('Updated transfer job: %s', transferJob.name)); | ||
setTimeout(done, 2000); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('listTransferJobs', function () { | ||
it('should list transferJobs', function (done) { | ||
program.listTransferJobs(function (err, transferJobs) { | ||
assert.ifError(err); | ||
var matchingTransferJobs = transferJobs.filter(function (transferJob) { | ||
return transferJob.name === jobName; | ||
}); | ||
assert.equal(matchingTransferJobs.length, 1); | ||
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. Create an object? 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. See #168 (comment) |
||
assert.equal(matchingTransferJobs[0].name, jobName); | ||
assert.equal(matchingTransferJobs[0].description, description); | ||
assert.equal(matchingTransferJobs[0].status, status); | ||
assert(console.log.calledWith('Found %d jobs!', transferJobs.length)); | ||
setTimeout(done, 2000); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('listTransferOperations', function () { | ||
it('should list transferJobs', function (done) { | ||
program.listTransferOperations(jobName, function (err, operations) { | ||
assert.ifError(err); | ||
assert(Array.isArray(operations)); | ||
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.
What is the purpose of this?
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.
jobName
is re-used in subsequent tests.