Skip to content

Commit

Permalink
Merge pull request #117 from thiagobustamante/master
Browse files Browse the repository at this point in the history
Improve tests
  • Loading branch information
thiagobustamante committed Mar 9, 2018
2 parents 3e78e78 + 9868a12 commit 5e64c16
Show file tree
Hide file tree
Showing 27 changed files with 603 additions and 351 deletions.
147 changes: 94 additions & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.2",
"bson": "^2.0.0",
"chai": "^4.1.2",
"chalk": "^2.3.2",
"cluster": "^0.7.7",
"compare-versions": "^3.1.0",
Expand Down Expand Up @@ -108,7 +109,8 @@
"@types/bcryptjs": "^2.4.1",
"@types/body-parser": "^1.16.7",
"@types/bson": "^1.0.7",
"@types/chai": "^3.5.1",
"@types/chai": "^4.1.2",
"@types/chai-as-promised": "^7.1.0",
"@types/chalk": "^2.2.0",
"@types/compression": "0.0.33",
"@types/consul": "^0.23.32",
Expand Down Expand Up @@ -139,7 +141,7 @@
"@types/winston": "0.0.28",
"@types/xml2js": "^0.4.0",
"@types/yamljs": "^0.2.30",
"chai": "^3.5.0",
"chai-as-promised": "^7.1.1",
"copyfiles": "^1.2.0",
"coveralls": "^2.13.3",
"cross-env": "^4.0.0",
Expand Down
14 changes: 3 additions & 11 deletions src/admin/api/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,19 +472,11 @@ export class MiddlewareRest {
}

private async addMiddleware(type: string, file: Express.Multer.File, name: string, basePath?: string): Promise<Return.NewResource<void>> {
try {
await this.service.add(type, name, file.buffer);
return new Return.NewResource<void>(path.join(basePath || type, name));
} catch(err) {
throw new Errors.InternalServerError(`Error saving ${type}.`);
}
await this.service.add(type, name, file.buffer);
return new Return.NewResource<void>(path.join(basePath || type, name));
}

private async saveMiddleware(type: string, file: Express.Multer.File, name: string): Promise<void> {
try {
return await this.service.save('servicediscovery', name, file.buffer);
} catch(err) {
throw new Errors.InternalServerError(`Error saving ${type}.`);
}
return await this.service.update(type, name, file.buffer);
}
}
16 changes: 8 additions & 8 deletions src/admin/config/cli-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ export class Cli {
await this.sdk.middleware.addCircuitBreaker(name, fileName);
console.info(`Middleware added`);
} else if (this.args.get) {
const file = await this.sdk.middleware.getCircuitBreakerMiddleware(this.args.get);
const file = await this.sdk.middleware.getCircuitBreaker(this.args.get);
console.info(file.toString());
} else {
throw new Error('Invalid arguments. Type -h for more info.');
Expand Down Expand Up @@ -491,7 +491,7 @@ export class Cli {
await this.sdk.middleware.addCors(name, fileName);
console.info(`Middleware added`);
} else if (this.args.get) {
const file = await this.sdk.middleware.getCorsMiddleware(this.args.get);
const file = await this.sdk.middleware.getCors(this.args.get);
console.info(file.toString());
} else {
throw new Error('Invalid arguments. Type -h for more info.');
Expand Down Expand Up @@ -523,7 +523,7 @@ export class Cli {
await this.sdk.middleware.addProxyRouter(name, fileName);
console.info(`Middleware added`);
} else if (this.args.get) {
const file = await this.sdk.middleware.getProxyRouterMiddleware(this.args.get);
const file = await this.sdk.middleware.getProxyRouter(this.args.get);
console.info(file.toString());
} else {
throw new Error('Invalid arguments. Type -h for more info.');
Expand Down Expand Up @@ -555,7 +555,7 @@ export class Cli {
await this.sdk.middleware.addServiceDiscovery(name, fileName);
console.info(`Middleware added`);
} else if (this.args.get) {
const file = await this.sdk.middleware.getServiceDiscoveryMiddleware(this.args.get);
const file = await this.sdk.middleware.getServiceDiscovery(this.args.get);
console.info(file.toString());
} else {
throw new Error('Invalid arguments. Type -h for more info.');
Expand Down Expand Up @@ -587,7 +587,7 @@ export class Cli {
await this.sdk.middleware.addServiceDiscoveryProvider(name, fileName);
console.info(`Middleware added`);
} else if (this.args.get) {
const file = await this.sdk.middleware.getServiceDiscoveryProviderMiddleware(this.args.get);
const file = await this.sdk.middleware.getServiceDiscoveryProvider(this.args.get);
console.info(file.toString());
} else {
throw new Error('Invalid arguments. Type -h for more info.');
Expand Down Expand Up @@ -619,7 +619,7 @@ export class Cli {
await this.sdk.middleware.addErrorHandler(name, fileName);
console.info(`Middleware added`);
} else if (this.args.get) {
const file = await this.sdk.middleware.getErrorHandlerMiddleware(this.args.get);
const file = await this.sdk.middleware.getErrorHandler(this.args.get);
console.info(file.toString());
} else {
throw new Error('Invalid arguments. Type -h for more info.');
Expand Down Expand Up @@ -651,7 +651,7 @@ export class Cli {
await this.sdk.middleware.addRequestLogger(name, fileName);
console.info(`Middleware added`);
} else if (this.args.get) {
const file = await this.sdk.middleware.getRequestLoggerMiddleware(this.args.get);
const file = await this.sdk.middleware.getRequestLogger(this.args.get);
console.info(file.toString());
} else {
throw new Error('Invalid arguments. Type -h for more info.');
Expand Down Expand Up @@ -720,7 +720,7 @@ export class Cli {

private async processConfig(): Promise<void> {
if (this.args.update) {
const config: ConfigPackage = await this.loadConfigObject(this.args.update)
const config: ConfigPackage = await this.loadConfigObject(this.args.update);
await this.sdk.config.set(config);
console.info(`Gateway configurations imported`);
} else if (this.args.get) {
Expand Down

0 comments on commit 5e64c16

Please sign in to comment.