From ee047f6593bbe412d72376b52b4361199b16722b Mon Sep 17 00:00:00 2001 From: Philip Cohoe Date: Fri, 13 Sep 2013 23:39:09 +0000 Subject: [PATCH] Added spec test for unattended-upgrades class --- spec/classes/unattended-upgrades_spec.rb | 179 +++++++++++++++++++++++ templates/50unattended-upgrades.erb | 6 +- 2 files changed, 182 insertions(+), 3 deletions(-) create mode 100644 spec/classes/unattended-upgrades_spec.rb diff --git a/spec/classes/unattended-upgrades_spec.rb b/spec/classes/unattended-upgrades_spec.rb new file mode 100644 index 0000000..98245ca --- /dev/null +++ b/spec/classes/unattended-upgrades_spec.rb @@ -0,0 +1,179 @@ +require 'spec_helper' +describe 'apt::unattended-upgrades', :type => :class do + + it { should contain_package("unattended-upgrades") } + + it { + should create_file("/etc/apt/apt.conf.d/50unattended-upgrades").with({ + "owner" => "root", + "group" => "root", + "mode" => "0644", + }) + } + + it { + should create_file("/etc/apt/apt.conf.d/10periodic").with({ + "owner" => "root", + "group" => "root", + "mode" => "0644", + }) + } + + describe "with origins => ['ubuntu:precise-security']" do + let :params do + { :origins => ['ubuntu:precise-security'] } + end + it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::Allowed-Origins \{\n\t"ubuntu:precise-security";\n\};$/) } + end + + describe "with blacklist => []" do + let :params do + { :blacklist => [] } + end + it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\};$/) } + end + + describe "with update => 2" do + let :params do + { :update => "2" } + end + it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::Update-Package-Lists "2";$/) } + end + + describe "with download => 2" do + let :params do + { :download => "2" } + end + it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::Download-Upgradeable-Packages "2";$/) } + end + + describe "with upgrade => 2" do + let :params do + { :upgrade => "2" } + end + it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::Unattended-Upgrade "2";$/) } + end + + describe "with autoclean => 2" do + let :params do + { :autoclean => "2" } + end + it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::AutocleanInterval "2";$/) } + end + + describe "with auto_fix => false" do + let :params do + { :auto_fix => "false" } + end + it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::AutoFixInterruptedDpkg "false";$/) } + end + + describe "with minimal_steps => true" do + let :params do + { :minimal_steps => "true" } + end + it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::MinimalSteps "true";$/) } + end + + describe "with install_on_shutdown => true" do + let :params do + { :install_on_shutdown => "true" } + end + it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::InstallOnShutdown "true";$/) } + end + + describe "with mail_to => NONE" do + let :params do + { :mail_to => "NONE" } + end + it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^\/\/ 'mailx' must be installed.\n$/) } + it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^\/\/ is to always send a mail if Unattended-Upgrade::Mail is set\n$/) } + end + + describe "with mail_to => user@website, mail_only_on_error => true" do + let :params do + { :mail_to => "user@website", + :mail_only_on_error => "true" } + end + it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::Mail "user@website";$/) } + it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::MailOnlyOnError "true";$/) } + end + + describe "with remove_unused => false" do + let :params do + { :remove_unused => "false" } + end + it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::Remove-Unused-Dependencies "false";$/) } + end + + describe "with auto_reboot => true" do + let :params do + { :auto_reboot => "true" } + end + it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::Automatic-Reboot "true";$/) } + end + + describe "with dl_limit => 70" do + let :params do + { :dl_limit => "70" } + end + it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Acquire::http::Dl-Limit "70";$/) } + end + + describe "with enable => 0" do + let :params do + { :enable => "0" } + end + it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::Enable "0";$/) } + end + + describe "with backup_interval => 1" do + let :params do + { :backup_interval => "1" } + end + it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::BackUpArchiveInterval "1";$/) } + end + + describe "with backup_level => 0" do + let :params do + { :backup_level => "0" } + end + it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::BackUpLevel "0";$/) } + end + + describe "with max_age => 1" do + let :params do + { :max_age => "1" } + end + it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::MaxAge "1";$/) } + end + + describe "with min_age => 1" do + let :params do + { :min_age => "1" } + end + it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::MinAge "1";$/) } + end + + describe "with max_size => 1" do + let :params do + { :max_size => "1" } + end + it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::MaxSize "1";$/) } + end + + describe "with download_delta => 2" do + let :params do + { :download_delta => "2" } + end + it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";$/) } + end + + describe "with verbose => 2" do + let :params do + { :verbose => "2" } + end + it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::Verbose "2";$/) } + end + +end diff --git a/templates/50unattended-upgrades.erb b/templates/50unattended-upgrades.erb index b026fe9..4df0f74 100644 --- a/templates/50unattended-upgrades.erb +++ b/templates/50unattended-upgrades.erb @@ -33,11 +33,11 @@ Unattended-Upgrade::InstallOnShutdown "<%= @install_on_shutdown %>"; // If empty or unset then no email is sent, make sure that you // have a working mail setup on your system. A package that provides // 'mailx' must be installed. -<% if @mail_to != "NONE" %> Unattended-Upgrade::Mail "<%= @mail_to %>"; <% end %> +<% if @mail_to != "NONE" %>Unattended-Upgrade::Mail "<%= @mail_to %>";<% end %> // Set this value to "true" to get emails only on errors. Default // is to always send a mail if Unattended-Upgrade::Mail is set -<% if @mail_to != "NONE" %> Unattended-Upgrade::MailOnlyOnError "<%= @mail_only_on_error %>"; <% end %> +<% if @mail_to != "NONE" %>Unattended-Upgrade::MailOnlyOnError "<%= @mail_only_on_error %>";<% end %> // Do automatic removal of new unused dependencies after the upgrade // (equivalent to apt-get autoremove) @@ -50,4 +50,4 @@ Unattended-Upgrade::Automatic-Reboot "<%= @auto_reboot %>"; // Use apt bandwidth limit feature, this example limits the download // speed to 70kb/sec -<% if @dl_limit != "NONE" %> Acquire::http::Dl-Limit "<%= @dl_limit %>"; <% end %> +<% if @dl_limit != "NONE" %>Acquire::http::Dl-Limit "<%= @dl_limit %>";<% end %> -- 2.32.3