0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-03-25 02:32:52 -05:00

refactor: use of constants for testing

This commit is contained in:
Juan Picado @jotadeveloper 2018-06-23 08:35:06 +02:00
parent 690b92a652
commit 686f22461f
No known key found for this signature in database
GPG key ID: 18AC54485952D158
13 changed files with 58 additions and 56 deletions

View file

@ -39,10 +39,6 @@ export const HTTP_STATUS = {
LOOP_DETECTED: 508,
};
export const PORT_SERVER_1 = '55551';
export const PORT_SERVER_2 = '55552';
export const PORT_SERVER_3 = '55553';
export const API_ERROR = {
NO_PACKAGE: 'no such package available',
NOT_ALLOWED: 'not allowed to access package',

View file

@ -4,7 +4,7 @@ import fs from 'fs';
import path from 'path';
import {createTarballHash} from "../../../src/lib/crypto-utils";
import {HTTP_STATUS} from "../../../src/lib/constants";
import {CREDENTIALS} from "../config.func";
import {CREDENTIALS, PORT_SERVER_1, PORT_SERVER_2, TARBALL} from "../config.func";
import whoIam from './whoIam';
import ping from './ping';
@ -44,7 +44,7 @@ export default function(server: any, server2: any) {
});
test('downloading non-existent tarball', () => {
return server.getTarball(PKG_NAME, 'blahblah')
return server.getTarball(PKG_NAME, TARBALL)
.status(HTTP_STATUS.NOT_FOUND)
.body_error(/no such file/);
});
@ -56,7 +56,7 @@ export default function(server: any, server2: any) {
describe('publishing package', () => {
beforeAll(function () {
return server.putTarball(PKG_NAME, 'blahblah', readfile('../fixtures/binary'))
return server.putTarball(PKG_NAME, TARBALL, readfile('../fixtures/binary'))
.status(HTTP_STATUS.CREATED)
.body_ok(/.*/);
});
@ -96,7 +96,7 @@ export default function(server: any, server2: any) {
// testexp-incomplete
test('downloading newly created tarball', () => {
return server.getTarball(PKG_NAME, 'blahblah')
return server.getTarball(PKG_NAME, TARBALL)
.status(200)
.then(function (body) {
expect(body).toEqual(readfile('../fixtures/binary'));
@ -140,7 +140,7 @@ export default function(server: any, server2: any) {
.then(function (body) {
expect(body.name).toEqual(PKG_NAME);
expect(body.versions['0.0.1'].name).toEqual(PKG_NAME);
expect(body.versions['0.0.1'].dist.tarball).toEqual('http://localhost:55551/testpkg/-/blahblah');
expect(body.versions['0.0.1'].dist.tarball).toEqual(`http://localhost:${PORT_SERVER_1}/testpkg/-/${TARBALL}`);
expect(body['dist-tags']).toEqual({
latest: '0.0.1'
});
@ -153,7 +153,7 @@ export default function(server: any, server2: any) {
.then(function (body) {
expect(body.name).toEqual(PKG_NAME);
expect(body.versions['0.0.1'].name).toEqual(PKG_NAME);
expect(body.versions['0.0.1'].dist.tarball).toEqual('http://localhost:55552/testpkg/-/blahblah');
expect(body.versions['0.0.1'].dist.tarball).toEqual(`http://localhost:${PORT_SERVER_2}/testpkg/-/${TARBALL}`);
expect(body['dist-tags']).toEqual({
latest: '0.0.1'
});
@ -183,7 +183,7 @@ export default function(server: any, server2: any) {
);
test('should be a package not found', () => {
return server.putTarball('nonExistingPackage', 'blahblah', readfile('../fixtures/binary'))
return server.putTarball('nonExistingPackage', TARBALL, readfile('../fixtures/binary'))
.status(HTTP_STATUS.NOT_FOUND)
.body_error(/no such/);
});

View file

@ -2,3 +2,8 @@ export const CREDENTIALS = {
user: 'test',
password: 'test'
};
export const TARBALL = 'tarball-blahblah-file.name';
export const PORT_SERVER_1 = '55551';
export const PORT_SERVER_2 = '55552';
export const PORT_SERVER_3 = '55553';

View file

@ -1,9 +1,7 @@
import {PORT_SERVER_1} from "../../../src/lib/constants";
export const FILE_NAME = 'blahblah';
import {PORT_SERVER_1, TARBALL} from '../config.func';
module.exports = function(name, version = '0.0.0', port = PORT_SERVER_1, domain= `http://localhost:${port}`,
fileName = 'blahblah', readme = 'this is a readme') {
fileName = TARBALL, readme = 'this is a readme') {
return {
name,
version,

View file

@ -8,7 +8,7 @@ import VerdaccioProcess from "../../lib/server_process";
import Server from "../../lib/server";
import ExpressServer from "./simple_server";
import type {IServerBridge} from '../../types';
import {PORT_SERVER_1, PORT_SERVER_2, PORT_SERVER_3} from "../../../src/lib/constants";
import {PORT_SERVER_1, PORT_SERVER_2, PORT_SERVER_3} from '../config.func';
const EXPRESS_PORT = 55550;

View file

@ -1,4 +1,5 @@
import {HEADERS, HTTP_STATUS, PORT_SERVER_1, PORT_SERVER_2} from '../../../src/lib/constants';
import {HEADERS, HTTP_STATUS} from '../../../src/lib/constants';
import {PORT_SERVER_1, PORT_SERVER_2} from '../config.func';
import {generateSha} from '../lib/test.utils';
import {DIST_TAGS} from "../../../src/lib/utils";

View file

@ -4,7 +4,7 @@ export default function(server2) {
// credentials
const USER1 = 'authtest';
const USER2 = 'authtest2';
const CORRECT_PASSWORD = 'blahblah';
const CORRECT_PASSWORD = 'blahblah-password';
const WRONG_PASSWORD = 'wrongpass1';
// package names
const DENY_PKG_NAME = 'test-auth-deny';

View file

@ -1,6 +1,7 @@
import {readFile} from '../lib/test.utils';
import {HTTP_STATUS} from "../../../src/lib/constants";
import generatePkg from '../fixtures/package';
import {TARBALL} from '../config.func';
const getBinary = () => readFile('../fixtures/binary');
@ -14,7 +15,6 @@ export default function (server, server2) {
});
describe('mirror', () => {
const pkgFileName = 'blahblah';
const pkgList = ['pkg1', 'pkg2', 'pkg3'];
pkgList.forEach(function (pkg) {
@ -45,7 +45,7 @@ export default function (server, server2) {
describe('should put a tarball', () => {
beforeAll(function () {
return server2.putTarball(pkg, pkgFileName, getBinary())
return server2.putTarball(pkg, TARBALL, getBinary())
.status(HTTP_STATUS.CREATED)
.body_ok(/.*/);
});
@ -53,7 +53,7 @@ export default function (server, server2) {
test(`should ${prefix} uploading new tarball`, () => {});
test(`should ${prefix} downloading tarball from server2`, () => {
return server2.getTarball(pkg, pkgFileName)
return server2.getTarball(pkg, TARBALL)
.status(HTTP_STATUS.OK)
.then(function (body) {
expect(body).toEqual(getBinary());
@ -65,7 +65,7 @@ export default function (server, server2) {
});
test(`should ${prefix} downloading tarball from server1`, () => {
return server.getTarball(pkg, pkgFileName)
return server.getTarball(pkg, TARBALL)
.status(HTTP_STATUS.OK)
.then(function (body) {
expect(body).toEqual(getBinary());

View file

@ -1,6 +1,7 @@
import assert from 'assert';
import crypto from 'crypto';
import {readFile} from '../lib/test.utils';
import {createTarballHash} from "../../../src/lib/crypto-utils";
import {HTTP_STATUS} from "../../../src/lib/constants";
import {PORT_SERVER_1, TARBALL} from '../config.func';
function getBinary() {
return readFile('../fixtures/binary');
@ -8,60 +9,60 @@ function getBinary() {
export default function (server, server2) {
const PKG_NAME = 'test-nullstorage2';
const PKG_VERSION = '0.0.1';
describe('should check whether test-nullstorage is on server1', () => {
test('trying to fetch non-existent package / null storage', () => {
return server.getPackage('test-nullstorage-nonexist')
.status(404)
return server.getPackage('test-nullstorage-nonexist').status(HTTP_STATUS.NOT_FOUND)
.body_error(/no such package/);
});
});
describe('should check whether test-nullstorage is on server2', () => {
beforeAll(function() {
return server2.addPackage('test-nullstorage2');
return server2.addPackage(PKG_NAME);
});
test('should creaate a new package on server2', () => {/* test for before() */});
test('should fails on download a non existent tarball', () => {
return server.getTarball('test-nullstorage2', 'blahblah')
.status(404)
return server.getTarball(PKG_NAME, TARBALL)
.status(HTTP_STATUS.NOT_FOUND)
.body_error(/no such file/);
});
describe('test and publish test-nullstorage2 package', () => {
beforeAll(function() {
return server2.putTarball('test-nullstorage2', 'blahblah', getBinary())
.status(201)
.body_ok(/.*/);
return server2.putTarball(PKG_NAME, TARBALL, getBinary())
.status(HTTP_STATUS.CREATED).body_ok(/.*/);
});
beforeAll(function() {
let pkg = require('../fixtures/package')('test-nullstorage2');
pkg.dist.shasum = crypto.createHash('sha1').update(getBinary()).digest('hex');
return server2.putVersion('test-nullstorage2', '0.0.1', pkg)
.status(201)
.body_ok(/published/);
let pkg = require('../fixtures/package')(PKG_NAME);
pkg.dist.shasum = createTarballHash().update(getBinary()).digest('hex');
return server2.putVersion(PKG_NAME, PKG_VERSION, pkg)
.status(HTTP_STATUS.CREATED).body_ok(/published/);
});
test('should upload a new version for test-nullstorage2', () => {/* test for before() */});
test('should fetch the newly created published tarball for test-nullstorage2', () => {
return server.getTarball('test-nullstorage2', 'blahblah')
.status(200)
return server.getTarball(PKG_NAME, TARBALL)
.status(HTTP_STATUS.OK)
.then(function(body) {
assert.deepEqual(body, getBinary());
expect(body).toEqual(getBinary());
});
});
test('should check whether the metadata for test-nullstorage2 match', () => {
return server.getPackage('test-nullstorage2')
.status(200)
return server.getPackage(PKG_NAME)
.status(HTTP_STATUS.OK)
.then(function(body) {
assert.equal(body.name, 'test-nullstorage2');
assert.equal(body.versions['0.0.1'].name, 'test-nullstorage2');
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55551/test-nullstorage2/-/blahblah');
assert.deepEqual(body['dist-tags'], {latest: '0.0.1'});
expect(body.name).toBe(PKG_NAME);
expect(body.versions[PKG_VERSION].name).toBe(PKG_NAME);
expect(body.versions[PKG_VERSION].dist.tarball).toBe(`http://localhost:${PORT_SERVER_1}/${PKG_NAME}/-/${TARBALL}`);
expect(body['dist-tags']).toEqual({latest: PKG_VERSION});
});
});
});

View file

@ -2,6 +2,7 @@ import {createTarballHash} from "../../../src/lib/crypto-utils";
import {HTTP_STATUS} from "../../../src/lib/constants";
import fs from 'fs';
import path from 'path';
import {TARBALL} from '../config.func';
function readfile(filePath) {
const folder = path.join(__dirname , filePath);
@ -11,12 +12,11 @@ function readfile(filePath) {
const binary = '../fixtures/binary';
const pkgName = 'testpkg-gh29';
const pkgFileName = 'blahblah';
export default function (server, server2) {
describe('pkg-gh29 #1', () => {
test('downloading non-existent tarball #1 / srv2', () => {
return server2.getTarball(pkgName, pkgFileName)
return server2.getTarball(pkgName, TARBALL)
.status(HTTP_STATUS.NOT_FOUND)
.body_error(/no such package/);
});
@ -32,14 +32,14 @@ export default function (server, server2) {
test('creating new package / srv1', () => {});
test('downloading non-existent tarball #2 / srv2', () => {
return server2.getTarball(pkgName, pkgFileName)
return server2.getTarball(pkgName, TARBALL)
.status(HTTP_STATUS.NOT_FOUND)
.body_error(/no such file available/);
});
describe('tarball', () => {
beforeAll(function() {
return server.putTarball(pkgName, pkgFileName, readfile(binary))
return server.putTarball(pkgName, TARBALL, readfile(binary))
.status(HTTP_STATUS.CREATED)
.body_ok(/.*/);
});
@ -58,7 +58,7 @@ export default function (server, server2) {
test('uploading new package version / srv1', () => {});
test('downloading newly created tarball / srv2', () => {
return server2.getTarball(pkgName, pkgFileName)
return server2.getTarball(pkgName, TARBALL)
.status(HTTP_STATUS.OK)
.then(function(body) {
expect(body).toEqual(readfile(binary));

View file

@ -25,10 +25,10 @@ auth:
password: test
authtest2:
name: authtest2
password: blahblah
password: blahblah-password
authtest:
name: authtest
password: blahblah
password: blahblah-password
logs:
- {type: stdout, format: pretty, level: trace}

View file

@ -1,6 +1,7 @@
import assert from 'assert';
import {generateSha} from '../lib/test.utils';
import {HEADERS} from '../../../src/lib/constants';
import {PORT_SERVER_1, PORT_SERVER_2} from '../config.func';
export default function(server, server2, express) {
describe('should test preserve tags when publishing something', () => {
@ -51,11 +52,11 @@ export default function(server, server2, express) {
};
test('server1 should be able to match latest dist-tags correctly', () => {
return matchDisTags(server, '55551');
return matchDisTags(server, PORT_SERVER_1);
});
test('server2 should be able to match latest dist-tags correctly', () => {
return matchDisTags(server2, '55552');
return matchDisTags(server2, PORT_SERVER_2);
});
});

View file

@ -4,13 +4,13 @@ import assert from 'assert';
import crypto from 'crypto';
import {readFile} from '../lib/test.utils';
import {HTTP_STATUS} from "../../../src/lib/constants";
import {TARBALL} from '../config.func';
function getBinary() {
return readFile('../fixtures/binary');
}
const STORAGE = '../store/test-storage3';
const TARBALL = 'blahblah';
const PKG_GH131 = 'pkg-gh131';
const PKG_GH1312 = 'pkg-gh1312';