Added unit tests for util.getTransferables
This commit is contained in:
parent
6547b4ef68
commit
25131e0df9
|
@ -64,7 +64,7 @@ export default {
|
||||||
if (config.zeroCopy && Object.prototype.isPrototypeOf(obj)) {
|
if (config.zeroCopy && Object.prototype.isPrototypeOf(obj)) {
|
||||||
const transferables = [];
|
const transferables = [];
|
||||||
this.collectBuffers(obj, transferables);
|
this.collectBuffers(obj, transferables);
|
||||||
return transferables;
|
return transferables.length ? transferables : undefined;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var openpgp = typeof window != 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
|
var openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
|
||||||
|
|
||||||
function stringify(array) {
|
function stringify(array) {
|
||||||
if(!Uint8Array.prototype.isPrototypeOf(array)) {
|
if(!Uint8Array.prototype.isPrototypeOf(array)) {
|
||||||
|
|
|
@ -144,4 +144,40 @@ describe('Util unit tests', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getTransferables', function() {
|
||||||
|
var zeroCopyVal,
|
||||||
|
buf1 = new Uint8Array(1),
|
||||||
|
buf2 = new Uint8Array(1),
|
||||||
|
obj = {
|
||||||
|
data1: buf1,
|
||||||
|
data2: buf1,
|
||||||
|
data3: {
|
||||||
|
data4: buf2
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
zeroCopyVal = openpgp.config.zeroCopy;
|
||||||
|
openpgp.config.zeroCopy = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
openpgp.config.zeroCopy = zeroCopyVal;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return undefined when zeroCopy is false', function() {
|
||||||
|
openpgp.config.zeroCopy = false;
|
||||||
|
expect(openpgp.util.getTransferables(obj)).to.be.undefined;
|
||||||
|
});
|
||||||
|
it('should return undefined for no input', function() {
|
||||||
|
expect(openpgp.util.getTransferables()).to.be.undefined;
|
||||||
|
});
|
||||||
|
it('should return undefined for an empty oject', function() {
|
||||||
|
expect(openpgp.util.getTransferables({})).to.be.undefined;
|
||||||
|
});
|
||||||
|
it('should return two buffers', function() {
|
||||||
|
expect(openpgp.util.getTransferables(obj)).to.deep.equal([buf1.buffer, buf2.buffer]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user