From 218dad12f18104818ffb702bc9048cb7343c5a9f Mon Sep 17 00:00:00 2001 From: thibaultCha Date: Thu, 26 Feb 2015 18:15:08 -0800 Subject: [PATCH 1/4] Linting, coverage, coveralls and dev rocks --- .gitignore | 3 +++ .travis.yml | 7 +++++-- INSTALL.md | 2 +- Makefile | 17 ++++++++++++++--- README.md | 6 ++++-- kong-0.0.1beta-1.rockspec | 4 +--- scripts/dev_rocks.sh | 10 ++++++++++ src/{ => kong}/constants.lua | 0 8 files changed, 38 insertions(+), 11 deletions(-) create mode 100755 scripts/dev_rocks.sh rename src/{ => kong}/constants.lua (100%) diff --git a/.gitignore b/.gitignore index 884317827d1..889137b13c5 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 f206f897b9f..b922a12b9f3 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 36b5ed9dba8..ca8fd17e666 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 cae694f3f21..1a7d8fa60aa 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 aea37dbbf4a..0c506a5c1b8 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 b2b7aa60518..3a98ca1bd4c 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 00000000000..ed8cac32ec9 --- /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 From cc8a2096dea9ec6dfa10084e621c8dc8ee3ea003 Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Fri, 27 Feb 2015 10:57:53 -0500 Subject: [PATCH 2/4] adding os declaration be good if travis can run builds for both osx and linux --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index f206f897b9f..ad1afc81110 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ language: erlang +os: + - linux + - osx + env: - LUA="" From 70243a693772b9fa291903cbedc77807758661e4 Mon Sep 17 00:00:00 2001 From: thibaultCha Date: Fri, 27 Feb 2015 11:06:18 -0800 Subject: [PATCH 3/4] Revert "adding os declaration" This reverts commit cc8a2096dea9ec6dfa10084e621c8dc8ee3ea003. --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index ad1afc81110..f206f897b9f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,5 @@ language: erlang -os: - - linux - - osx - env: - LUA="" From 6a62e5b315070e023e8da388020d6917a6c47629 Mon Sep 17 00:00:00 2001 From: thibaultCha Date: Fri, 27 Feb 2015 12:04:45 -0800 Subject: [PATCH 4/4] README: add coveralls badge --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0c506a5c1b8..3fb6a661da4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Kong -[![Build Status][travis-image]][travis-url] [![Gitter][gitter-image]][gitter-url] +[![Build Status][travis-badge]][travis-url] [![Coverage Status][coveralls-badge]][coveralls-url] [![Gitter][gitter-badge]][gitter-url] Kong is a scalable and customizable API Management Layer built on top of nginx. @@ -104,6 +104,8 @@ scripts/db.lua drop ``` [travis-url]: https://travis-ci.org/Mashape/kong -[travis-image]: https://img.shields.io/travis/Mashape/kong.svg?style=flat +[travis-badge]: https://img.shields.io/travis/Mashape/kong.svg?style=flat +[coveralls-url]: https://coveralls.io/r/Mashape/kong?branch=master +[coveralls-badge]: https://coveralls.io/repos/Mashape/kong/badge.svg?branch=master [gitter-url]: https://gitter.im/Mashape/kong?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge -[gitter-image]: https://badges.gitter.im/Join%20Chat.svg +[gitter-badge]: https://badges.gitter.im/Join%20Chat.svg