-
Notifications
You must be signed in to change notification settings - Fork 125
/
Rakefile
80 lines (67 loc) · 2.22 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require "bundler/gem_tasks"
require 'rspec/core/rake_task'
require 'tempfile'
require 'net/ssh'
Dir['tasks/*.rb'].each do |file|
require_relative file
end
desc 'Run unit and integration specs.'
task :spec => ['spec:unit', 'spec:integration:all']
TEST_IMAGE = ENV["TEST_IMAGE"] || "ubuntu:trusty"
namespace :spec do
RSpec::Core::RakeTask.new("unit") do |task|
task.ruby_opts = '-I ./spec/unit'
task.pattern = "./spec/unit{,/*/**}/*_spec.rb"
end
namespace :integration do
container_name = 'itamae'
task :all => ['spec:integration:docker', 'spec:integration:local']
desc "Run provision and specs"
task :docker => ["docker:boot", "docker:provision", "docker:serverspec", 'docker:clean_docker_container']
namespace :docker do
desc "Run docker"
task :boot do
sh "docker run --privileged -d --name #{container_name} #{TEST_IMAGE} /sbin/init"
end
desc "Run itamae"
task :provision do
suites = [
[
"spec/integration/recipes/default.rb",
"spec/integration/recipes/default2.rb",
"spec/integration/recipes/redefine.rb",
"spec/integration/recipes/docker.rb",
],
[
"--dry-run",
"spec/integration/recipes/dry_run.rb",
],
]
suites.each do |suite|
cmd = %w!bundle exec ruby -w bin/itamae docker!
cmd << "-l" << (ENV['LOG_LEVEL'] || 'debug')
cmd << "-j" << "spec/integration/recipes/node.json"
cmd << "--container" << container_name
cmd << "--tag" << "itamae:latest"
cmd << "--tmp-dir" << (ENV['ITAMAE_TMP_DIR'] || '/tmp/itamae_tmp')
cmd += suite
p cmd
unless system(*cmd)
raise "#{cmd} failed"
end
end
end
desc "Run serverspec tests"
RSpec::Core::RakeTask.new(:serverspec) do |t|
ENV['DOCKER_CONTAINER'] = container_name
t.ruby_opts = '-I ./spec/integration'
t.pattern = "spec/integration/{default,docker}_spec.rb"
end
desc 'Clean a docker container for test'
task :clean_docker_container do
sh('docker', 'rm', '-f', container_name)
end
end
end
end
task :default => :spec