0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-04-01 02:42:23 -05:00

refactor: dist-tags-merge test

This commit is contained in:
Juan Picado @jotadeveloper 2018-06-23 16:34:22 +02:00
parent 2c74133dfc
commit 90e700ce78
No known key found for this signature in database
GPG key ID: 18AC54485952D158
9 changed files with 213 additions and 119 deletions

View file

@ -4,7 +4,7 @@ import _ from 'lodash';
import Path from 'path';
import mime from 'mime';
import {HEADERS} from '../../../lib/constants';
import {API_MESSAGE, HEADERS} from '../../../lib/constants';
import {DIST_TAGS, validate_metadata, isObject, ErrorCode} from '../../../lib/utils';
import {media, expectJson, allow} from '../../middleware';
import {notify} from '../../../lib/notify';
@ -119,11 +119,11 @@ export default function(router: Router, auth: IAuth, storage: IStorageHandler, c
if (req.params._rev) {
storage.changePackage(name, metadata, req.params.revision, function(err) {
after_change(err, 'package changed');
after_change(err, API_MESSAGE.PKG_CHANGED);
});
} else {
storage.addPackage(name, metadata, function(err) {
after_change(err, 'created new package');
after_change(err, API_MESSAGE.PKG_CREATED);
});
}
});
@ -135,7 +135,7 @@ export default function(router: Router, auth: IAuth, storage: IStorageHandler, c
return next(err);
}
res.status(201);
return next({ok: 'package removed'});
return next({ok: API_MESSAGE.PKG_REMOVED});
});
});
@ -147,7 +147,7 @@ export default function(router: Router, auth: IAuth, storage: IStorageHandler, c
return next(err);
}
res.status(201);
return next({ok: 'tarball removed'});
return next({ok: API_MESSAGE.TARBALL_REMOVED});
});
});
@ -196,7 +196,7 @@ export default function(router: Router, auth: IAuth, storage: IStorageHandler, c
res.status(201);
return next({
ok: 'package published',
ok: API_MESSAGE.PKG_PUBLISHED,
});
});
});

View file

