Skip to content

Commit

Permalink
Linting, coverage, coveralls and dev rocks
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed Feb 27, 2015
1 parent cd2ac7f commit 218dad1
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ bower_components/
out/
config.*/
!config.default/

# luacov
luacov.*
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.."
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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 |
Expand Down
4 changes: 1 addition & 3 deletions kong-0.0.1beta-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions scripts/dev_rocks.sh
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.

0 comments on commit 218dad1

Please sign in to comment.