Skip to content

Commit

Permalink
fix: don’t packages that have no uplinks after reading (#1204)
Browse files Browse the repository at this point in the history
  • Loading branch information
buffaybu committed Jan 29, 2019
1 parent 23b02c0 commit 95686be
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/lib/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,9 @@ class Storage implements IStorageHandler {
, null
, upLinksErrors );
}

if (upLinks.length === 0) {
return callback(null, packageInfo);
}
self.localStorage.updateVersions(name, packageInfo, function(err, packageJsonLocal: Package) {
if (err) {
return callback(err);
Expand Down
28 changes: 24 additions & 4 deletions test/unit/api/store.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import _ from 'lodash';
import path from 'path';
import fs from 'fs';
import rimraf from 'rimraf';
// $FlowFixMe
import configExample from '../partials/config/index';
import AppConfig from '../../../src/lib/config';
Expand All @@ -16,12 +18,12 @@ import {DOMAIN_SERVERS} from '../../functional/config.functional';

setup(configExample.logs);

const storagePath = path.join(__dirname, '../partials/store/test-storage-store.spec');
const mockServerPort: number = 55548;
const generateStorage = async function(port = mockServerPort, configDefault = configExample) {
const storageConfig = _.clone(configDefault);
const storage = path.join(__dirname, '../partials/store/test-storage-store.spec');
storageConfig.self_path = __dirname;
storageConfig.storage = storage;
storageConfig.storage = storagePath;
storageConfig.uplinks = {
npmjs: {
url: `http://${DOMAIN_SERVERS}:${port}`
Expand All @@ -37,8 +39,11 @@ const generateStorage = async function(port = mockServerPort, configDefault = co
describe('StorageTest', () => {
let mockRegistry;

beforeAll(async () => {
mockRegistry = await mockServer(mockServerPort).init();
beforeAll(done => {
rimraf(storagePath, async () => {
mockRegistry = await mockServer(mockServerPort).init();
done()
})
});

afterAll(function(done) {
Expand Down Expand Up @@ -90,5 +95,20 @@ describe('StorageTest', () => {
done();
});
});

test('should not touch if the package exists and has no uplinks', async (done) => {
const storage: IStorageHandler = await generateStorage();
const metadataPath = path.join(storagePath, 'npm_test/package.json')
fs.mkdirSync(path.join(storagePath, 'npm_test'))
fs.copyFileSync(path.join(__dirname, '../partials/metadata'), metadataPath)
const metadata = JSON.parse(fs.readFileSync(metadataPath).toString())
const prevStat = fs.statSync(metadataPath)
storage._syncUplinksMetadata('npm_test', metadata, {}, (err) => {
expect(err).toBeFalsy()
const nextStat = fs.statSync(metadataPath)
expect(nextStat).toEqual(prevStat)
done()
})
})
});
});

0 comments on commit 95686be

Please sign in to comment.