From d1a0963a4f5ca2175ea2fd2f63a727f4d590d0ae Mon Sep 17 00:00:00 2001
From: rafaelatc3sl <rpd17@c3sl>
Date: Thu, 10 Jan 2019 09:48:31 -0200
Subject: [PATCH] Issue #98: Add verification to env variable

Signed-off-by: rafaelatc3sl <rpd17@c3sl>
---
 scripts/loadTest.ts                 |  9 ++++++++-
 src/api/controllers/collect.spec.ts | 11 +++++++++--
 src/main.ts                         | 11 ++++++++++-
 test/scenario.ts                    | 10 +++++++++-
 4 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/scripts/loadTest.ts b/scripts/loadTest.ts
index dfef421c..4e8fe824 100644
--- a/scripts/loadTest.ts
+++ b/scripts/loadTest.ts
@@ -27,7 +27,14 @@ import { ConfigParser } from "../src/util/configParser";
 let config: any;
 let fixture;
 
-const configPath = process.env.BLENDB_SCHEMA_FILE;
+let configPath;
+
+if(process.env.BLENDB_SCHEMA_FILE){
+    configPath = process.env.BLENDB_SCHEMA_FILE;
+}
+else{
+    throw new Error("BLENDB_SCHEMA_FILE wasn't informed");
+}
 config = ConfigParser.parse(configPath);
 
 fixture = new FixPostgres(config.connection);
diff --git a/src/api/controllers/collect.spec.ts b/src/api/controllers/collect.spec.ts
index d189bd57..9c57224d 100644
--- a/src/api/controllers/collect.spec.ts
+++ b/src/api/controllers/collect.spec.ts
@@ -72,8 +72,15 @@ function loadDb(db: string, index: number, cb: (err: any, result: Adapter) => vo
 describe("API collect controller", () => {
     // Initializing
     before(function (done): void {
-        // Arrow function not used to get acces to this and skip the test    
-        const configPath =  process.env.BLENDB_SCHEMA_FILE;
+        // Arrow function not used to get acces to this and skip the test 
+        let configPath;
+
+        if(process.env.BLENDB_SCHEMA_FILE){
+            configPath = process.env.BLENDB_SCHEMA_FILE;
+        }
+        else{
+            throw new Error("BLENDB_SCHEMA_FILE wasn't informed");
+        }
         config = ConfigParser.parse(configPath);    
 
         eachOf(config.adapters , function(database, key: number, callback) {
diff --git a/src/main.ts b/src/main.ts
index 456e82a8..0710b3cc 100755
--- a/src/main.ts
+++ b/src/main.ts
@@ -36,8 +36,17 @@ const app = module.exports = express();
 // Load configuration file
 
 import { ConfigParser } from "./util/configParser";
+
+let configPath;
+
 /** @hidden */
-const configPath = process.env.BLENDB_SCHEMA_FILE;
+if(process.env.BLENDB_SCHEMA_FILE){
+    configPath = process.env.BLENDB_SCHEMA_FILE;
+}
+else{
+    throw new Error("BLENDB_SCHEMA_FILE wasn't informed");
+}
+
 /** @hidden */
 const config = ConfigParser.parse(configPath);
 
diff --git a/test/scenario.ts b/test/scenario.ts
index 0cad7fa5..ad807b82 100644
--- a/test/scenario.ts
+++ b/test/scenario.ts
@@ -29,7 +29,15 @@ import { ViewHandler } from "../src/util/viewHandler";
 import { EngineScenario, AdapterScenario, DataCtrlScenario } from "../src/util/scenarioHandler";
 import { Query, QueryOpts } from "../src/common/query";
 
-const configPath =  process.env.BLENDB_SCHEMA_FILE;
+let configPath;
+
+if(process.env.BLENDB_SCHEMA_FILE){
+    configPath = process.env.BLENDB_SCHEMA_FILE;
+}
+else{
+    throw new Error("BLENDB_SCHEMA_FILE wasn't informed");
+}
+
 const config = ConfigParser.parse(configPath);
 
 const mets : {[key: string]: Metric} = {};
-- 
GitLab