diff --git a/.gitignore b/.gitignore index 884317827d11..889137b13c56 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ bower_components/ out/ config.*/ !config.default/ + +# luacov +luacov.* diff --git a/.travis.yml b/.travis.yml index f206f897b9f1..b922a12b9f3a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,9 @@ before_install: install: - sudo make install - - make dev + - sudo make dev -script: "make run-integration-tests FOLDER=spec" +script: "make run-integration-tests COVERAGE_FLAG=--coverage FOLDER=spec" + +after_success: + - luacov-coveralls -i kong diff --git a/INSTALL.md b/INSTALL.md index 36b5ed9dba8c..ca8fd17e6664 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -24,7 +24,7 @@ If you don't have Lua 5.1 installed: ```bash brew install lua51 -ln /usr/local/bin/lua-5.1 /usr/local/bin/lua # alias lua-5.1 to lua (required for kong scripts) +ln /usr/local/bin/lua5.1 /usr/local/bin/lua # alias lua5.1 to lua (required for kong scripts) ``` We'll need Luarocks for Lua 5.1. The official Luarocks recipe only supports 5.2 now, so we'll use a custom recipe: diff --git a/Makefile b/Makefile index cae694f3f210..1a7d8fa60aaa 100644 --- a/Makefile +++ b/Makefile @@ -6,12 +6,13 @@ export KONG_CONF ?= $(DIR)/kong.yml export NGINX_CONF ?= $(DIR)/nginx.conf export DEV_LUA_LIB ?= lua_package_path \"$(KONG_HOME)/src/?.lua\;\;\"\; export SILENT_FLAG ?= +export COVERAGE_FLAG ?= # Tests variables TESTS_DIR ?= $(KONG_HOME)/config.tests TESTS_KONG_CONF ?= $(TESTS_DIR)/kong.yml TESTS_NGINX_CONF ?= $(TESTS_DIR)/nginx.conf -.PHONY: install dev clean migrate reset seed drop test run-integration-tests test-web test-proxy test-all +.PHONY: install dev clean migrate reset seed drop test coverage run-integration-tests test-web test-proxy test-all install: @echo "Please wait, this process could take some time.." @@ -24,6 +25,7 @@ install: fi dev: + @scripts/dev_rocks.sh @mkdir -p $(DIR) @sed -e "s@lua_package_path.*;@$(DEV_LUA_LIB)@g" $(KONG_HOME)/config.default/nginx.conf > $(NGINX_CONF) @cp $(KONG_HOME)/config.default/kong.yml $(KONG_CONF) @@ -34,6 +36,7 @@ dev: clean: @rm -rf $(DIR) @rm -rf $(TESTS_DIR) + @rm -f luacov.* migrate: @scripts/db.lua $(SILENT_FLAG) migrate $(KONG_CONF) @@ -48,14 +51,22 @@ drop: @scripts/db.lua $(SILENT_FLAG) drop $(KONG_CONF) test: - @busted spec/unit + @busted $(COVERAGE_FLAG) spec/unit + +coverage: + @rm -f luacov.* + @$(MAKE) test COVERAGE_FLAG=--coverage + @luacov kong + +lint: + @luacheck kong*.rockspec --globals ngx dao utils run-integration-tests: @$(MAKE) migrate KONG_CONF=$(TESTS_KONG_CONF) @bin/kong -c $(TESTS_KONG_CONF) -n $(TESTS_NGINX_CONF) start @while ! [ `ps aux | grep nginx | grep -c -v grep` -gt 0 ]; do sleep 1; done # Wait until nginx starts @$(MAKE) seed KONG_CONF=$(TESTS_KONG_CONF) - @busted $(FOLDER) || (bin/kong stop; make drop KONG_CONF=$(TESTS_KONG_CONF) SILENT_FLAG=$(SILENT_FLAG); exit 1) + @busted $(COVERAGE_FLAG) $(FOLDER) || (bin/kong stop; make drop KONG_CONF=$(TESTS_KONG_CONF) SILENT_FLAG=$(SILENT_FLAG); exit 1) @bin/kong stop @$(MAKE) reset KONG_CONF=$(TESTS_KONG_CONF) diff --git a/README.md b/README.md index aea37dbbf4ac..0c506a5c1b8b 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Running Kong for development requires you to run: make dev ``` -This will create your environment configuration files (`dev` and `tests`). Setup your database access for each of these enviroments (be careful about keyspaces, since Kong already uses `kong` and unit tests already use `kong_tests`). +This will install development dependencies and create your environment configuration files (`dev` and `tests`). Setup your database access for each of these enviroments (be careful about keyspaces, since Kong already uses `kong` and unit tests already use `kong_tests`). - Run the tests: @@ -64,12 +64,14 @@ When developing, use the `Makefile` for doing the following operations: | Name | Description | | ------------ | --------------------------------------------------------------------------------------------------- | | `install` | Install the Kong luarock globally | -| `dev` | Setup your development enviroment (creates `config.dev` and `config.tests` configurations) | +| `dev` | Setup your development enviroment (install dev deps and creates `config.dev` and `config.tests`) | | `clean` | Clean the development environment | | `migrate` | Migrate your database schema according to the development Kong config inside `config.dev` | | `reset` | Reset your database schema according to the development Kong config inside `config.dev` | | `seed` | Seed your database according to the development Kong config inside `config.dev` | | `drop` | Drop your database according to the development Kong config inside `config.dev` | +| `lint` | Lint Lua in `src/` | +| `coverage` | Run unit tests + coverage report (only unit-tested modules) | | `test` | Run the unit tests | | `test-proxy` | Run the proxy integration tests | | `test-web` | Run the web integration tests | diff --git a/kong-0.0.1beta-1.rockspec b/kong-0.0.1beta-1.rockspec index b2b7aa605187..3a98ca1bd4cb 100644 --- a/kong-0.0.1beta-1.rockspec +++ b/kong-0.0.1beta-1.rockspec @@ -28,8 +28,6 @@ dependencies = { "stringy ~> 0.2-1", "inspect ~> 3.0-1", "luasocket ~> 2.0.2-5", - - "busted ~> 2.0.rc6-0", "lua_cliargs ~> 2.3-3", "luafilesystem ~> 1.6.2" } @@ -39,7 +37,7 @@ build = { ["kong"] = "src/main.lua", ["classic"] = "src/classic.lua", - ["kong.constants"] = "src/constants.lua", + ["kong.constants"] = "src/kong/constants.lua", ["kong.tools.utils"] = "src/kong/tools/utils.lua", ["kong.tools.faker"] = "src/kong/tools/faker.lua", diff --git a/scripts/dev_rocks.sh b/scripts/dev_rocks.sh new file mode 100755 index 000000000000..ed8cac32ec98 --- /dev/null +++ b/scripts/dev_rocks.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +NEEDED_ROCKS="busted luacov luacov-coveralls luacheck" + +for rock in ${NEEDED_ROCKS} ; do + if ! command -v ${rock} &> /dev/null ; then + echo ${rock} not found, installing via luarocks... + luarocks install ${rock} + fi +done diff --git a/src/constants.lua b/src/kong/constants.lua similarity index 100% rename from src/constants.lua rename to src/kong/constants.lua