@ -39,6 +39,14 @@ export const HTTP_STATUS = {
LOOP_DETECTED: 508,
};
export const API_MESSAGE = {
PKG_CREATED: 'created new package',
PKG_CHANGED: 'package changed',
PKG_REMOVED: 'package removed',
PKG_PUBLISHED: 'package published',
TARBALL_REMOVED: 'tarball removed',
};
export const API_ERROR = {
NO_PACKAGE: 'no such package available',
NOT_ALLOWED: 'not allowed to access package',

View file

@ -11,7 +11,7 @@ import packageAccess from './package/access';
import packageGzip from './package/gzip';
import packageScoped from './package/scoped';
import tags from './tags/tags';
import preserveTags from './tags/preserve_tags';
import distTagsMerge from './tags/dist-tags-merge';
import addtag from './tags/addtag';
import adduser from './adduser/adduser';
import logout from './adduser/logout';
@ -21,6 +21,7 @@ import mirror from './sanity/mirror';
import readme from './readme/readme';
import gh29 from './scenarios/gh29';
import nullstorage from './sanity/nullstorage';
import simpleSearch from './search/simple.search';
import racycrash from './sanity/racycrash';
import security from './sanity/security';
import race from './performance/race';
@ -43,7 +44,7 @@ describe('functional test verdaccio', function() {
packageGzip(server1, app);
incomplete(server1, app);
mirror(server1, server2);
preserveTags(server1, server2, app);
distTagsMerge(server1, server2, server3);
readme(server1, server2);
nullstorage(server1, server2);
middleware(server2);
@ -59,6 +60,7 @@ describe('functional test verdaccio', function() {
adduser(server1);
logout(server1);
basic(server1, server2);
simpleSearch(server1, server2, app)
});

View file

@ -0,0 +1,57 @@
{
"_id": "testpkg-search",
"name": "testpkg-search",
"description": "",
"dist-tags": {
"foo": "0.0.1",
"latest": "0.0.1"
},
"versions": {
"0.0.1": {
"name": "testpkg-search",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": ""
},
"author": "",
"license": "ISC",
"_id": "testpkg-search@0.0.1",
"dist": {
"shasum": "8ee7331cbc641581b1a8cecd9d38d744a8feb863",
"tarball": "http:\/\/localhost:1234\/testpkg-search\/-\/testpkg-search-0.0.1.tgz"
},
"_from": ".",
"_npmVersion": "1.3.1",
"_npmUser": {
"name": "alex",
"email": "user@domain.com"
},
"maintainers": [
{
"name": "alex",
"email": "user@domain.com"
}
]
}
},
"readme": "blah blah blah",
"maintainers": [
{
"name": "alex",
"email": "user@domain.com"
}
],
"_attachments": {
"testpkg-search-0.0.1.tgz": {
"content_type": "application\/octet-stream",
"data": "H4sIAAAAAAAAA+2TsW7CMBCGM\/spTh6YKHUSIJLXqkPnrixWcIMLsS3btCDEu\/fs0Ba1SFVVVISUP8Odzqf\/zlY+K+qlaOSt7eLo2RudnVmMsel4DBjzasKOY1JZlJDlRVkU5aSspnnG8pIVOZ6fe5FTWvsgHK7yV5\/uLvARr0Q7qkUrKadB+mCXzY2Wr9q2TjZ0SF+k88poPGUj\/LAyl752yoauioVWqJgpPZcb\/Hmw0jV4ynfJEw9lvTAwo\/fOGcdBG4h18FbW6knJ+YzCYAByowLkdD+kTlrjVTBumzy2Nq7XqIDea7eKY7FJrMPCuG6Hlaql9rHr4fGO7i\/9pFcl+4X\/rWhX557xA\/9FVZ3gv+j5\/w9F+jl8g58c0OeQyCdH3HOglETsObxTTw7McwLJClt+wzz5JD45IPEcEHjMEfg0r8M9pQfaOSDs5NLP16tXr15XqzeJD6m5AAwAAA==",
"length": 352
}
}
}

View file

@ -0,0 +1,64 @@
import {API_MESSAGE, HTTP_STATUS} from '../../../src/lib/constants';
const pkgExample = require('./search.json');
export default function(server, server2, express) {
describe('should test search a published package', () => {
const PKG_NAME = 'testpkg-search';
beforeAll(function() {
return server.putPackage(PKG_NAME, pkgExample)
.status(HTTP_STATUS.CREATED)
.body_ok(API_MESSAGE.PKG_CREATED);
});
describe('should test simple search', () => {
const check = (medatada) => {
medatada[PKG_NAME].time.modified = '2014-10-02T07:07:51.000Z';
expect(medatada[PKG_NAME]).toEqual(
{
'name': PKG_NAME,
'description': '',
'author': '',
'license': 'ISC',
'dist-tags': {
latest: '0.0.1'
},
'maintainers': [{
name: 'alex',
email: 'user@domain.com'
}],
'readmeFilename': '',
'time': {
modified: '2014-10-02T07:07:51.000Z'
},
'versions': {
"0.0.1": "latest"
},
'repository': {
type: 'git', url: ''}
});
};
beforeAll(function() {
express.get('/-/all', (req, res) => {
res.send({});
});
});
test('server1 - search', () => {
return server.request({uri: '/-/all'})
.status(HTTP_STATUS.OK)
.then(check);
});
test('server2 - search', () => {
return server2.request({uri: '/-/all'})
.status(HTTP_STATUS.OK)
.then(check);
});
});
});
}

View file

@ -26,6 +26,11 @@ packages:
access: $all
proxy: server1
'testpkg-preserve':
access: test $anonymous
publish: test $anonymous
proxy: server1
'pkg-gh1312':
access: $all
proxy: server2

View file

@ -0,0 +1,69 @@
import {generateSha} from '../lib/test.utils';
import {API_MESSAGE, HTTP_STATUS} from '../../../src/lib/constants';
import {DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2, PORT_SERVER_3} from '../config.func';
import {DIST_TAGS} from '../../../src/lib/utils';
const pkgExample = require('./dist-tags-merge.json');
export default function(server, server2, server3) {
describe('should test preserve tags when publishing something', () => {
const PKG_NAME = 'testpkg-preserve';
const PKG_VERSION = '0.0.1';
beforeAll(function() {
return server.putPackage(PKG_NAME, pkgExample)
.status(HTTP_STATUS.CREATED)
.body_ok(API_MESSAGE.PKG_CREATED);
});
describe('should check sha integrity', () => {
const matchTarBallSha = (server) => {
return server.getTarball(PKG_NAME, `${PKG_NAME}-${PKG_VERSION}.tgz`)
.status(HTTP_STATUS.OK)
.then(function(body) {
// not real sha due to utf8 conversion
expect(generateSha(body)).toBe(pkgExample.versions[PKG_VERSION].dist.shasum);
});
};
test('server1 should match with sha key from published package', () => {
return matchTarBallSha(server);
});
test('server2 should match with sha key from published package', () => {
return matchTarBallSha(server2);
});
});
describe('should match dist-tags', () => {
const matchDisTags = (verdaccioServer, port) => {
return verdaccioServer.getPackage(PKG_NAME)
.status(HTTP_STATUS.OK)
.then(function(body) {
expect(body.name).toBe(PKG_NAME);
expect(body.time).toBeDefined();
expect(body.time[PKG_VERSION]).toBeDefined();
expect(body.time).toBeDefined();
expect(body.versions[PKG_VERSION].name).toBe(PKG_NAME);
expect(body.versions[PKG_VERSION].dist.tarball).toBe(`http://${DOMAIN_SERVERS}:${port}/${PKG_NAME}/-/${PKG_NAME}-${PKG_VERSION}.tgz`);
expect(body[DIST_TAGS]).toEqual({foo: PKG_VERSION, latest: PKG_VERSION});
});
};
test('server1 should be able to match latest dist-tags correctly', () => {
return matchDisTags(server, PORT_SERVER_1);
});
test('server2 should be able to match latest dist-tags correctly', () => {
return matchDisTags(server2, PORT_SERVER_2);
});
test('server3 should be able to match latest dist-tags correctly', () => {
return matchDisTags(server3, PORT_SERVER_3);
});
});
});
}

View file

@ -1,111 +0,0 @@
import assert from 'assert';
import {generateSha} from '../lib/test.utils';
import {HEADERS, HTTP_STATUS} from '../../../src/lib/constants';
import {DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2} from '../config.func';
export default function(server, server2, express) {
describe('should test preserve tags when publishing something', () => {
beforeAll(function() {
return server.request({
uri: '/testpkg-preserve',
headers: {
'content-type': HEADERS.JSON,
},
method: 'PUT',
json: require('./preserve_tags.json'),
}).status(201);
});
test('add new package', () => {});
describe('should check sha integrity', () => {
const matchTarBallSha = (server) => {
return server.getTarball('testpkg-preserve', 'testpkg-preserve-0.0.1.tgz')
.status(200)
.then(function(body) {
// not real sha due to utf8 conversion
assert.strictEqual(generateSha(body), '8ee7331cbc641581b1a8cecd9d38d744a8feb863');
});
};
test('server1 should match with sha key from published package', () => {
return matchTarBallSha(server);
});
test('server2 should match with sha key from published packagel', () => {
matchTarBallSha(server2);
});
});
describe('should match dist-tags', () => {
const matchDisTags = (server, port) => {
return server.getPackage('testpkg-preserve')
.status(HTTP_STATUS.OK)
.then(function(body) {
assert.equal(body.name, 'testpkg-preserve');
assert.equal(body.versions['0.0.1'].name, 'testpkg-preserve');
assert.equal(body.versions['0.0.1'].dist.tarball, `http://${DOMAIN_SERVERS}:${port}/testpkg-preserve/-/testpkg-preserve-0.0.1.tgz`);
assert.deepEqual(body['dist-tags'], {foo: '0.0.1', latest: '0.0.1'});
});
};
test('server1 should be able to match latest dist-tags correctly', () => {
return matchDisTags(server, PORT_SERVER_1);
});
test('server2 should be able to match latest dist-tags correctly', () => {
return matchDisTags(server2, PORT_SERVER_2);
});
});
describe('should test search', () => {
const check = (obj) => {
obj['testpkg-preserve'].time.modified = '2014-10-02T07:07:51.000Z';
assert.deepEqual(obj['testpkg-preserve'],
{
'name': 'testpkg-preserve',
'description': '',
'author': '',
'license': 'ISC',
'dist-tags': {
latest: '0.0.1'
},
'maintainers': [{
name: 'alex',
email: 'user@domain.com'
}],
'readmeFilename': '',
'time': {
modified: '2014-10-02T07:07:51.000Z'
},
'versions': {
"0.0.1": "latest"
},
'repository': {
type: 'git', url: ''}
});
};
beforeAll(function() {
express.get('/-/all', (req, res) => {
res.send({});
});
});
test('server1 - search', () => {
return server.request({uri: '/-/all'})
.status(HTTP_STATUS.OK)
.then(check);
});
test('server2 - search', () => {
return server2.request({uri: '/-/all'})
.status(HTTP_STATUS.OK)
.then(check);
});
});
});
}