Merge pull request #14 from haus/ticket/12094_add_spec_tests
Ticket/12094 add spec tests
This commit is contained in:
commit
0d32fee292
15 changed files with 388 additions and 21 deletions
|
@ -7,7 +7,7 @@ class apt::debian::unstable {
|
|||
# Key: 55BE302B Server: subkeys.pgp.net
|
||||
# debian-keyring
|
||||
# debian-archive-keyring
|
||||
|
||||
|
||||
apt::source { "debian_unstable":
|
||||
location => "http://debian.mirror.iweb.ca/debian/",
|
||||
release => "unstable",
|
||||
|
|
|
@ -29,7 +29,7 @@ class apt(
|
|||
package { "python-software-properties": }
|
||||
|
||||
file { "sources.list":
|
||||
name => "${apt::params::root}/sources.list",
|
||||
path => "${apt::params::root}/sources.list",
|
||||
ensure => present,
|
||||
owner => root,
|
||||
group => root,
|
||||
|
@ -37,7 +37,7 @@ class apt(
|
|||
}
|
||||
|
||||
file { "sources.list.d":
|
||||
name => "${apt::params::root}/sources.list.d",
|
||||
path => "${apt::params::root}/sources.list.d",
|
||||
ensure => directory,
|
||||
owner => root,
|
||||
group => root,
|
||||
|
|
|
@ -9,7 +9,7 @@ define apt::pin(
|
|||
include apt::params
|
||||
|
||||
file { "${name}.pref":
|
||||
name => "${apt::params::root}/preferences.d/${name}",
|
||||
path => "${apt::params::root}/preferences.d/${name}",
|
||||
ensure => file,
|
||||
owner => root,
|
||||
group => root,
|
||||
|
|
|
@ -17,7 +17,7 @@ define apt::source(
|
|||
|
||||
|
||||
file { "${name}.list":
|
||||
name => "${apt::params::root}/sources.list.d/${name}.list",
|
||||
path => "${apt::params::root}/sources.list.d/${name}.list",
|
||||
ensure => file,
|
||||
owner => root,
|
||||
group => root,
|
||||
|
@ -48,7 +48,7 @@ define apt::source(
|
|||
command => "/bin/echo '${key_content}' | /usr/bin/apt-key add -",
|
||||
unless => "/usr/bin/apt-key list | /bin/grep '${key}'",
|
||||
before => File["${name}.list"],
|
||||
}
|
||||
}
|
||||
} else {
|
||||
exec { "/usr/bin/apt-key adv --keyserver ${key_server} --recv-keys ${key}":
|
||||
unless => "/usr/bin/apt-key list | /bin/grep ${key}",
|
||||
|
|
79
spec/classes/apt_spec.rb
Normal file
79
spec/classes/apt_spec.rb
Normal file
|
@ -0,0 +1,79 @@
|
|||
require 'spec_helper'
|
||||
describe 'apt', :type => :class do
|
||||
let :default_params do
|
||||
{
|
||||
:disable_keys => false,
|
||||
:always_apt_update => false
|
||||
}
|
||||
end
|
||||
|
||||
[{},
|
||||
{
|
||||
:disable_keys => true,
|
||||
:always_apt_update => true
|
||||
}
|
||||
].each do |param_set|
|
||||
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
|
||||
let :param_hash do
|
||||
default_params.merge(param_set)
|
||||
end
|
||||
|
||||
let :params do
|
||||
param_set
|
||||
end
|
||||
|
||||
let :refresh_only_apt_update do
|
||||
if param_hash[:always_apt_update]
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
it { should include_class("apt::params") }
|
||||
|
||||
it { should contain_package("python-software-properties") }
|
||||
|
||||
it {
|
||||
should contain_file("sources.list").with({
|
||||
'path' => "/etc/apt/sources.list",
|
||||
'ensure' => "present",
|
||||
'owner' => "root",
|
||||
'group' => "root",
|
||||
'mode' => 644
|
||||
})
|
||||
}
|
||||
|
||||
it {
|
||||
should create_file("sources.list.d").with({
|
||||
"path" => "/etc/apt/sources.list.d",
|
||||
"ensure" => "directory",
|
||||
"owner" => "root",
|
||||
"group" => "root"
|
||||
})
|
||||
}
|
||||
|
||||
it {
|
||||
should contain_exec("apt_update").with({
|
||||
'command' => "/usr/bin/apt-get update",
|
||||
'subscribe' => ["File[sources.list]", "File[sources.list.d]"],
|
||||
'refreshonly' => refresh_only_apt_update
|
||||
})
|
||||
}
|
||||
|
||||
it {
|
||||
if param_hash[:disable_keys]
|
||||
should contain_exec("make-apt-insecure").with({
|
||||
'command' => '/bin/echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth',
|
||||
'creates' => '/etc/apt/apt.conf.d/99unauth'
|
||||
})
|
||||
else
|
||||
should_not contain_exec("make-apt-insecure").with({
|
||||
'command' => '/bin/echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth',
|
||||
'creates' => '/etc/apt/apt.conf.d/99unauth'
|
||||
})
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
14
spec/classes/debian_testing_spec.rb
Normal file
14
spec/classes/debian_testing_spec.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require 'spec_helper'
|
||||
describe 'apt::debian::testing', :type => :class do
|
||||
it {
|
||||
should contain_apt__source("debian_testing").with({
|
||||
"location" => "http://debian.mirror.iweb.ca/debian/",
|
||||
"release" => "testing",
|
||||
"repos" => "main contrib non-free",
|
||||
"required_packages" => "debian-keyring debian-archive-keyring",
|
||||
"key" => "55BE302B",
|
||||
"key_server" => "subkeys.pgp.net",
|
||||
"pin" => "-10"
|
||||
})
|
||||
}
|
||||
end
|
14
spec/classes/debian_unstable_spec.rb
Normal file
14
spec/classes/debian_unstable_spec.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require 'spec_helper'
|
||||
describe 'apt::debian::unstable', :type => :class do
|
||||
it {
|
||||
should contain_apt__source("debian_unstable").with({
|
||||
"location" => "http://debian.mirror.iweb.ca/debian/",
|
||||
"release" => "unstable",
|
||||
"repos" => "main contrib non-free",
|
||||
"required_packages" => "debian-keyring debian-archive-keyring",
|
||||
"key" => "55BE302B",
|
||||
"key_server" => "subkeys.pgp.net",
|
||||
"pin" => "-10"
|
||||
})
|
||||
}
|
||||
end
|
13
spec/classes/params_spec.rb
Normal file
13
spec/classes/params_spec.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
require 'spec_helper'
|
||||
describe 'apt::params', :type => :class do
|
||||
let (:title) { 'my_package' }
|
||||
|
||||
it { should contain_apt__params }
|
||||
|
||||
# There are 4 resources in this class currently
|
||||
# there should not be any more resources because it is a params class
|
||||
# The resources are class[apt::params], class[main], class[settings], stage[main]
|
||||
it "Should not contain any resources" do
|
||||
subject.resources.size.should == 4
|
||||
end
|
||||
end
|
22
spec/classes/release_spec.rb
Normal file
22
spec/classes/release_spec.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'spec_helper'
|
||||
describe 'apt::release', :type => :class do
|
||||
let (:title) { 'my_package' }
|
||||
|
||||
let :param_set do
|
||||
{ :release_id => 'precise' }
|
||||
end
|
||||
|
||||
let (:params) { param_set }
|
||||
|
||||
it { should include_class("apt::params") }
|
||||
|
||||
it {
|
||||
should contain_file("/etc/apt/apt.conf.d/01release").with({
|
||||
"owner" => "root",
|
||||
"group" => "root",
|
||||
"mode" => 644,
|
||||
"content" => "APT::Default-Release \"#{param_set[:release_id]}\";"
|
||||
})
|
||||
}
|
||||
end
|
||||
|
25
spec/defines/builddep_spec.rb
Normal file
25
spec/defines/builddep_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require 'spec_helper'
|
||||
describe 'apt::builddep', :type => :define do
|
||||
|
||||
let(:title) { 'my_package' }
|
||||
|
||||
describe "should succeed with a Class['apt']" do
|
||||
let(:pre_condition) { 'class {"apt": } ' }
|
||||
|
||||
it { should contain_exec("apt-update-#{title}").with({
|
||||
'command' => "/usr/bin/apt-get update",
|
||||
'refreshonly' => true
|
||||
})
|
||||
}
|
||||
end
|
||||
|
||||
describe "should fail without Class['apt']" do
|
||||
it { expect {should contain_exec("apt-update-#{title}").with({
|
||||
'command' => "/usr/bin/apt-get update",
|
||||
'refreshonly' => true
|
||||
}).to raise_error(Puppet::Error)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
end
|
|
@ -1,22 +1,39 @@
|
|||
require 'spec_helper'
|
||||
describe 'apt::force', :type => :define do
|
||||
|
||||
let :title do
|
||||
'my_package'
|
||||
end
|
||||
|
||||
[false, '1'].each do |version|
|
||||
describe "with version: #{version}" do
|
||||
let :params do
|
||||
{:version => version, :release => 'testing'}
|
||||
let :default_params do
|
||||
{
|
||||
:release => 'testing',
|
||||
:version => false
|
||||
}
|
||||
end
|
||||
|
||||
[{},
|
||||
{
|
||||
:release => 'stable',
|
||||
:version => '1'
|
||||
}
|
||||
].each do |param_set|
|
||||
describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
|
||||
let :param_hash do
|
||||
default_params.merge(param_set)
|
||||
end
|
||||
|
||||
let :params do
|
||||
param_set
|
||||
end
|
||||
|
||||
let :unless_query do
|
||||
base_command = "/usr/bin/dpkg -s #{title} | grep -q "
|
||||
base_command + (version ? "'Version: #{params[:version]}'" : "'Status: install'")
|
||||
base_command + (params[:version] ? "'Version: #{params[:version]}'" : "'Status: install'")
|
||||
end
|
||||
|
||||
let :exec_title do
|
||||
base_exec = "/usr/bin/aptitude -y -t #{params[:release]} install #{title}"
|
||||
base_exec + (version ? "=#{version}" : "")
|
||||
base_exec = "/usr/bin/aptitude -y -t #{param_hash[:release]} install #{title}"
|
||||
base_exec + (params[:version] ? "=#{params[:version]}" : "")
|
||||
end
|
||||
it { should contain_exec(exec_title).with_unless(unless_query) }
|
||||
end
|
||||
|
|
40
spec/defines/pin_spec.rb
Normal file
40
spec/defines/pin_spec.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
require 'spec_helper'
|
||||
describe 'apt::pin', :type => :define do
|
||||
let(:title) { 'my_pin' }
|
||||
|
||||
let :default_params do
|
||||
{
|
||||
:packages => '*',
|
||||
:priority => '0'
|
||||
}
|
||||
end
|
||||
|
||||
[{},
|
||||
{
|
||||
:packages => 'apache',
|
||||
:priority => '1'
|
||||
}
|
||||
].each do |param_set|
|
||||
describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
|
||||
let :param_hash do
|
||||
default_params.merge(param_set)
|
||||
end
|
||||
|
||||
let :params do
|
||||
param_set
|
||||
end
|
||||
|
||||
it { should include_class("apt::params") }
|
||||
|
||||
it { should contain_file("#{title}.pref").with({
|
||||
'path' => "/etc/apt/preferences.d/#{title}",
|
||||
'ensure' => "file",
|
||||
'owner' => "root",
|
||||
'group' => "root",
|
||||
'mode' => "644",
|
||||
'content' => "# #{title}\nPackage: #{param_hash[:packages]}\nPin: release a=#{title}\nPin-Priority: #{param_hash[:priority]}"
|
||||
})
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -20,7 +20,7 @@ describe 'apt::ppa', :type => :define do
|
|||
'notify' => "Exec[apt-update-#{t}]"
|
||||
)
|
||||
}
|
||||
it { should contain_exec("add-apt-repository-#{t}").with_unless(unless_statement) }
|
||||
it { should contain_exec("add-apt-repository-#{t}").with({"unless" => unless_statement}) }
|
||||
it { should contain_exec("apt-update-#{t}").with(
|
||||
'command' => '/usr/bin/aptitude update',
|
||||
'refreshonly' => true
|
||||
|
@ -29,4 +29,9 @@ describe 'apt::ppa', :type => :define do
|
|||
it { should contain_exec("apt-update-#{t}").without_unless }
|
||||
end
|
||||
end
|
||||
|
||||
describe "without Class[apt] should raise a Puppet::Error" do
|
||||
let(:title) { "ppa" }
|
||||
it { expect { should contain_apt__ppa(title) }.to raise_error(Puppet::Error) }
|
||||
end
|
||||
end
|
||||
|
|
144
spec/defines/source_spec.rb
Normal file
144
spec/defines/source_spec.rb
Normal file
|
@ -0,0 +1,144 @@
|
|||
require 'spec_helper'
|
||||
describe 'apt::source', :type => :define do
|
||||
let :title do
|
||||
'my_source'
|
||||
end
|
||||
|
||||
let :default_params do
|
||||
{
|
||||
:location => '',
|
||||
:release => 'karmic',
|
||||
:repos => 'main',
|
||||
:include_src => true,
|
||||
:required_packages => false,
|
||||
:key => false,
|
||||
:key_server => 'keyserver.ubuntu.com',
|
||||
:pin => false,
|
||||
:key_content => false
|
||||
}
|
||||
end
|
||||
|
||||
[{},
|
||||
{
|
||||
:location => 'somewhere',
|
||||
:release => 'precise',
|
||||
:repos => 'security',
|
||||
:include_src => false,
|
||||
:required_packages => 'apache',
|
||||
:key => 'key_name',
|
||||
:key_server => 'keyserver.debian.com',
|
||||
:pin => '600',
|
||||
:key_content => 'ABCD1234'
|
||||
}
|
||||
].each do |param_set|
|
||||
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
|
||||
let :param_hash do
|
||||
default_params.merge(param_set)
|
||||
end
|
||||
|
||||
let :params do
|
||||
param_set
|
||||
end
|
||||
|
||||
let :filename do
|
||||
"/etc/apt/sources.list.d/#{title}.list"
|
||||
end
|
||||
|
||||
let :content do
|
||||
content = "# #{title}"
|
||||
content << "\ndeb #{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
|
||||
if param_hash[:include_src]
|
||||
content << "deb-src #{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
|
||||
end
|
||||
content
|
||||
end
|
||||
|
||||
it { should contain_apt__params }
|
||||
|
||||
it { should contain_file("#{title}.list").with({
|
||||
'path' => filename,
|
||||
'ensure' => "file",
|
||||
'owner' => "root",
|
||||
'group' => "root",
|
||||
'mode' => 644,
|
||||
'content' => content
|
||||
})
|
||||
}
|
||||
|
||||
it {
|
||||
if param_hash[:pin]
|
||||
should contain_apt__pin(param_hash[:release]).with({
|
||||
"priority" => param_hash[:pin],
|
||||
"before" => "File[#{title}.list]"
|
||||
})
|
||||
else
|
||||
should_not contain_apt__pin(param_hash[:release]).with({
|
||||
"priority" => param_hash[:pin],
|
||||
"before" => "File[#{title}.list]"
|
||||
})
|
||||
end
|
||||
}
|
||||
|
||||
it {
|
||||
should contain_exec("#{title} apt update").with({
|
||||
"command" => "/usr/bin/apt-get update",
|
||||
"subscribe" => "File[#{title}.list]",
|
||||
"refreshonly" => true
|
||||
})
|
||||
}
|
||||
|
||||
it {
|
||||
if param_hash[:required_packages]
|
||||
should contain_exec("/usr/bin/apt-get -y install #{param_hash[:required_packages]}").with({
|
||||
"subscribe" => "File[#{title}.list]",
|
||||
"refreshonly" => true
|
||||
})
|
||||
else
|
||||
should_not contain_exec("/usr/bin/apt-get -y install #{param_hash[:required_packages]}").with({
|
||||
"subscribe" => "File[#{title}.list]",
|
||||
"refreshonly" => true
|
||||
})
|
||||
end
|
||||
}
|
||||
|
||||
it {
|
||||
if param_hash[:key]
|
||||
if param_hash[:key_content]
|
||||
should contain_exec("Add key: #{param_hash[:key]} from content").with({
|
||||
"command" => "/bin/echo '#{param_hash[:key_content]}' | /usr/bin/apt-key add -",
|
||||
"unless" => "/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'",
|
||||
"before" => "File[#{title}.list]"
|
||||
})
|
||||
should_not contain_exec("/usr/bin/apt-key adv --keyserver #{param_hash[:key_server]} --recv-keys #{param_hash[:key]}").with({
|
||||
"unless" => "/usr/bin/apt-key list | /bin/grep #{param_hash[:key]}",
|
||||
"before" => "File[#{title}.list]"
|
||||
})
|
||||
|
||||
else
|
||||
should contain_exec("/usr/bin/apt-key adv --keyserver #{param_hash[:key_server]} --recv-keys #{param_hash[:key]}").with({
|
||||
"unless" => "/usr/bin/apt-key list | /bin/grep #{param_hash[:key]}",
|
||||
"before" => "File[#{title}.list]"
|
||||
})
|
||||
should_not contain_exec("Add key: #{param_hash[:key]} from content").with({
|
||||
"command" => "/bin/echo '#{param_hash[:key_content]}' | /usr/bin/apt-key add -",
|
||||
"unless" => "/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'",
|
||||
"before" => "File[#{title}.list]"
|
||||
})
|
||||
end
|
||||
else
|
||||
should_not contain_exec("Add key: #{param_hash[:key]} from content").with({
|
||||
"command" => "/bin/echo '#{param_hash[:key_content]}' | /usr/bin/apt-key add -",
|
||||
"unless" => "/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'",
|
||||
"before" => "File[#{title}.list]"
|
||||
})
|
||||
should_not contain_exec("/usr/bin/apt-key adv --keyserver #{param_hash[:key_server]} --recv-keys #{param_hash[:key]}").with({
|
||||
"unless" => "/usr/bin/apt-key list | /bin/grep #{param_hash[:key]}",
|
||||
"before" => "File[#{title}.list]"
|
||||
})
|
||||
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
--format
|
||||
s
|
||||
--colour
|
||||
--loadby
|
||||
mtime
|
||||
--backtrace
|
Loading…
Reference in a new issue