Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e857605
- converted CosmosPartitioned tests
Oct 25, 2019
cd700bd
added CosmosClientOptions test
Oct 25, 2019
64d04ab
- converted cosmosDbStorage tests
Oct 25, 2019
97a79de
converted BlobStorage tests
Oct 25, 2019
c5e2b0d
converted MemoryStorage
Oct 28, 2019
7114010
Merge branch 'master' into storageBaseTests
mdrichardson Oct 28, 2019
6ffe99d
- fixed cosmosPartitioned test
Oct 28, 2019
4c0266c
uncommented test
Oct 28, 2019
170dcb0
Merge branch 'master' into storageBaseTests
mdrichardson Oct 31, 2019
830e7ae
Merge branch 'master' into storageBaseTests
Stevenic Nov 12, 2019
e982805
Merge branch 'master' into storageBaseTests
Stevenic Nov 12, 2019
132fe44
Merge branch 'master' into storageBaseTests
mdrichardson Nov 14, 2019
5816fb5
moved newItem.eTag check to outer if
Nov 14, 2019
c9f91a3
moved empty keys/changes checks under the Promise
Nov 15, 2019
a1b8311
*actually* moved throw under the promise. whoops
Nov 15, 2019
ba6de67
Merge branch 'master' into storageBaseTests
mdrichardson Nov 15, 2019
3b12256
Merge branch 'master' into storageBaseTests
mdrichardson Nov 21, 2019
23fa207
minor typo fix
Nov 21, 2019
9b76498
Merge branch 'master' into storageBaseTests
mdrichardson Nov 27, 2019
eb03049
Merge branch 'master' into storageBaseTests
mdrichardson Dec 9, 2019
c78eabf
Merge branch 'master' into storageBaseTests
mdrichardson Dec 11, 2019
561cc8a
fixed tests
Dec 12, 2019
5c9d98b
fixed tests failing due to doOnce
Dec 12, 2019
0654b15
restore expectedCalls
Dec 12, 2019
928f675
Merge branch 'master' into storageBaseTests
Stevenic Feb 18, 2020
38641f0
Merge branch 'master' into storageBaseTests
Stevenic Feb 19, 2020
f892ac1
Merge branch 'master' into storageBaseTests
Stevenic Feb 19, 2020
6fca920
Merge branch 'master' into storageBaseTests
Stevenic Feb 20, 2020
c1c9cb7
Merge branch 'master' into storageBaseTests
Stevenic Feb 24, 2020
3beec12
Merge branch 'master' into storageBaseTests
mdrichardson Feb 25, 2020
9bf9b42
Merge branch 'master' into storageBaseTests
Stevenic Feb 27, 2020
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
Prev Previous commit
Next Next commit
converted BlobStorage tests
  • Loading branch information
mdrichardson committed Oct 25, 2019
commit 97a79de57c7dea746276b51a5fee6f7cde656b0c
356 changes: 126 additions & 230 deletions libraries/botbuilder-azure/tests/blobStorage.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
const assert = require('assert');
const { BlobStorage } = require('../');
const { StorageBaseTests } = require('../../botbuilder/tests/storageBaseTests');
const azure = require('azure-storage');
const { MockMode, usingNock } = require('./mockHelper.js')
const { MockMode, usingNock } = require('./mockHelper.js');
const nock = require('nock');
const fs = require('fs');

/**
* @param mode controls the nock mode used for the tests. Available options found in ./mockHelper.js.
*/
const mode = process.env.MOCK_MODE || MockMode.lockdown;

const emulatorPath = 'C:/Program Files (x86)/Microsoft Azure Storage Explorer/StorageExplorer.exe';

