summaryrefslogtreecommitdiff
path: root/features/steps/deploy_steps.rb
blob: 2a3906f5ad5c79734d9e4958712e17e1d09fe21d (plain)
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
81
82
83
84
require 'chef/shell_out'


# Given /^I have a clone of typo in the data\/tmp dir$/ do
#   cmd = "git clone #{datadir}/typo.bundle #{tmpdir}/gitrepo/typo"
#   `#{cmd}`
# end
def gem_installed?(gem_name, version)
  cmd = "gem list -i #{gem_name} -v #{version}"
  `#{cmd}`=~ /true/ ? true : false
end


Given /^I have a clone of the rails app in the data\/tmp dir$/ do
  cmd = "git clone #{datadir}/myapp.bundle #{tmpdir}/gitrepo/myapp"
  `#{cmd}`
end

Given /^that I have '(.*)' '(.*)' installed$/ do |gem_name, version|
  unless gem_installed?(gem_name, version)
    pending "This Cucumber feature will not execute, as #{gem_name} #{version} is not installed."
  end
end

Given /^a test git repo in the temp directory$/ do
  test_git_repo_tarball_filename = "#{datadir}/test_git_repo.tar.gz"
  cmd = Chef::ShellOut.new("tar xzvf #{test_git_repo_tarball_filename} -C #{tmpdir}")
  cmd.run_command.exitstatus.should == 0
end

Then /^I should hear about it$/ do
  puts "==deploy:"
  puts `ls #{tmpdir}/deploy/`
  puts "==Releases:"
  puts `ls #{tmpdir}/deploy/releases/`
  puts "==Releases/*/"
  puts `ls #{tmpdir}/deploy/releases/*/`
  puts "==Releases/*/db"
  puts `ls #{tmpdir}/deploy/releases/*/db/`
  puts "==Releases/*/config/"
  puts `ls #{tmpdir}/deploy/releases/*/config/`
  puts "==current:"
  puts `ls #{tmpdir}/deploy/current/`
  puts "==current/db:"
  puts `ls #{tmpdir}/deploy/current/db/`
  puts "==current/deploy:"
  puts `ls #{tmpdir}/deploy/current/deploy/`
  puts "==current/app:"
  puts `ls #{tmpdir}/deploy/current/app/`
  puts "==current/config:"
  puts `ls #{tmpdir}/deploy/current/config/`
  puts "==shared/config/app_config.yml"
  puts `ls #{tmpdir}/deploy/shared/config/`
end

Then /^there should be '(.*)' releases?$/ do |n|
  numnums = {"one" => 1, "two" => 2, "three" => 3}
  n = numnums.has_key?(n) ? numnums[n] : n.to_i
  @releases = Dir.glob(tmpdir + "/deploy/releases/*")
  @releases.size.should eql(n)
end

Then /^a callback named <callback_file> should exist$/ do |callback_files|
  callback_files.raw.each do |file|
    want_file = "deploy/current/deploy/#{file.first}"
    Then "a file named '#{want_file}' should exist"
  end
end

Then /^the callback named <callback> should have run$/ do |callback_files|
  callback_files.raw.each do |file|
    hook_name = file.first.gsub(/\.rb$/, "")
    evidence_file = "deploy/current/app/" + hook_name 
    expected_contents = {"hook_name" => hook_name, "env" => "production"}
    actual_contents = JSON.parse(IO.read(File.join(tmpdir, evidence_file)))
    expected_contents.should == actual_contents
  end
end

Then /^the second chef run should have skipped deployment$/ do
  expected_deploy = "#{tmpdir}/deploy/releases/62c9979f6694612d9659259f8a68d71048ae9a5b"
  Then "'stdout' should not have 'INFO: Already deployed app at #{expected_deploy}.  Rolling back to it - use action :force_deploy to re-checkout this revision.'"
end