Add sample unit tests
diff --git a/Dockerfile-test b/Dockerfile-test
index 1b321f8..44d3548 100644
--- a/Dockerfile-test
+++ b/Dockerfile-test
@@ -23,7 +23,8 @@
&& luarocks install luabitop \
&& luarocks install luasocket \
&& luarocks install sha1 \
- && luarocks install md5
+ && luarocks install md5 \
+ && luarocks install fakeredis
COPY init-test.sh /etc/init-container-test.sh
ONBUILD COPY init-test.sh /etc/init-container-test.sh
diff --git a/Makefile b/Makefile
index a4ec8a1..06d3825 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,6 @@
.PHONY: docker-test
docker-test:
docker build -f ./Dockerfile-test -t apicgw/apigateway-test .
- docker run --rm --name="apigateway-test" apicgw/apigateway-test:latest
.PHONY: docker-test-run
docker-test-run:
diff --git a/api-gateway-config/tests/test.lua b/api-gateway-config/tests/test.lua
index e586fc7..af2bf6a 100644
--- a/api-gateway-config/tests/test.lua
+++ b/api-gateway-config/tests/test.lua
@@ -22,15 +22,46 @@
-- @author Alex Song (songs)
package.path = package.path .. ';/usr/local/share/lua/5.2/?.lua' ..
- ';/usr/local/api-gateway/lualib/resty/?.lua;/etc/api-gateway/scripts/lua/?.lua'
+ ';/usr/local/api-gateway/lualib/?.lua;/etc/api-gateway/scripts/lua/?.lua'
package.cpath = package.cpath .. ';/usr/local/lib/lua/5.2/?.so;/usr/local/api-gateway/lualib/?.so'
local fakengx = require 'fakengx'
+local fakeredis = require 'fakeredis'
+local cjson = require 'cjson'
+
+local redis = require 'lib/redis'
local request = require 'lib/request'
+describe('Testing Redis module', function()
+ before_each(function()
+ _G.ngx = fakengx.new()
+ red = fakeredis.new()
+ end)
+ it('should generate a resource obj to store in redis', function()
+ local key = 'resources:guest:hello'
+ local gatewayMethod = 'GET'
+ local backendUrl = 'https://httpbin.org:8000/get'
+ local backendMethod = gatewayMethod
+ local apiId = 12345
+ local policies
+ local security
+ local expected = {
+ operations = {
+ [gatewayMethod] = {
+ backendUrl = backendUrl,
+ backendMethod = backendMethod
+ }
+ },
+ apiId = apiId
+ }
+ expected = cjson.encode(expected)
+ local generated = redis.generateResourceObj(red, key, gatewayMethod, backendUrl, backendMethod, apiId, policies, security)
+ assert.are.same(expected, generated)
+ end)
+end)
+
describe('Testing Request module', function()
before_each(function()
- -- Mock ngx object for each test
_G.ngx = fakengx.new()
end)
it('should return correct error response', function()
diff --git a/init-test.sh b/init-test.sh
index 407f042..e83d454 100644
--- a/init-test.sh
+++ b/init-test.sh
@@ -1,3 +1,3 @@
#!/bin/bash
cd /etc/api-gateway/tests
-busted test.lua
\ No newline at end of file
+busted --output=TAP test.lua
\ No newline at end of file