From 234cb7ee42ca5a27614576a027f70aa80d35b629 Mon Sep 17 00:00:00 2001
From: Rafael <rpd17@inf.ufpr.br>
Date: Tue, 28 Aug 2018 11:42:55 -0300
Subject: [PATCH] Issue #86: Add environment variable for yaml files

Signed-off-by: Rafael <rpd17@inf.ufpr.br>
---
 .gitlab-ci.yml                      | 2 --
 config/ci_monet_test.env.example    | 1 +
 config/ci_postgres_test.env.example | 1 +
 config/config.env.example           | 1 +
 src/adapter/postgres.spec.ts        | 3 ++-
 src/api/controllers/collect.spec.ts | 3 ++-
 src/main.ts                         | 2 +-
 test/scenario.ts                    | 3 ++-
 8 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 77635187..a8939b05 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -28,7 +28,6 @@ run_test_postgres:
     stage: test
     script:                
         - yarn install --frozen-lockfile --silent --non-interactive
-        - mv config/ci_test.yaml.example config/test.yaml
         - mv config/ci_postgres_test.env.example config/test.env
         - yarn test
         - yarn run lint
@@ -40,7 +39,6 @@ run_test_monet:
     stage: test
     script: 
         - yarn install --frozen-lockfile --silent --non-interactive
-        - mv config/ci_test.yaml.example config/test.yaml
         - mv config/ci_monet_test.env.example config/test.env
         - yarn test
         - yarn run lint
diff --git a/config/ci_monet_test.env.example b/config/ci_monet_test.env.example
index 2bec39d9..bbdd0ca9 100644
--- a/config/ci_monet_test.env.example
+++ b/config/ci_monet_test.env.example
@@ -4,4 +4,5 @@ BLENDB_DB_PASSWORD=monetdb
 BLENDB_DB_HOST=monet
 BLENDB_DB_PORT=50000
 BLENDB_ADAPTER=monet
+BLENDB_SCHEMA_FILE=config/ci_test.yaml.example
 PORT=3000
diff --git a/config/ci_postgres_test.env.example b/config/ci_postgres_test.env.example
index 433eeb12..64c1c597 100644
--- a/config/ci_postgres_test.env.example
+++ b/config/ci_postgres_test.env.example
@@ -4,4 +4,5 @@ BLENDB_DB_PASSWORD=
 BLENDB_DB_HOST=postgres
 BLENDB_DB_PORT=5432
 BLENDB_ADAPTER=postgres
+BLENDB_SCHEMA_FILE=config/ci_test.yaml.example
 PORT=3000
diff --git a/config/config.env.example b/config/config.env.example
index 565344bf..16b7a86b 100644
--- a/config/config.env.example
+++ b/config/config.env.example
@@ -4,4 +4,5 @@ BLENDB_DB_PASSWORD=secret
 BLENDB_DB_HOST=localhost
 BLENDB_DB_PORT=5432
 BLENDB_ADAPTER=postgres
+BLENDB_SCHEMA_FILE=config/config.yaml
 PORT=3000
diff --git a/src/adapter/postgres.spec.ts b/src/adapter/postgres.spec.ts
index 867d4c83..a77952af 100644
--- a/src/adapter/postgres.spec.ts
+++ b/src/adapter/postgres.spec.ts
@@ -36,7 +36,8 @@ describe("Sql adapter", () => {
     let fixture;
     before(function (done): void {
         // Arrow function not used to get acces to this and skip the test
-        config = ConfigParser.parse("config/test.yaml");
+        const configPath =  process.env.BLENDB_SCHEMA_FILE;
+        config = ConfigParser.parse(configPath);
 
         if (config.adapter === "postgres") {
             fixture = new FixPostgres(config.connection);
diff --git a/src/api/controllers/collect.spec.ts b/src/api/controllers/collect.spec.ts
index 24ac015a..7ad1619a 100644
--- a/src/api/controllers/collect.spec.ts
+++ b/src/api/controllers/collect.spec.ts
@@ -36,7 +36,8 @@ describe("API collect controller", () => {
     let fixture;
     before(function (done): void {
         // Arrow function not used to get acces to this and skip the test
-        config = ConfigParser.parse("config/test.yaml");
+        const configPath =  process.env.BLENDB_SCHEMA_FILE;
+        config = ConfigParser.parse(configPath);
         if (config.adapter === "postgres") {
             fixture = new FixPostgres(config.connection);
             fixture.loadSource(config.sources, (err) => {
diff --git a/src/main.ts b/src/main.ts
index de792ba5..7a0133ff 100755
--- a/src/main.ts
+++ b/src/main.ts
@@ -37,7 +37,7 @@ const app = module.exports = express();
 
 import { ConfigParser } from "./util/configParser";
 /** @hidden */
-const configPath = (app.get("env") === "test") ? "config/test.yaml" : "config/config.yaml";
+const configPath = process.env.BLENDB_SCHEMA_FILE;
 /** @hidden */
 const config = ConfigParser.parse(configPath);
 
diff --git a/test/scenario.ts b/test/scenario.ts
index 59a91b72..8aa83ecb 100644
--- a/test/scenario.ts
+++ b/test/scenario.ts
@@ -66,7 +66,8 @@ interface DataCtrlScenario {
     clausal: Query;
 }
 
-const config = ConfigParser.parse("config/test.yaml");
+const configPath =  process.env.BLENDB_SCHEMA_FILE;
+const config = ConfigParser.parse(configPath);
 
 const mets = config.metrics.sort((a, b) => {
     const aValue = parseInt(a.name.split(":")[1], 10);
-- 
GitLab