2014-02-17 22:44:00 +04:00
|
|
|
//
|
2013-11-08 10:22:08 +04:00
|
|
|
// Copyright (c) Microsoft and contributors. All rights reserved.
|
2014-02-17 22:44:00 +04:00
|
|
|
//
|
2013-11-08 10:22:08 +04:00
|
|
|
// 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
|
2014-02-17 22:44:00 +04:00
|
|
|
//
|
2013-11-08 10:22:08 +04:00
|
|
|
// 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.
|
2014-02-17 22:44:00 +04:00
|
|
|
//
|
2013-11-08 10:22:08 +04:00
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2014-02-17 22:44:00 +04:00
|
|
|
//
|
2013-02-21 16:37:27 +04:00
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
var util = require('util');
|
|
|
|
|
2014-02-17 22:44:00 +04:00
|
|
|
var existsSync = fs.existsSync;
|
|
|
|
if (!existsSync) {
|
|
|
|
existsSync = require('path').existsSync;
|
|
|
|
}
|
|
|
|
|
2013-02-21 16:37:27 +04:00
|
|
|
var MockedTestUtils = require('./mocked-test-utils');
|
|
|
|
|
|
|
|
function BlobTestUtils(service, testPrefix) {
|
|
|
|
BlobTestUtils.super_.call(this, service, testPrefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
util.inherits(BlobTestUtils, MockedTestUtils);
|
|
|
|
|
|
|
|
BlobTestUtils.prototype.teardownTest = function (callback) {
|
|
|
|
var self = this;
|
|
|
|
|
2014-02-17 22:44:00 +04:00
|
|
|
function asyncDeleteFiles(files, count, callback) {
|
|
|
|
if (count > 3) {
|
|
|
|
throw new Error('Could not delete file ' + files[0]);
|
|
|
|
}
|
|
|
|
if (files.length === 0) {
|
|
|
|
return callback();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (existsSync(files[0])) {
|
|
|
|
fs.unlinkSync(files[0]);
|
|
|
|
}
|
|
|
|
asyncDeleteFiles(files.slice(1), 0, callback);
|
|
|
|
} catch (ex) {
|
|
|
|
setTimeout(function () { asyncDeleteFiles(files, count + 1, callback); }, 1500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-21 16:37:27 +04:00
|
|
|
var deleteFiles = function () {
|
|
|
|
// delete test files
|
2014-02-17 22:44:00 +04:00
|
|
|
var list = fs.readdirSync('./').filter(function (f) { return f.indexOf('.test') !== -1; });
|
|
|
|
asyncDeleteFiles(list, 0, function (err) {
|
|
|
|
self.baseTeardownTest(callback);
|
2013-02-21 16:37:27 +04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var deleteContainers = function (containers, done) {
|
|
|
|
if (!containers || containers.length <= 0) {
|
|
|
|
done();
|
|
|
|
} else {
|
|
|
|
var currentContainer = containers.pop();
|
|
|
|
self.service.deleteContainer(currentContainer.name, function () {
|
|
|
|
deleteContainers(containers, done);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// delete blob containers
|
|
|
|
self.service.listContainers(function (listError, containers) {
|
|
|
|
deleteContainers(containers, function () {
|
|
|
|
// clean up
|
|
|
|
deleteFiles();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.createBlobTestUtils = function (service, testPrefix) {
|
|
|
|
return new BlobTestUtils(service, testPrefix);
|
|
|
|
};
|