Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Vagrant-based integration tests #103

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add Vagrant-based integration tests
  • Loading branch information
milgner committed Sep 6, 2014
commit 25ab7ae75e68af95760fdae51d0d5a309e17c4e3
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ api/config.js
frontend/express/config.js
frontend/express/public/javascripts/countly/countly.config.js
closure-compiler.jar

# Vagrant-related & test data
.vagrant/
log/
bin/config/nginx.default.backup

24 changes: 24 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

# Installer script to set up Countly on the box
# run in noninteractive mode because of packages asking "dialog" questions
installer_script = <<SCRIPT
export DEBIAN_FRONTEND=noninteractive
/vagrant/bin/countly.install.sh
SCRIPT

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "ubuntu/trusty64"

config.vm.provision :shell, inline: installer_script

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
end
1 change: 1 addition & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
41 changes: 41 additions & 0 deletions tests/integration/post-install.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This test checks that everything is set up correctly
# after running the countly.install.sh script

assert = require 'assert'
http = require 'http'
expect = require('chai').expect

check_http = (done, port_num, expected_http_code, path = '/') ->
req = http.request(
hostname: 'localhost',
port: port_num,
path: path
, (res) ->
expect(res.statusCode).to.equal(expected_http_code)
done()
)
req.on 'error', (e) ->
done(e)
req.end()

describe 'Countly', () ->
describe 'API', () ->
describe 'runs on port 3001', () ->
it 'responds to /i', (done) ->
# will complain about missing API key
check_http(done, 3001, 400, '/i')
it 'responds to /o', (done) ->
check_http(done, 3001, 400, '/o')

describe 'Frontend', () ->
it 'runs on port 6001', (done) ->
# will redirect to login or setup
check_http(done, 6001, 302)

describe 'Web-Proxy', () ->
it 'runs on port 80', (done) ->
check_http(done, 80, 302)
it 'responds to /i', (done) ->
check_http(done, 80, 400, '/i')
it 'responds to /o', (done) ->
check_http(done, 80, 400, '/o')
23 changes: 23 additions & 0 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# if not running in vagrant, run in vagrant :)
if [ ! -d /vagrant ]; then
vagrant up
vagrant ssh -c "/vagrant/tests/run_tests.sh"
exit $?
fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
pushd $DIR > /dev/null

# check & install dependencies as required
for DEP in coffee-script mocha chai; do
if [ ! -d node_modules/$DEP ]; then
npm install $DEP
fi
done

# run integration tests
PATH=$(npm bin):$PATH mocha --compilers coffee:coffee-script/register --recursive integration/

popd > /dev/null