const getSettings = (container = null) => ({
storageAccountOrConnectionString: 'UseDevelopmentStorage=true;',
containerName: container || 'test'
Expand All @@ -21,254 +28,143 @@ const reset = (done) => {
} else {
done();
}
}

const print = (o) => {
return JSON.stringify(o, null, ' ');
}

testStorage = function () {

const noEmulatorMessage = 'skipping test because azure storage emulator is not running';

it('read of unknown key', function () {
return usingNock(this.test, mode)
.then(({nockDone, context}) => {
let storage = new BlobStorage(getSettings());
return storage.read(['unk'])
.then((result) => {
assert(result != null, 'result should be object');
assert(!result.unk, 'key should be undefined');
})
.catch(reason => {
if (reason.code == 'ECONNREFUSED') {
console.log(noEmulatorMessage);
} else {
assert(false, `should not throw: ${print(reason.message)}`);
}
})
.then(nockDone);
});
};

const checkEmulator = () => {
if (!fs.existsSync(emulatorPath)) {
console.warn('This test requires Azure Storage Emulator! go to https://docs.microsoft.com/en-us/azure/storage/common/storage-use-emulator#get-the-storage-emulator to download and install.');
}
return true;
};

const storage = new BlobStorage(getSettings());

describe('BlobStorage - Constructor', function() {
before('cleanup', reset);
after('cleanup', reset);

it('missing settings should throw error', function() {
assert.throws(() => new BlobStorage(), Error, 'constructor should have thrown error about missing settings.');
});

it('key creation', function () {
return usingNock(this.test, mode)
.then(({nockDone, context}) => {
let storage = new BlobStorage(getSettings());
return storage.write({ keyCreate: { count: 1 } })
.then(() => storage.read(['keyCreate']))
.then((result) => {
assert(result != null, 'result should be object');
assert(result.keyCreate != null, 'keyCreate should be defined');
assert(result.keyCreate.count == 1, 'object should have count of 1');
assert(!result.eTag, 'ETag should be defined');
})
.catch(reason => {
if (reason.code == 'ECONNREFUSED') {
console.log(noEmulatorMessage);
} else {
assert(false, `should not throw: ${print(reason.message)}`);
}
})
.then(nockDone);
});
it('Invalid container name should throw error', function() {
assert.throws(() => new BlobStorage(getSettings('invalid--name')), Error, 'constructor should have thrown error about invalid container name.');
});
});

describe('BlobStorage - Base Storage Tests', function() {
before('cleanup', reset);
after('cleanup', reset);

it('return empty object when reading unknown key', async function() {
checkEmulator();
const { nockDone } = await usingNock(this.test, mode);

const testRan = await StorageBaseTests.returnEmptyObjectWhenReadingUnknownKey(storage);

assert.strictEqual(testRan, true);

it('key update', function () {
return usingNock(this.test, mode)
.then(({nockDone, context}) => {
let storage = new BlobStorage(getSettings());
return storage.write({ keyUpdate: { count: 1 } })
.then(() => storage.read(['keyUpdate']))
.then((result) => {
result.keyUpdate.count = 2;
return storage.write(result)
.then(() => storage.read(['keyUpdate']))
.then((updated) => {
assert(updated.keyUpdate.count == 2, 'object should be updated');
assert(updated.keyUpdate.eTag != result.keyUpdate.eTag, 'Etag should be updated on write');
});
})
.catch(reason => {
if (reason.code == 'ECONNREFUSED') {
console.log(noEmulatorMessage);
} else {
assert(false, `should not throw: ${print(reason.message)}`);
}
})
.then(nockDone);
});
return nockDone();
});

it('invalid eTag', function () {
return usingNock(this.test, mode)
.then(({nockDone, context}) => {
let storage = new BlobStorage(getSettings());
return storage.write({ keyUpdate2: { count: 1 } })
.then(() => storage.read(['keyUpdate2']))
.then((result) => {
result.keyUpdate2.count = 2;
return storage.write(result).then(() => {
result.keyUpdate2.count = 3;
return storage.write(result)
.then(() => assert(false, `should throw an exception on second write with same etag: ${print(reason)}`))
.catch((reason) => { });
});
})
.catch(reason => {
if (reason.code == 'ECONNREFUSED') {
console.log(noEmulatorMessage);
} else {
assert(false, `should not throw: ${print(reason.message)}`);
}
})
.then(nockDone);
});
it('throws when reading null keys', async function() {
checkEmulator();
const { nockDone } = await usingNock(this.test, mode);

const testRan = await StorageBaseTests.handleNullKeysWhenReading(storage);

assert.strictEqual(testRan, true);
return nockDone();
});

it('wildcard eTag', function () {
return usingNock(this.test, mode)
.then(({nockDone, context}) => {
let storage = new BlobStorage(getSettings());
return storage.write({ keyUpdate3: { count: 1 } })
.then(() => storage.read(['keyUpdate3']))
.then((result) => {
result.keyUpdate3.eTag = '*';
result.keyUpdate3.count = 2;
return storage.write(result).then(() => {
result.keyUpdate3.count = 3;
return storage.write(result)
.catch((reason) => assert(false, `should NOT fail on etag writes with wildcard: ${print(reason.message)}`));
});
})
.catch(reason => {
if (reason.code == 'ECONNREFUSED') {
console.log(noEmulatorMessage);
} else {
assert(false, `should not throw: ${print(reason.message)}`);
}
})
.then(nockDone);
});
it('throws when writing null keys', async function() {
checkEmulator();
const { nockDone } = await usingNock(this.test, mode);

const testRan = await StorageBaseTests.handleNullKeysWhenWriting(storage);

assert.strictEqual(testRan, true);
return nockDone();
});

it('delete unknown', function () {
return usingNock(this.test, mode)
.then(({nockDone, context}) => {
let storage = new BlobStorage(getSettings());
return storage.delete(['unknown'])
.catch(reason => {
if (reason.code == 'ECONNREFUSED') {
console.log(noEmulatorMessage);
} else {
assert(false, `should not throw: ${print(reason.message)}`);
}
})
.then(nockDone);
});
it('does not throw when writing no items', async function() {
checkEmulator();
const { nockDone } = await usingNock(this.test, mode);

const testRan = await StorageBaseTests.doesNotThrowWhenWritingNoItems(storage);

assert.strictEqual(testRan, true);
return nockDone();
});

it('delete known', function () {
return usingNock(this.test, mode)
.then(({nockDone, context}) => {
let storage = new BlobStorage(getSettings());
return storage.write({ delete1: { count: 1 } })
.then(() => storage.delete(['delete1']))
.then(() => storage.read(['delete1']))
.then(result => {
if (result.delete1)
console.log(JSON.stringify(result.delete1));
assert(!result.delete1, 'delete1 should not be found');
})
.catch(reason => {
if (reason.code == 'ECONNREFUSED') {
console.log(noEmulatorMessage);
} else {
assert(false, `should not throw: ${print(reason.message)}`);
}
})
.then(nockDone);
});
it('create an object', async function() {
checkEmulator();
const { nockDone } = await usingNock(this.test, mode);

const testRan = await StorageBaseTests.createObject(storage);

assert.strictEqual(testRan, true);
return nockDone();
});

it('batch operations', function () {
return usingNock(this.test, mode)
.then(({nockDone, context}) => {
let storage = new BlobStorage(getSettings());
return storage.write({
batch1: { count: 10 },
batch2: { count: 20 },
batch3: { count: 30 },
})
.then(() => storage.read(['batch1', 'batch2', 'batch3']))
.then((result) => {
assert(result.batch1 != null, 'batch1 should exist and doesnt');
assert(result.batch2 != null, 'batch2 should exist and doesnt');
assert(result.batch3 != null, 'batch3 should exist and doesnt');
assert(result.batch1.count > 0, 'batch1 should have count and doesnt');
assert(result.batch2.count > 0, 'batch2 should have count and doesnt');
assert(result.batch3.count > 0, 'batch3 should have count and doesnt');
assert(result.batch1.eTag != null, 'batch1 should have etag and doesnt');
assert(result.batch2.eTag != null, 'batch2 should have etag and doesnt');
assert(result.batch3.eTag != null, 'batch3 should have etag and doesnt');
})
.then(() => storage.delete(['batch1', 'batch2', 'batch3']))
.then(() => storage.read(['batch1', 'batch2', 'batch3']))
.then((result) => {
assert(!result.batch1, 'batch1 should not exist and does');
assert(!result.batch2, 'batch2 should not exist and does');
assert(!result.batch3, 'batch3 should not exist and does');
})
.catch(reason => {
if (reason.code == 'ECONNREFUSED') {
console.log(noEmulatorMessage);
} else {
assert(false, `should not throw: ${print(reason.message)}`);
}
})
.then(nockDone);
});
it('handle crazy keys', async function() {
checkEmulator();
const { nockDone } = await usingNock(this.test, mode);

const testRan = await StorageBaseTests.handleCrazyKeys(storage);

assert.strictEqual(testRan, true);
return nockDone();
});

it('crazy keys work', function () {
return usingNock(this.test, mode)
.then(({nockDone, context}) => {
let storage = new BlobStorage(getSettings());
let obj = {};
let crazyKey = '!@#$%^&*()_+??><":QASD~`';
obj[crazyKey] = { count: 1 };
return storage.write(obj)
.then(() => storage.read([crazyKey]))
.then((result) => {
assert(result != null, 'result should be object');
assert(result[crazyKey], 'keyCreate should be defined');
assert(result[crazyKey].count == 1, 'object should have count of 1');
assert(result[crazyKey].eTag, 'ETag should be defined');
})
.catch(reason => {
if (reason.code == 'ECONNREFUSED') {
console.log(noEmulatorMessage);
} else {
assert(false, `should not throw: ${print(reason.message)}`);
}
})
.then(nockDone);
});
it('update an object', async function() {
checkEmulator();
const { nockDone } = await usingNock(this.test, mode);

const testRan = await StorageBaseTests.updateObject(storage);

assert.strictEqual(testRan, true);
return nockDone();
});

it('missing settings should throw error', function() {
assert.throws(() => new BlobStorage(), Error, 'constructor should have thrown error about missing settings.');
})
it('delete an object', async function() {
checkEmulator();
const { nockDone } = await usingNock(this.test, mode);

it('Invalid container name should throw error', function() {
assert.throws(() => new BlobStorage(getSettings('invalid--name')), Error, 'constructor should have thrown error about invalid container name.');
})
}
const testRan = await StorageBaseTests.deleteObject(storage);

describe('BlobStorage', function () {
this.timeout(20000);
before('cleanup', reset);
testStorage();
after('cleanup', reset);
assert.strictEqual(testRan, true);
return nockDone();
});

it('does not throw when deleting an unknown object', async function() {
checkEmulator();
const { nockDone } = await usingNock(this.test, mode);

const testRan = await StorageBaseTests.deleteUnknownObject(storage);

assert.strictEqual(testRan, true);
return nockDone();
});

it('performs batch operations', async function() {
checkEmulator();
const { nockDone } = await usingNock(this.test, mode);

const testRan = await StorageBaseTests.performBatchOperations(storage);

assert.strictEqual(testRan, true);
return nockDone();
});

it('proceeds through a waterfall dialog', async function() {
checkEmulator();
const { nockDone } = await usingNock(this.test, mode);

const testRan = await StorageBaseTests.proceedsThroughWaterfall(storage);

assert.strictEqual(testRan, true);
return nockDone();
});
});

Loading