Debian Codegraph @

Rakefile

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