Skip to content
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

Merged
merged 2 commits into from
Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
},
"dependencies": {
"@google-cloud/storage": "^0.1.1"
"@google-cloud/storage": "^0.1.1",
"googleapis": "^12.2.0",
"moment": "^2.14.1"
},
"devDependencies": {
"mocha": "^3.0.2",
Expand Down
125 changes: 125 additions & 0 deletions storage/system-test/transfer.test.js
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 bucketName = 'nodejs-docs-samples-test-' + uuid.v4();
var bucketName2 = 'nodejs-docs-samples-test-' + uuid.v4();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind calling this something like "firstBucketName" and "secondBucketName"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.


describe.only('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(bucketName, function (err) {
if (err) {
return done(err);
}
storage.createBucket(bucketName2, done);
});
});

after(function (done) {
storage.bucket(bucketName).deleteFiles({ force: true }, function (err) {
if (err) {
return done(err);
}
storage.bucket(bucketName).delete(function (err) {
if (err) {
return done(err);
}
storage.bucket(bucketName2).deleteFiles({ force: true }, function (err) {
if (err) {
return done(err);
}
storage.bucket(bucketName2).delete(done);
});
});
});
});

describe('createTransferJob', function () {
it('should create a storage transfer job', function (done) {
program.createTransferJob(bucketName, bucketName2, date, time, description, function (err, transferJob) {
assert.ifError(err);
jobName = transferJob.name;
Copy link
Contributor

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?

Copy link
Member Author

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.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a cleaner way to implement this delay?

Copy link
Member Author

Choose a reason for hiding this comment

The 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);
Copy link
Contributor

@ace-n ace-n Aug 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we create an object (with the correct job properties) and use deepEqual or something like that here?

Copy link
Member Author

Choose a reason for hiding this comment

The 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create an object?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
});
});
});
});
Loading