Add scripts to install lua_modules and run tests
diff --git a/.gitignore b/.gitignore
index 5b58e6a..bbb2fb9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@
 api-gateway-config/conf.d/includes/resolvers.conf
 *.iml
 .DS_STORE
+lua_modules
 
 # Webstorm files
 .idea
@@ -11,3 +12,4 @@
 *~
 *.swp
 *.swo
+
diff --git a/Dockerfile-test b/Dockerfile-test
deleted file mode 100644
index f56bb35..0000000
--- a/Dockerfile-test
+++ /dev/null
@@ -1,34 +0,0 @@
-# Dockerfile for creating apigateway image for running unit tests
-
-FROM apicgw/apigateway:latest
-
-RUN echo "... Installing test dependencies ..." \
-    && apk add --update gcc readline-dev git unzip ncurses-dev \
-    && LUA_VERSION=5.1.5 && LUAROCKS_VERSION=2.4.1 \
-    && curl -R -O https://www.lua.org/ftp/lua-${LUA_VERSION}.tar.gz \
-    && tar zxf lua-${LUA_VERSION}.tar.gz \
-    && cd lua-${LUA_VERSION} \
-    && make linux install \
-    && wget http://keplerproject.github.io/luarocks/releases/luarocks-${LUAROCKS_VERSION}.tar.gz \
-    && tar -xvzf ./luarocks-${LUAROCKS_VERSION}.tar.gz \
-    && cd luarocks-${LUAROCKS_VERSION} \
-    && ./configure \
-    && make build \
-    && make install \
-    && cd /etc/api-gateway/tests \
-    && curl -R -O https://raw.githubusercontent.com/bsm/fakengx/master/fakengx.lua
-
-RUN echo "... Installing lua modules ..." \
-    && luarocks install busted \
-    && luarocks install luabitop \
-    && luarocks install luasocket \
-    && luarocks install sha1 \
-    && luarocks install md5 \
-    && luarocks install fakeredis \
-    && luarocks install luacov
-
-COPY init-test.sh /etc/init-container-test.sh
-ONBUILD COPY init-test.sh /etc/init-container-test.sh
-RUN chmod +x /etc/init-container-test.sh
-
-ENTRYPOINT ["/etc/init-container-test.sh"]
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 06d3825..eb2851d 100644
--- a/Makefile
+++ b/Makefile
@@ -4,18 +4,18 @@
 docker:
 	docker build -t apicgw/apigateway .
 
-.PHONY: docker-test
-docker-test:
-	docker build -f ./Dockerfile-test -t apicgw/apigateway-test .
-
-.PHONY: docker-test-run
-docker-test-run:
-	docker run --rm --name="apigateway-test" apicgw/apigateway-test:latest
-
 .PHONY: docker-ssh
 docker-ssh:
 	docker run -ti --entrypoint='bash' apicgw/apigateway:latest
 
+.PHONY: test-build
+test-build:
+	cd api-gateway-config/tests; ./install-deps.sh
+
+.PHONY: test-run
+test-run:
+	cd api-gateway-config/tests; ./run-tests.sh
+
 .PHONY: docker-run
 docker-run:
 	docker run --rm --name="apigateway" -p 80:80 -p 5000:5000 apicgw/apigateway:latest ${DOCKER_ARGS}
@@ -53,17 +53,6 @@
 	docker stop apigateway
 	docker rm apigateway
 
-.PHONY: docker-compose
-docker-compose:
-	#Volumes directories must be under your Users directory
-	mkdir -p ${HOME}/tmp/apiplatform/apigateway
-	rm -rf ${HOME}/tmp/apiplatform/apigateway/api-gateway-config
-	cp -r `pwd`/api-gateway-config ${HOME}/tmp/apiplatform/apigateway/
-	sed -i '' 's/127\.0\.0\.1/redis\.docker/' ${HOME}/tmp/apiplatform/apigateway/api-gateway-config/environment.conf.d/api-gateway-upstreams.http.conf
-	# clone api-gateway-redis block
-	sed -e '/api-gateway-redis/,/}/!d' ${HOME}/tmp/apiplatform/apigateway/api-gateway-config/environment.conf.d/api-gateway-upstreams.http.conf | sed 's/-redis/-redis-replica/' >> ${HOME}/tmp/apiplatform/apigateway/api-gateway-config/environment.conf.d/api-gateway-upstreams.http.conf
-	docker-compose up
-
 .PHONY: docker-push
 docker-push:
 	docker tag -f apicgw/apigateway $(DOCKER_REGISTRY)/apicgw/apigateway:$(DOCKER_TAG)
