diff --git a/.travis.yml b/.travis.yml index 9081a9e9d66..f994befdfd2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,18 +9,15 @@ branches: - master before_install: - - bash .travis/setup_lua.sh - - bash .travis/setup_openresty.sh - - export PATH=$PATH:/usr/local/openresty/nginx/sbin + - bash .travis/setup_kong.sh - bash .travis/setup_cassandra.sh - - bash .travis/setup_dnsmasq.sh install: - sudo make install - sudo make dev script: - - "busted --coverage spec/" + - "busted -o spec/busted-print.lua --coverage spec/ spec/" - "luacheck kong" after_success: "luacov-coveralls -i kong" diff --git a/.travis/kong-0.3.0travis.precise_all.deb.REMOVED.git-id b/.travis/kong-0.3.0travis.precise_all.deb.REMOVED.git-id new file mode 100644 index 00000000000..407cb8489b1 --- /dev/null +++ b/.travis/kong-0.3.0travis.precise_all.deb.REMOVED.git-id @@ -0,0 +1 @@ +bce95eeda6a509f6f92d9e7537089a17006ee45b \ No newline at end of file diff --git a/.travis/platform.sh b/.travis/platform.sh deleted file mode 100644 index 4a3af0d487e..00000000000 --- a/.travis/platform.sh +++ /dev/null @@ -1,15 +0,0 @@ -if [ -z "$PLATFORM" ]; then - PLATFORM=$TRAVIS_OS_NAME; -fi - -if [ "$PLATFORM" == "osx" ]; then - PLATFORM="macosx"; -fi - -if [ -z "$PLATFORM" ]; then - if [ "$(uname)" == "Linux" ]; then - PLATFORM="linux"; - else - PLATFORM="macosx"; - fi; -fi diff --git a/.travis/setup_dnsmasq.sh b/.travis/setup_dnsmasq.sh deleted file mode 100644 index 75a6e6b7ea8..00000000000 --- a/.travis/setup_dnsmasq.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -sudo apt-get update && sudo apt-get install dnsmasq sudo -echo -e "user=root" | sudo tee /etc/dnsmasq.conf \ No newline at end of file diff --git a/.travis/setup_kong.sh b/.travis/setup_kong.sh new file mode 100644 index 00000000000..36ba8680a59 --- /dev/null +++ b/.travis/setup_kong.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +source ./versions.sh + +sudo apt-get update + +# Installing dependencies required to build development rocks +sudo apt-get install wget curl tar make gcc unzip git liblua5.1-0-dev + +# Installing dependencies required for Kong +sudo apt-get install sudo netcat lua5.1 openssl libpcre3 dnsmasq + +# Installing Kong and its dependencies +sudo dpkg -i ./.travis/kong-0.3.0travis.precise_all.deb \ No newline at end of file diff --git a/.travis/setup_lua.sh b/.travis/setup_lua.sh deleted file mode 100644 index d94c4ba1d99..00000000000 --- a/.travis/setup_lua.sh +++ /dev/null @@ -1,101 +0,0 @@ -#!/bin/bash - -# A script for setting up environment for travis-ci testing. -# Sets up Lua and Luarocks. -# LUA must be "lua5.1", "lua5.2" or "luajit". -# luajit2.0 - master v2.0 -# luajit2.1 - master v2.1 - -LUAJIT_BASE="LuaJIT-$LUAJIT_VERSION" - -source .travis/platform.sh - -LUAJIT_ENABLED="no" - -if [ "$PLATFORM" == "macosx" ]; then - if [ "$LUA" == "luajit" ]; then - LUAJIT_ENABLED="yes"; - fi - if [ "$LUA" == "luajit2.0" ]; then - LUAJIT_ENABLED="yes"; - fi - if [ "$LUA" == "luajit2.1" ]; then - LUAJIT_ENABLED="yes"; - fi; -elif [ "$(expr substr $LUA 1 6)" == "luajit" ]; then - LUAJIT_ENABLED="yes"; -fi - -if [ "$LUAJIT_ENABLED" == "yes" ]; then - - if [ "$LUA" == "luajit" ]; then - curl http://luajit.org/download/$LUAJIT_BASE.tar.gz | tar xz; - else - git clone http://luajit.org/git/luajit-2.0.git $LUAJIT_BASE; - fi - - cd $LUAJIT_BASE - - if [ "$LUA" == "luajit2.1" ]; then - git checkout v2.1; - fi - - make && sudo make install - - if [ "$LUA" == "luajit2.1" ]; then - sudo ln -s /usr/local/bin/luajit-2.1.0-alpha /usr/local/bin/luajit - sudo ln -s /usr/local/bin/luajit /usr/local/bin/lua; - else - sudo ln -s /usr/local/bin/luajit /usr/local/bin/lua; - fi; - -else - if [ "$LUA" == "lua5.1" ]; then - curl http://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xz - cd lua-5.1.5; - elif [ "$LUA" == "lua5.2" ]; then - curl http://www.lua.org/ftp/lua-5.2.3.tar.gz | tar xz - cd lua-5.2.3; - elif [ "$LUA" == "lua5.3" ]; then - curl http://www.lua.org/ftp/lua-5.3.0.tar.gz | tar xz - cd lua-5.3.0; - fi - sudo make $PLATFORM install; -fi - -cd $TRAVIS_BUILD_DIR; - -LUAROCKS_BASE=luarocks-$LUAROCKS_VERSION - -# curl http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz | tar xz - -git clone https://github.com/keplerproject/luarocks.git $LUAROCKS_BASE -cd $LUAROCKS_BASE - -git checkout v$LUAROCKS_VERSION - -if [ "$LUA" == "luajit" ]; then - ./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.0; -elif [ "$LUA" == "luajit2.0" ]; then - ./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.0; -elif [ "$LUA" == "luajit2.1" ]; then - ./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.1; -else - ./configure; -fi - -make build && sudo make install - -cd $TRAVIS_BUILD_DIR - -rm -rf $LUAROCKS_BASE - -if [ "$LUAJIT_ENABLED" == "yes" ]; then - rm -rf $LUAJIT_BASE; -elif [ "$LUA" == "lua5.1" ]; then - rm -rf lua-5.1.5; -elif [ "$LUA" == "lua5.2" ]; then - rm -rf lua-5.2.3; -elif [ "$LUA" == "lua5.3" ]; then - rm -rf lua-5.3.0; -fi diff --git a/.travis/setup_openresty.sh b/.travis/setup_openresty.sh deleted file mode 100644 index b503fd9c241..00000000000 --- a/.travis/setup_openresty.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash - -source ./versions.sh - -OPENRESTY_BASE=ngx_openresty-$OPENRESTY_VERSION -OPENSSL_BASE=openssl-$OPENSSL_VERSION - -sudo apt-get update && sudo apt-get install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl make wget - -cd $TRAVIS_BUILD_DIR - -# Download OpenSSL -wget https://www.openssl.org/source/$OPENSSL_BASE.tar.gz -O $OPENSSL_BASE.tar.gz -tar xzf $OPENSSL_BASE.tar.gz -OPENRESTY_CONFIGURE_PARAMS="--with-openssl=$TRAVIS_BUILD_DIR/$OPENSSL_BASE" - -# Download OpenResty -curl http://openresty.org/download/$OPENRESTY_BASE.tar.gz | tar xz - -# Download and apply nginx patch -cd $OPENRESTY_BASE/bundle/nginx-* -wget https://raw.githubusercontent.com/openresty/lua-nginx-module/ssl-cert-by-lua/patches/nginx-ssl-cert.patch --no-check-certificate -patch -p1 < nginx-ssl-cert.patch -cd .. - -# Download `ssl-cert-by-lua` branch -wget https://github.com/openresty/lua-nginx-module/archive/ssl-cert-by-lua.tar.gz -O ssl-cert-by-lua.tar.gz --no-check-certificate -tar xzf ssl-cert-by-lua.tar.gz - -# Replace `ngx_lua-*` with `ssl-cert-by-lua` branch -NGX_LUA=`ls | grep ngx_lua-*` -rm -rf $NGX_LUA -mv lua-nginx-module-ssl-cert-by-lua $NGX_LUA - -# Install ssl.lua -cd $NGX_LUA/lua -echo ' -package = "ngxssl" -version = "0.1-1" -source = { - url = "git://github.com/openresty/lua-nginx-module", - branch = "ssl-cert-by-lua" -} -dependencies = { - "lua >= 5.1" -} -build = { - type = "builtin", - modules = { - ["ngx.ssl"] = "ngx/ssl.lua" - } -} -' > ngxssl-0.1-1.rockspec -sudo luarocks make ngxssl-0.1-1.rockspec - -# Install OpenResty -cd $TRAVIS_BUILD_DIR/$OPENRESTY_BASE -./configure --with-pcre-jit --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module $OPENRESTY_CONFIGURE_PARAMS -make && sudo make install -cd $TRAVIS_BUILD_DIR -rm -rf $OPENRESTY_BASE -rm -rf $OPENSSL_BASE \ No newline at end of file diff --git a/Makefile b/Makefile index f666c8627e4..f2c4c4a1be3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ TESTING_CONF = kong_TEST.yml DEVELOPMENT_CONF = kong_DEVELOPMENT.yml -DEV_ROCKS=busted luacov luacov-coveralls luacheck +DEV_ROCKS=busted luacov luacov-coveralls luacheck ansicolors .PHONY: install dev clean start seed drop lint test coverage test-all diff --git a/distributions/build-package-script.sh b/distributions/build-package-script.sh index 11533ea1f12..704f109f553 100755 --- a/distributions/build-package-script.sh +++ b/distributions/build-package-script.sh @@ -196,26 +196,6 @@ tar xzf ssl-cert-by-lua.tar.gz NGX_LUA=`ls | grep ngx_lua-*` rm -rf $NGX_LUA mv lua-nginx-module-ssl-cert-by-lua $NGX_LUA -# Install ssl.lua -cd $NGX_LUA/lua -echo ' -package = "ngxssl" -version = "0.1-1" -source = { - url = "git://github.com/openresty/lua-nginx-module", - branch = "ssl-cert-by-lua" -} -dependencies = { - "lua >= 5.1" -} -build = { - type = "builtin", - modules = { - ["ngx.ssl"] = "ngx/ssl.lua" - } -} -' > ngxssl-0.1-1.rockspec -$OUT/usr/local/bin/luarocks make ngxssl-0.1-1.rockspec # Configure and install cd $TMP/ngx_openresty-$OPENRESTY_VERSION ./configure --with-pcre-jit --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module ${OPENRESTY_CONFIGURE} diff --git a/kong/cli/utils/signal.lua b/kong/cli/utils/signal.lua index e26bf2d0d82..e6edf1f9ad1 100644 --- a/kong/cli/utils/signal.lua +++ b/kong/cli/utils/signal.lua @@ -272,11 +272,6 @@ function _M.send_signal(args_config, signal) end end - local nginx_pid - if IO.file_exists(kong_config.pid_file) then - nginx_pid = stringy.strip(IO.read_file(kong_config.pid_file)) - end - -- Build nginx signal command local cmd = string.format("KONG_CONF=%s %s -p %s -c %s -g 'pid %s;' %s", kong_config_path, @@ -315,10 +310,6 @@ function _M.send_signal(args_config, signal) stop_dnsmasq(kong_config) -- If the start failed, then stop dnsmasq end - if success and (signal == STOP or signal == QUIT) and nginx_pid then - IO.os_execute("while kill -0 "..nginx_pid.." >/dev/null 2>&1; do sleep 0.1; done") - end - return success end diff --git a/kong/cli/utils/utils.lua b/kong/cli/utils/utils.lua index f33056006a9..18c132b1fff 100644 --- a/kong/cli/utils/utils.lua +++ b/kong/cli/utils/utils.lua @@ -9,7 +9,6 @@ local constants = require "kong.constants" local Object = require "classic" local lpath = require "luarocks.path" local IO = require "kong.tools.io" -local socket = require "socket" -- -- Colors @@ -152,10 +151,8 @@ end -- @param `port` The port to check -- @return `open` True if open, false otherwise local function is_port_open(port) - local tcp = socket.tcp() - local ok = tcp:connect("127.0.0.1", port) - tcp:close() - return ok + local _, code = IO.os_execute("nc -w 3 127.0.0.1 "..tostring(port).." <<< \"\"") + return code == 0 end return { diff --git a/spec/busted-print.lua b/spec/busted-print.lua new file mode 100644 index 00000000000..ecc94930ce9 --- /dev/null +++ b/spec/busted-print.lua @@ -0,0 +1,21 @@ +local ansicolors = require 'ansicolors' + +return function(options) + local handler = require 'busted.outputHandlers.utfTerminal'(options) + + handler.fileStart = function(file) + io.write('\n' .. ansicolors('%{cyan}' .. file.name) .. ':') + end + + handler.testStart = function(element, parent, status, debug) + io.write('\n ' .. handler.getFullName(element) .. ' ... ') + io.flush() + end + + local busted = require 'busted' + + busted.subscribe({ 'file', 'start' }, handler.fileStart) + busted.subscribe({ 'test', 'start' }, handler.testStart) + + return handler +end diff --git a/spec/integration/admin_api/admin_api_spec.lua b/spec/integration/admin_api/admin_api_spec.lua index 4032778884f..6be06c86fe9 100644 --- a/spec/integration/admin_api/admin_api_spec.lua +++ b/spec/integration/admin_api/admin_api_spec.lua @@ -40,7 +40,7 @@ local ENDPOINTS = { } }, update_fields = { enabled = false }, - error_message = '{"name":"name is required","api_id":"api_id is required","value":"value is required"}\n' + error_message = '{"api_id":"api_id is required","name":"name is required"}\n' } } diff --git a/spec/plugins/logging_spec.lua b/spec/plugins/logging_spec.lua index 9ec064cb907..e9fe55da104 100644 --- a/spec/plugins/logging_spec.lua +++ b/spec/plugins/logging_spec.lua @@ -12,9 +12,9 @@ uuid.seed() local STUB_GET_URL = spec_helper.STUB_GET_URL local TEST_CONF = "kong_TEST.yml" -local TCP_PORT = 7777 -local UDP_PORT = 7778 -local HTTP_PORT = 7779 +local TCP_PORT = 20777 +local UDP_PORT = 20778 +local HTTP_PORT = 20779 describe("Logging Plugins", function() @@ -79,11 +79,8 @@ describe("Logging Plugins", function() end) it("should log to HTTP", function() - pending() local thread = spec_helper.start_http_server(HTTP_PORT) -- Starting the mock TCP server - --os.execute("sleep 0.5") - -- Making the request local _, status = http_client.get(STUB_GET_URL, nil, { host = "http_logging.com" }) assert.are.equal(200, status) diff --git a/spec/spec_helpers.lua b/spec/spec_helpers.lua index a8a97de9396..b075de5a977 100644 --- a/spec/spec_helpers.lua +++ b/spec/spec_helpers.lua @@ -190,4 +190,4 @@ end -- Add the default env to our spec_helper _M.add_env(_M.TEST_CONF_FILE) -return _M +return _M \ No newline at end of file diff --git a/spec/unit/schemas_spec.lua b/spec/unit/schemas_spec.lua index c3bfb351518..95e1e37437c 100644 --- a/spec/unit/schemas_spec.lua +++ b/spec/unit/schemas_spec.lua @@ -417,7 +417,7 @@ describe("Schemas", function() local valid, err = validate(obj, schema) assert.truthy(err) assert.False(valid) - --assert.are.same("hello", obj.value.some_property) + assert.are.same("value is required", err.value) end) end) diff --git a/versions.sh b/versions.sh index 1270d0f940e..a67924a4122 100755 --- a/versions.sh +++ b/versions.sh @@ -1,12 +1,2 @@ # Travis only -CASSANDRA_VERSION=2.1.5 - -# Travis and package builder -LUAROCKS_VERSION=2.2.2 -OPENRESTY_VERSION=1.7.10.2rc0 - -# Package builder only -LUA_VERSION=5.1.4 -PCRE_VERSION=8.36 -KONG_VERSION=0.2.0-2 -OPENSSL_VERSION=1.0.2a \ No newline at end of file +CASSANDRA_VERSION=2.1.5 \ No newline at end of file