|
| 1 | +// Copyright 2015-2016, Google, Inc. |
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +// you may not use this file except in compliance with the License. |
| 4 | +// You may obtain a copy of the License at |
| 5 | +// |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | + |
| 14 | +'use strict'; |
| 15 | + |
| 16 | +var uuid = require('node-uuid'); |
| 17 | +var program = require('../transfer'); |
| 18 | +var Storage = require('@google-cloud/storage'); |
| 19 | + |
| 20 | +var storage = Storage(); |
| 21 | +var firstBucketName = 'nodejs-docs-samples-test-' + uuid.v4(); |
| 22 | +var secondBucketName = 'nodejs-docs-samples-test-' + uuid.v4(); |
| 23 | + |
| 24 | +describe('storage:transfer', function () { |
| 25 | + var jobName; |
| 26 | + var date = '2222/08/11'; |
| 27 | + var time = '15:30'; |
| 28 | + var description = 'this is a test'; |
| 29 | + var status = 'DISABLED'; |
| 30 | + |
| 31 | + before(function (done) { |
| 32 | + storage.createBucket(firstBucketName, function (err) { |
| 33 | + if (err) { |
| 34 | + return done(err); |
| 35 | + } |
| 36 | + storage.createBucket(secondBucketName, done); |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + after(function (done) { |
| 41 | + storage.bucket(firstBucketName).deleteFiles({ force: true }, function (err) { |
| 42 | + if (err) { |
| 43 | + return done(err); |
| 44 | + } |
| 45 | + storage.bucket(firstBucketName).delete(function (err) { |
| 46 | + if (err) { |
| 47 | + return done(err); |
| 48 | + } |
| 49 | + storage.bucket(secondBucketName).deleteFiles({ force: true }, function (err) { |
| 50 | + if (err) { |
| 51 | + return done(err); |
| 52 | + } |
| 53 | + storage.bucket(secondBucketName).delete(done); |
| 54 | + }); |
| 55 | + }); |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + describe('createTransferJob', function () { |
| 60 | + it('should create a storage transfer job', function (done) { |
| 61 | + program.createTransferJob(firstBucketName, secondBucketName, date, time, description, function (err, transferJob) { |
| 62 | + assert.ifError(err); |
| 63 | + jobName = transferJob.name; |
| 64 | + assert.equal(transferJob.name.indexOf('transferJobs/'), 0); |
| 65 | + assert.equal(transferJob.description, description); |
| 66 | + assert.equal(transferJob.status, 'ENABLED'); |
| 67 | + assert(console.log.calledWith('Created transfer job: %s', transferJob.name)); |
| 68 | + setTimeout(done, 2000); |
| 69 | + }); |
| 70 | + }); |
| 71 | + }); |
| 72 | + |
| 73 | + describe('getTransferJob', function () { |
| 74 | + it('should get a transferJob', function (done) { |
| 75 | + program.getTransferJob(jobName, function (err, transferJob) { |
| 76 | + assert.ifError(err); |
| 77 | + assert.equal(transferJob.name, jobName); |
| 78 | + assert.equal(transferJob.description, description); |
| 79 | + assert.equal(transferJob.status, 'ENABLED'); |
| 80 | + assert(console.log.calledWith('Found transfer job: %s', transferJob.name)); |
| 81 | + setTimeout(done, 2000); |
| 82 | + }); |
| 83 | + }); |
| 84 | + }); |
| 85 | + |
| 86 | + describe('updateTransferJob', function () { |
| 87 | + it('should update a transferJob', function (done) { |
| 88 | + program.updateTransferJob(jobName, 'status', status, function (err, transferJob) { |
| 89 | + assert.ifError(err); |
| 90 | + assert.equal(transferJob.name, jobName); |
| 91 | + assert.equal(transferJob.description, description); |
| 92 | + assert.equal(transferJob.status, status); |
| 93 | + assert(console.log.calledWith('Updated transfer job: %s', transferJob.name)); |
| 94 | + setTimeout(done, 2000); |
| 95 | + }); |
| 96 | + }); |
| 97 | + }); |
| 98 | + |
| 99 | + describe('listTransferJobs', function () { |
| 100 | + it('should list transferJobs', function (done) { |
| 101 | + program.listTransferJobs(function (err, transferJobs) { |
| 102 | + assert.ifError(err); |
| 103 | + var matchingTransferJobs = transferJobs.filter(function (transferJob) { |
| 104 | + return transferJob.name === jobName; |
| 105 | + }); |
| 106 | + assert.equal(matchingTransferJobs.length, 1); |
| 107 | + assert.equal(matchingTransferJobs[0].name, jobName); |
| 108 | + assert.equal(matchingTransferJobs[0].description, description); |
| 109 | + assert.equal(matchingTransferJobs[0].status, status); |
| 110 | + assert(console.log.calledWith('Found %d jobs!', transferJobs.length)); |
| 111 | + setTimeout(done, 2000); |
| 112 | + }); |
| 113 | + }); |
| 114 | + }); |
| 115 | + |
| 116 | + describe('listTransferOperations', function () { |
| 117 | + it('should list transferJobs', function (done) { |
| 118 | + program.listTransferOperations(jobName, function (err, operations) { |
| 119 | + assert.ifError(err); |
| 120 | + assert(Array.isArray(operations)); |
| 121 | + done(); |
| 122 | + }); |
| 123 | + }); |
| 124 | + }); |
| 125 | +}); |
0 commit comments