2017-12-02 11:19:08 +01:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
import assert from 'assert';
|
|
|
|
import crypto from 'crypto';
|
|
|
|
import {readFile} from './lib/test.utils';
|
2017-08-06 21:54:15 +02:00
|
|
|
|
|
|
|
function getBinary() {
|
2017-12-02 11:19:08 +01:00
|
|
|
return readFile('../fixtures/binary');
|
2017-08-06 21:54:15 +02:00
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
export default function (server, server2, server3) {
|
2017-07-02 00:05:58 +02:00
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
describe('storage tarball cache test', () => {
|
2017-07-02 00:05:58 +02:00
|
|
|
|
|
|
|
//more info #131
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2017-07-02 00:05:58 +02:00
|
|
|
return server.addPackage(PKG_GH131);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(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(/.*/);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(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/);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2018-06-05 21:03:27 +02:00
|
|
|
return server3.getPackage(PKG_GH131).status(200);
|
2017-07-02 00:05:58 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2017-07-02 00:05:58 +02:00
|
|
|
return server3.getTarball(PKG_GH131, TARBALL)
|
|
|
|
.status(200);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('should be caching packages from uplink server1', () => {
|
2017-07-02 00:05:58 +02:00
|
|
|
assert.equal(isCached(PKG_GH131, TARBALL), true);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2017-07-02 00:05:58 +02:00
|
|
|
return server2.addPackage(PKG_GH1312);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(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(/.*/);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(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/);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2017-07-02 00:05:58 +02:00
|
|
|
return server3.getPackage(PKG_GH1312)
|
|
|
|
.status(200);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2017-07-02 00:05:58 +02:00
|
|
|
return server3.getTarball(PKG_GH1312, TARBALL)
|
|
|
|
.status(200);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('must not be caching packages from uplink server2', () => {
|
2017-07-02 00:05:58 +02:00
|
|
|
assert.equal(isCached(PKG_GH1312, TARBALL), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2017-12-02 11:19:08 +01:00
|
|
|
}
|