2017-07-02 00:05:58 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const assert = require('assert');
|
|
|
|
const crypto = require('crypto');
|
|
|
|
|
2017-08-06 21:54:15 +02:00
|
|
|
const util = require('./lib/test.utils');
|
|
|
|
|
|
|
|
function getBinary() {
|
|
|
|
return util.readFile('../fixtures/binary');
|
|
|
|
}
|
|
|
|
|
2017-07-02 00:05:58 +02:00
|
|
|
const STORAGE = 'store/test-storage3';
|
|
|
|
const TARBALL = 'blahblah';
|
|
|
|
const PKG_GH131 = 'pkg-gh131';
|
|
|
|
const PKG_GH1312 = 'pkg-gh1312';
|
|
|
|
|
|
|
|
function isCached(pkgName, tarballName) {
|
|
|
|
return fs.existsSync(path.join(__dirname, STORAGE, pkgName, tarballName));
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function() {
|
|
|
|
const server = process.server;
|
|
|
|
const server2 = process.server2;
|
|
|
|
const server3 = process.server3;
|
|
|
|
|
|
|
|
describe('storage tarball cache test', function() {
|
|
|
|
|
|
|
|
//more info #131
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
return server.addPackage(PKG_GH131);
|
|
|
|
});
|
|
|
|
|
|
|
|
before(function () {
|
2017-08-06 21:54:15 +02:00
|
|
|
return server.putTarball(PKG_GH131, TARBALL, getBinary())
|
2017-07-02 00:05:58 +02:00
|
|
|
.status(201)
|
|
|
|
.body_ok(/.*/);
|
|
|
|
});
|
|
|
|
|
|
|
|
before(function () {
|
2017-08-06 21:54:15 +02:00
|
|
|
const pkg = require('./fixtures/package')(PKG_GH131);
|
|
|
|
pkg.dist.shasum = crypto.createHash('sha1').update(getBinary()).digest('hex');
|
2017-07-02 00:05:58 +02:00
|
|
|
|
|
|
|
return server.putVersion(PKG_GH131, '0.0.1', pkg)
|
|
|
|
.status(201)
|
|
|
|
.body_ok(/published/);
|
|
|
|
});
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
return server3.getPackage(PKG_GH131)
|
|
|
|
.status(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
return server3.getTarball(PKG_GH131, TARBALL)
|
|
|
|
.status(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be caching packages from uplink server1', function () {
|
|
|
|
assert.equal(isCached(PKG_GH131, TARBALL), true);
|
|
|
|
});
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
return server2.addPackage(PKG_GH1312);
|
|
|
|
});
|
|
|
|
|
|
|
|
before(function () {
|
2017-08-06 21:54:15 +02:00
|
|
|
return server2.putTarball(PKG_GH1312, TARBALL, getBinary())
|
2017-07-02 00:05:58 +02:00
|
|
|
.status(201)
|
|
|
|
.body_ok(/.*/);
|
|
|
|
});
|
|
|
|
|
|
|
|
before(function () {
|
2017-08-06 21:54:15 +02:00
|
|
|
const pkg = require('./fixtures/package')(PKG_GH1312);
|
|
|
|
pkg.dist.shasum = crypto.createHash('sha1').update(getBinary()).digest('hex');
|
2017-07-02 00:05:58 +02:00
|
|
|
|
|
|
|
return server2.putVersion(PKG_GH1312, '0.0.1', pkg)
|
|
|
|
.status(201)
|
|
|
|
.body_ok(/published/);
|
|
|
|
});
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
return server3.getPackage(PKG_GH1312)
|
|
|
|
.status(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
return server3.getTarball(PKG_GH1312, TARBALL)
|
|
|
|
.status(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('must not be caching packages from uplink server2', function () {
|
|
|
|
assert.equal(isCached(PKG_GH1312, TARBALL), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|