summaryrefslogtreecommitdiff
path: root/features/steps/packages.rb
blob: 2d349f0894df2217a692ce716c01619b4b7489d7 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
def debian_compatible?
  (ohai[:platform] == 'debian') || (ohai[:platform] == "ubuntu")
end

def chef_test_dpkg_installed?
  shell_out("dpkg -l chef-integration-test").status.success?
end

def purge_chef_integration_debs
  if debian_compatible? && chef_test_dpkg_installed?
    shell_out!("dpkg -r chef-integration-test")
    shell_out("dpkg --clear-avail")
  end
end

Given /^I have configured my apt sources for integration tests$/ do
  File.open("/etc/apt/sources.list.d/chef-integration-test.list", "w+") do |f|
    f.puts "deb http://localhost:9000/ sid main"
  end
end

def remove_integration_test_apt_source
  FileUtils.rm("/etc/apt/sources.list.d/chef-integration-test.list")  
rescue Errno::ENOENT
  Chef::Log.info("Attempted to remove integration test from /etc/apt/sources.list.d but it didn't exist")
end

After("@apt") do
  remove_integration_test_apt_source
end

Before('@dpkg,@apt') do
  purge_chef_integration_debs
end

After('@dpkg,@apt') do
  purge_chef_integration_debs
end

Given "I am running on a debian compatible OS" do
  unless debian_compatible?
    pending("This test can only run on debian or ubuntu, but you have #{ohai[:platform]}")
  end
end

Given "my dpkg architecture is 'amd64'" do
  unless `dpkg --print-architecture`.strip == "amd64"
    pending("This scenario can only run on an amd64 system")
  end
end

Given "the deb package '$pkg_name' is available" do |pkg_name|
  source = File.expand_path(File.dirname(__FILE__) + "/../data/apt/#{pkg_name}-1_amd64.deb")
  dest = File.join(tmpdir, File.basename(source))
  FileUtils.cp(source, dest)
end

Given "the apt server is running" do
  self.apt_server_thread = Thread.new do
    trap("INT") do
      apt_server.shutdown
      apt_server_thread.join
    end
    
    apt_server.start
  end
end

Given "I have updated my apt cache" do
  shell_out!("apt-get update")
end

Given /^the gems server is running$/ do
  self.gemserver_thread = Thread.new do
    trap("INT") do 
      gemserver.shutdown
      gemserver_thread.join
    end
    
    gemserver.start
  end
end

Given /^that I have the (.+) package system installed$/ do |package_system|
  unless package_system_available?(package_system)
    pending "This Cucumber feature will not execute, as it is missing the #{package_system} packaging system."
  end
end

Then /^there should be a binary on the path called '(.+)'$/ do |binary_name|
  binary_name.strip!
  result = `which #{binary_name}`
  result.should_not =~ /not found/
end

Then /^there should not be a binary on the path called '(.+)'$/ do |binary_name|
  binary_name.strip!
  result = `which #{binary_name}`.strip

  unless result.empty?
    result.should =~ /not found/
  end
end

Then /^the gem '(.+)' version '(.+)' should be installed$/ do |gem_name, version|
  Then "a file named 'installed-gems/gems/#{gem_name}-#{version}' should exist"
end

Then "the gem '$gem_name' version '$version' should not be installed" do |gem_name, version|
  Then "a file named 'installed-gems/gems/#{gem_name}-#{version}' should not exist"
end


def dpkg_should_be_installed(pkg_name)
  shell_out!("dpkg -l #{pkg_name}")
end

Then "the dpkg package '$package_name' should be installed" do |package_name|
  dpkg_should_be_installed(package_name)
end