diff --git a/README.md b/README.md
index 973c91e..3e9d6f2 100644
--- a/README.md
+++ b/README.md
@@ -244,4 +244,18 @@
   $ curl http://<docker_host_ip>/health-check
     API-Platform is running!
  ```
+ 
+##Testing
+
+ Unit tests can be found in the `api-gateway-config/tests/spec` directory.
+
+ First install the necessary dependencies:
+ ```
+  make test-build
+ ```
+ Then, run the unit tests:
+ ```
+  make test-run
+ ```
+ This will output the results of the tests as well as generate a code coverage report.
 
diff --git a/api-gateway-config/tests/install-deps.sh b/api-gateway-config/tests/install-deps.sh
new file mode 100755
index 0000000..d44356a
--- /dev/null
+++ b/api-gateway-config/tests/install-deps.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+# Install global dependencies
+luarocks install busted
+luarocks install luacov
+# Install test dependencies
+mkdir -p lua_modules
+luarocks install --tree lua_modules lua-cjson
+luarocks install --tree lua_modules luabitop
+luarocks install --tree lua_modules luasocket
+luarocks install --tree lua_modules sha1
+luarocks install --tree lua_modules md5
+luarocks install --tree lua_modules fakeredis
\ No newline at end of file
diff --git a/run-tests.sh b/api-gateway-config/tests/run-tests.sh
similarity index 71%
rename from run-tests.sh
rename to api-gateway-config/tests/run-tests.sh
index 189ef3a..7d27b35 100755
--- a/run-tests.sh
+++ b/api-gateway-config/tests/run-tests.sh
@@ -1,8 +1,7 @@
 #!/bin/bash
 
 # Run unit tests
-cd api-gateway-config/tests
-busted -c --output=TAP test.lua
+busted -c --output=TAP --helper=set_paths spec/test.lua
 
 # Generate code coverage report
 luacov ../scripts/lua/
diff --git a/api-gateway-config/tests/set_paths.lua b/api-gateway-config/tests/set_paths.lua
new file mode 100644
index 0000000..bdc8afb
--- /dev/null
+++ b/api-gateway-config/tests/set_paths.lua
@@ -0,0 +1,11 @@
+-- add lua_modules to package.path and package.cpath
+local version = _VERSION:match("%d+%.%d+")
+local f = assert(io.popen('pwd', 'r'))
+local pwd = assert(f:read('*a')):sub(1, -2)
+f:close()
+package.path = package.path ..
+    ';' .. pwd .. '/lua_modules/share/lua/' .. version .. '/?.lua' ..
+    ';' .. pwd .. '/lua_modules/share/lua/' .. version .. '/?/init.lua' ..
+    ';' .. pwd .. '/../scripts/lua/?.lua'
+package.cpath = package.cpath ..
+    ';' .. pwd .. '/lua_modules/lib/lua/' .. version .. '/?.so'
\ No newline at end of file
diff --git a/api-gateway-config/tests/test.lua b/api-gateway-config/tests/spec/test.lua
similarity index 88%
rename from api-gateway-config/tests/test.lua
rename to api-gateway-config/tests/spec/test.lua
index 3c9e789..04da8e7 100644
--- a/api-gateway-config/tests/test.lua
+++ b/api-gateway-config/tests/spec/test.lua
@@ -21,10 +21,6 @@
 -- Unit tests for the apigateway using the busted framework.
 -- @author Alex Song (songs)
 
-local handle = io.popen('pwd')
-local pwd = handle:read('*a'):sub(1, -2)  -- get current working directory
-handle:close()
-package.path = package.path .. ';' .. pwd .. '/../scripts/lua/?.lua'
 local fakengx = require 'fakengx'
 local fakeredis = require 'fakeredis'
 local cjson = require 'cjson'
@@ -32,6 +28,7 @@
 local utils = require 'lib/utils'
 local logger = require 'lib/logger'
 local redis = require 'lib/redis'
+local mapping = require 'policies/mapping'
 
 
 ------------------------------------
@@ -102,30 +99,6 @@
   it('should convert templated path parameter', function()
     -- TODO: Add test cases for convertTemplatedPathParam(m)
   end)
-
-  it('should convert json body to lua table', function()
-    -- General case
-    local jsonString = '{ "apiId" : 12345, "policies" : [{"test":true}], "security" : {}}'
-    local expected = cjson.decode(jsonString)
-    local args = {}
-    args[jsonString] = true
-    local generated = utils.convertJSONBody(args)
-    assert.are.same(expected, generated)
-
-    -- "=" sign in original body, resulting in separated out key
-    -- original json string is '{ "apiId" : 12345, "policies" : [{"test":true}], "security" : {"apiKey":"a53kw2kfq302="}}'
-    local firstHalf = '{ "apiId" : 12345, "policies" : [{"test":true}], "security" : {"apiKey":"a53kw2kfq302'
-    local secondHalf = '"}}'
-    expected = {
-      apiId = 12345,
-      policies = {{test=true}},
-      security = {apiKey = "a53kw2kfq302="}
-    }
-    args = {}
-    args[firstHalf] = secondHalf
-    generated = utils.convertJSONBody(args)
-    assert.are.same(expected, generated)
-  end)
 end)
 
 
@@ -277,4 +250,9 @@
 ---- Unit tests for policy modules ----
 ---------------------------------------
 
---TODO: mapping, rateLimit, security
\ No newline at end of file
+--TODO: mapping, rateLimit, security
+describe('Testing mapping module', function()
+  before_each(function()
+    _G.ngx = fakengx.new()
+  end)
+end)