Skip to content

Commit c2f4085

Browse files
committed
feat(test): add integration tests
Adds a test/ directory with a Rakefile that defines integration tests to fully exercise a Deis cluster. Currently these are written in Ruby, as the goal here was to get tests implemented quickly. The tests were written so they can be easily ported later.
1 parent 6b4f890 commit c2f4085

6 files changed

Lines changed: 130 additions & 0 deletions

File tree

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,8 @@ status: check-fleet
115115
stop: check-fleet
116116
fleetctl --strict-host-key-checking=false stop $(ALL_UNITS)
117117

118+
tests:
119+
cd test && bundle install && bundle exec rake
120+
118121
uninstall: check-fleet stop
119122
fleetctl --strict-host-key-checking=false destroy $(ALL_UNITS)

test/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
example-*

test/Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'mixlib-shellout', '~> 1.4.0'
4+
gem 'rainbow', '~> 2.0.0'
5+
gem 'rake', '~> 10.3.1'

test/Gemfile.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
mixlib-shellout (1.4.0)
5+
rainbow (2.0.0)
6+
rake (10.3.1)
7+
8+
PLATFORMS
9+
ruby
10+
11+
DEPENDENCIES
12+
mixlib-shellout (~> 1.4.0)
13+
rainbow (~> 2.0.0)
14+
rake (~> 10.3.1)

test/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Deis integration testing
2+
This directory includes a Rakefile which will run integration tests on an existing Deis cluster.
3+
4+
To run all tests:
5+
6+
```console
7+
$ bundle install
8+
$ bundle exec rake
9+
```
10+
11+
The namespaces `setup`, `tests`, and `cleanup` are defined. The default task runs `setup:all`, `tests:all`, `cleanup:all` and then exits.
12+
13+
Namespaces can also be run manually:
14+
15+
```console
16+
$ bundle exec rake setup:all
17+
```
18+
19+
...and so can tests:
20+
21+
```console
22+
$ bundle exec rake tests:create_cluster
23+
```
24+
25+
The test environment uses several environment variables, which can be set to customize the run:
26+
* `DEIS_TEST_AUTH_KEY` - SSH key used to register with the Deis controller -- will be generated if it doesn't exist (default: `~/.ssh/deis`)
27+
* `DEIS_TEST_KEY` - SSH key used to login to the controller machine (default: `~/.vagrant.d/insecure_private_key`)
28+
* `DEIS_TEST_HOST` - hostname which resolves to the controller host (default: `local.deisapp.com`)
29+
* `DEIS_TEST_APP` - name of the Deis example app to use, which is cloned from GitHub (default: `example-ruby-sinatra`)

test/Rakefile

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env rake
2+
3+
require 'mixlib/shellout'
4+
require 'rainbow/ext/string'
5+
6+
AUTH_KEY = ENV['DEIS_TEST_KEY'] || '~/.ssh/deis'
7+
SSH_KEY = ENV['DEIS_TEST_SSH_KEY'] || '~/.vagrant.d/insecure_private_key'
8+
HOST = ENV['DEIS_TEST_HOST'] || 'local.deisapp.com'
9+
EXAMPLE_APP = ENV['DEIS_TEST_APP'] || 'example-ruby-sinatra'
10+
11+
namespace :setup do
12+
task :all => ['create_ssh_key','clone_example_app']
13+
task :create_ssh_key do
14+
run_command("if [ ! -f #{AUTH_KEY} ]; then ssh-keygen -q -t rsa -f #{AUTH_KEY} -N '' -C deis && ssh-add -K #{AUTH_KEY} ; fi")
15+
end
16+
task :clone_example_app do
17+
run_command("if [ ! -d ./#{EXAMPLE_APP} ]; then git clone https://github.com/opdemand/#{EXAMPLE_APP}.git ; fi")
18+
end
19+
end
20+
21+
namespace :tests do
22+
task :all => ['register','login','add_key','create_cluster','create_app','push_app','scale_app','verify_app']
23+
task :register do
24+
run_command("deis register http://#{HOST}:8000 --username=test --email=test@test.co.nz --password=asdf1234")
25+
end
26+
task :login do
27+
run_command("deis login http://#{HOST}:8000 --username=test --password=asdf1234")
28+
end
29+
task :add_key do
30+
run_command("deis keys:add #{AUTH_KEY}.pub")
31+
end
32+
task :create_cluster do
33+
run_command("deis init dev #{HOST} --hosts=#{HOST} --auth=#{SSH_KEY}")
34+
end
35+
task :create_app do
36+
run_command("cd #{EXAMPLE_APP} && deis apps:create testing")
37+
end
38+
task :push_app do
39+
run_command("cd #{EXAMPLE_APP} && git push deis master")
40+
end
41+
task :scale_app do
42+
run_command("cd #{EXAMPLE_APP} && deis scale web=2")
43+
end
44+
task :verify_app do
45+
run_command("curl -s http://testing.#{HOST} | grep -q 'Powered by Deis'")
46+
end
47+
end
48+
49+
namespace :cleanup do
50+
task :all => ['destroy_app','destroy_cluster','remove_key','logout']
51+
task :destroy_app do
52+
run_command("cd #{EXAMPLE_APP} && deis apps:destroy --app=testing --confirm=testing")
53+
end
54+
task :destroy_cluster do
55+
run_command("deis clusters:destroy dev --confirm=dev")
56+
end
57+
task :remove_key do
58+
run_command("deis keys:remove deis")
59+
end
60+
task :logout do
61+
run_command("deis auth:logout")
62+
end
63+
end
64+
65+
def run_command(cmd)
66+
print "Running #{cmd}... ".color(:yellow)
67+
cmd = Mixlib::ShellOut.new(cmd).run_command
68+
if not cmd.error?
69+
puts "Success!".color(:green)
70+
else
71+
puts "Failed!".color(:red)
72+
puts cmd.stdout.color(:red)
73+
puts cmd.stderr.color(:red)
74+
raise "Command failed - stopping"
75+
end
76+
end
77+
78+
task :default => ['setup:all', 'tests:all', 'cleanup:all']

0 commit comments

Comments
 (0)