diff options
author | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2018-09-16 22:55:58 +0200 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2018-09-16 22:55:58 +0200 |
commit | 9513b93a992470e21e387db1451fa4fd21ffc5d6 (patch) | |
tree | 24b584e9a66ce00f053748ab938eecc8d91110ab /code/environments/production/modules/apt/spec/unit | |
parent | b9c90f087cb54a0b8be222dbdcd88c8a73ef4f57 (diff) | |
download | puppet.DEV-9513b93a992470e21e387db1451fa4fd21ffc5d6.tar.gz puppet.DEV-9513b93a992470e21e387db1451fa4fd21ffc5d6.tar.bz2 puppet.DEV-9513b93a992470e21e387db1451fa4fd21ffc5d6.zip |
modules/apt: Ship puppetlabs-apt module v4.5.1.
Diffstat (limited to 'code/environments/production/modules/apt/spec/unit')
13 files changed, 689 insertions, 0 deletions
diff --git a/code/environments/production/modules/apt/spec/unit/facter/apt_dist_has_updates_spec.rb b/code/environments/production/modules/apt/spec/unit/facter/apt_dist_has_updates_spec.rb new file mode 100644 index 0000000..ae67bcf --- /dev/null +++ b/code/environments/production/modules/apt/spec/unit/facter/apt_dist_has_updates_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'apt_has_dist_updates fact' do + subject { Facter.fact(:apt_has_dist_updates).value } + + after(:each) { Facter.clear } + + describe 'on non-Debian distro' do + before(:each) do + Facter.fact(:osfamily).expects(:value).at_least(1).returns 'RedHat' + end + it { is_expected.to be_nil } + end + + describe 'on Debian based distro missing apt-get' do + before(:each) do + Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' + File.stubs(:executable?) # Stub all other calls + File.expects(:executable?).with('/usr/bin/apt-get').returns false + end + it { is_expected.to be_nil } + end + + describe 'on Debian based distro' do + before(:each) do + Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' + File.stubs(:executable?) # Stub all other calls + Facter::Util::Resolution.stubs(:exec) # Catch all other calls + File.expects(:executable?).with('/usr/bin/apt-get').returns true + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns 'test' + File.expects(:executable?).with('/usr/bin/apt-get').returns true + apt_output = "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ + "Conf planet.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').returns apt_output + end + it { is_expected.to be true } + end +end diff --git a/code/environments/production/modules/apt/spec/unit/facter/apt_dist_package_security_updates_spec.rb b/code/environments/production/modules/apt/spec/unit/facter/apt_dist_package_security_updates_spec.rb new file mode 100644 index 0000000..7f4f16a --- /dev/null +++ b/code/environments/production/modules/apt/spec/unit/facter/apt_dist_package_security_updates_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' + +describe 'apt_package_security_dist_updates fact' do + subject { Facter.fact(:apt_package_security_dist_updates).value } + + after(:each) { Facter.clear } + + describe 'when apt has no updates' do + before(:each) do + Facter.fact(:apt_has_dist_updates).stubs(:value).returns false + end + it { is_expected.to be nil } + end + + describe 'when apt has updates' do + before(:each) do + Facter.fact(:osfamily).stubs(:value).returns 'Debian' + File.stubs(:executable?) # Stub all other calls + Facter::Util::Resolution.stubs(:exec) # Catch all other calls + File.expects(:executable?).with('/usr/bin/apt-get').returns true + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns 'test' + File.expects(:executable?).with('/usr/bin/apt-get').returns true + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').returns apt_get_upgrade_output + end + + describe 'on Debian' do + let(:apt_get_upgrade_output) do + "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ + "Conf planet.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ + "Inst vim [7.52.1-5] (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64]) []\n" \ + "Conf vim (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64])\n" \ + end + + if Facter.version < '2.0.0' + it { is_expected.to eq('vim') } + else + it { is_expected.to eq(['vim']) } + end + end + + describe 'on Ubuntu' do + let(:apt_get_upgrade_output) do + "Inst extremetuxracer [2016f-0ubuntu0.16.04] (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ + "Conf extremetuxracer (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ + "Inst vim [7.47.0-1ubuntu2] (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64]) []\n" \ + "Conf vim (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64])\n" \ + "Inst onioncircuits [2:3.3.10-4ubuntu2] (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" \ + "Conf onioncircuits (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" + end + + if Facter.version < '2.0.0' + it { is_expected.to eq('extremetuxracer,vim') } + else + it { is_expected.to eq(%w[extremetuxracer vim]) } + end + end + end +end diff --git a/code/environments/production/modules/apt/spec/unit/facter/apt_dist_package_updates_spec.rb b/code/environments/production/modules/apt/spec/unit/facter/apt_dist_package_updates_spec.rb new file mode 100644 index 0000000..080e21f --- /dev/null +++ b/code/environments/production/modules/apt/spec/unit/facter/apt_dist_package_updates_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe 'apt_package_dist_updates fact' do + subject { Facter.fact(:apt_package_dist_updates).value } + + after(:each) { Facter.clear } + + describe 'when apt has no updates' do + before(:each) do + Facter.fact(:apt_has_dist_updates).stubs(:value).returns false + end + it { is_expected.to be nil } + end + + describe 'when apt has updates' do + before(:each) do + Facter.fact(:osfamily).stubs(:value).returns 'Debian' + File.stubs(:executable?) # Stub all other calls + Facter::Util::Resolution.stubs(:exec) # Catch all other calls + File.expects(:executable?).with('/usr/bin/apt-get').returns true + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns 'test' + File.expects(:executable?).with('/usr/bin/apt-get').returns true + apt_output = "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ + "Conf planet.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').returns apt_output + end + if Facter.version < '2.0.0' + it { is_expected.to eq('extremetuxracer,planet.rb') } + else + it { is_expected.to eq(['extremetuxracer', 'planet.rb']) } + end + end +end diff --git a/code/environments/production/modules/apt/spec/unit/facter/apt_dist_security_updates_spec.rb b/code/environments/production/modules/apt/spec/unit/facter/apt_dist_security_updates_spec.rb new file mode 100644 index 0000000..9b58b6e --- /dev/null +++ b/code/environments/production/modules/apt/spec/unit/facter/apt_dist_security_updates_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +describe 'apt_security_updates fact' do + subject { Facter.fact(:apt_security_dist_updates).value } + + after(:each) { Facter.clear } + + describe 'when apt has no updates' do + before(:each) do + Facter.fact(:apt_has_dist_updates).stubs(:value).returns false + end + it { is_expected.to be nil } + end + + describe 'when apt has security updates' do + before(:each) do + Facter.fact(:osfamily).stubs(:value).returns 'Debian' + File.stubs(:executable?) # Stub all other calls + Facter::Util::Resolution.stubs(:exec) # Catch all other calls + File.expects(:executable?).with('/usr/bin/apt-get').returns true + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns 'test' + File.expects(:executable?).with('/usr/bin/apt-get').returns true + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').returns apt_get_upgrade_output + end + + describe 'on Debian' do + let(:apt_get_upgrade_output) do + "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ + "Conf planet.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ + "Inst vim [7.52.1-5] (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64]) []\n" \ + "Conf vim (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64])\n" \ + end + + it { is_expected.to eq(1) } + end + + describe 'on Ubuntu' do + let(:apt_get_upgrade_output) do + "Inst extremetuxracer [2016f-0ubuntu0.16.04] (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ + "Conf extremetuxracer (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ + "Inst vim [7.47.0-1ubuntu2] (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64]) []\n" \ + "Conf vim (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64])\n" \ + "Inst onioncircuits [2:3.3.10-4ubuntu2] (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" \ + "Conf onioncircuits (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" + end + + it { is_expected.to eq(2) } + end + end +end diff --git a/code/environments/production/modules/apt/spec/unit/facter/apt_dist_updates_spec.rb b/code/environments/production/modules/apt/spec/unit/facter/apt_dist_updates_spec.rb new file mode 100644 index 0000000..737d1b6 --- /dev/null +++ b/code/environments/production/modules/apt/spec/unit/facter/apt_dist_updates_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe 'apt_updates fact' do + subject { Facter.fact(:apt_dist_updates).value } + + after(:each) { Facter.clear } + + describe 'when apt has no updates' do + before(:each) do + Facter.fact(:apt_has_dist_updates).stubs(:value).returns false + end + it { is_expected.to be nil } + end + + describe 'when apt has updates' do + before(:each) do + Facter.fact(:osfamily).stubs(:value).returns 'Debian' + File.stubs(:executable?) # Stub all other calls + Facter::Util::Resolution.stubs(:exec) # Catch all other calls + File.expects(:executable?).with('/usr/bin/apt-get').returns true + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns 'test' + File.expects(:executable?).with('/usr/bin/apt-get').returns true + apt_output = "Inst extremetuxracer [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Conf extremetuxracer (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Inst planet.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ + "Conf planet.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true dist-upgrade 2>&1').returns apt_output + end + it { is_expected.to eq(2) } + end +end diff --git a/code/environments/production/modules/apt/spec/unit/facter/apt_has_updates_spec.rb b/code/environments/production/modules/apt/spec/unit/facter/apt_has_updates_spec.rb new file mode 100644 index 0000000..5c06c2f --- /dev/null +++ b/code/environments/production/modules/apt/spec/unit/facter/apt_has_updates_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe 'apt_has_updates fact' do + subject { Facter.fact(:apt_has_updates).value } + + after(:each) { Facter.clear } + + describe 'on non-Debian distro' do + before(:each) do + Facter.fact(:osfamily).expects(:value).at_least(1).returns 'RedHat' + end + it { is_expected.to be_nil } + end + + describe 'on Debian based distro missing apt-get' do + before(:each) do + Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' + File.stubs(:executable?) # Stub all other calls + File.expects(:executable?).with('/usr/bin/apt-get').returns false + end + it { is_expected.to be_nil } + end + + describe 'on Debian based distro' do + before(:each) do + Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' + File.stubs(:executable?) # Stub all other calls + Facter::Util::Resolution.stubs(:exec) # Catch all other calls + File.expects(:executable?).with('/usr/bin/apt-get').returns true + apt_output = "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ + "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_output + end + it { is_expected.to be true } + end +end diff --git a/code/environments/production/modules/apt/spec/unit/facter/apt_package_security_updates_spec.rb b/code/environments/production/modules/apt/spec/unit/facter/apt_package_security_updates_spec.rb new file mode 100644 index 0000000..1cd992d --- /dev/null +++ b/code/environments/production/modules/apt/spec/unit/facter/apt_package_security_updates_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' + +describe 'apt_package_security_updates fact' do + subject { Facter.fact(:apt_package_security_updates).value } + + after(:each) { Facter.clear } + + describe 'when apt has no updates' do + before(:each) do + Facter.fact(:apt_has_updates).stubs(:value).returns false + end + it { is_expected.to be nil } + end + + describe 'when apt has updates' do + before(:each) do + Facter.fact(:osfamily).stubs(:value).returns 'Debian' + File.stubs(:executable?) # Stub all other calls + Facter::Util::Resolution.stubs(:exec) # Catch all other calls + File.expects(:executable?).with('/usr/bin/apt-get').returns true + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_get_upgrade_output + end + + describe 'on Debian' do + let(:apt_get_upgrade_output) do + "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ + "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ + "Inst curl [7.52.1-5] (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64]) []\n" \ + "Conf curl (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64])\n" \ + end + + if Facter.version < '2.0.0' + it { is_expected.to eq('curl') } + else + it { is_expected.to eq(['curl']) } + end + end + + describe 'on Ubuntu' do + let(:apt_get_upgrade_output) do + "Inst tzdata [2016f-0ubuntu0.16.04] (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ + "Conf tzdata (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ + "Inst curl [7.47.0-1ubuntu2] (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64]) []\n" \ + "Conf curl (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64])\n" \ + "Inst procps [2:3.3.10-4ubuntu2] (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" \ + "Conf procps (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" + end + + if Facter.version < '2.0.0' + it { is_expected.to eq('tzdata,curl') } + else + it { is_expected.to eq(%w[tzdata curl]) } + end + end + end +end diff --git a/code/environments/production/modules/apt/spec/unit/facter/apt_package_updates_spec.rb b/code/environments/production/modules/apt/spec/unit/facter/apt_package_updates_spec.rb new file mode 100644 index 0000000..f24481a --- /dev/null +++ b/code/environments/production/modules/apt/spec/unit/facter/apt_package_updates_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +describe 'apt_package_updates fact' do + subject { Facter.fact(:apt_package_updates).value } + + after(:each) { Facter.clear } + + describe 'when apt has no updates' do + before(:each) do + Facter.fact(:apt_has_updates).stubs(:value).returns false + end + it { is_expected.to be nil } + end + + describe 'when apt has updates' do + before(:each) do + Facter.fact(:osfamily).stubs(:value).returns 'Debian' + File.stubs(:executable?) # Stub all other calls + Facter::Util::Resolution.stubs(:exec) # Catch all other calls + File.expects(:executable?).with('/usr/bin/apt-get').returns true + apt_output = "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ + "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_output + end + if Facter.version < '2.0.0' + it { is_expected.to eq('tzdata,unhide.rb') } + else + it { is_expected.to eq(['tzdata', 'unhide.rb']) } + end + end +end diff --git a/code/environments/production/modules/apt/spec/unit/facter/apt_reboot_required_spec.rb b/code/environments/production/modules/apt/spec/unit/facter/apt_reboot_required_spec.rb new file mode 100644 index 0000000..356f36b --- /dev/null +++ b/code/environments/production/modules/apt/spec/unit/facter/apt_reboot_required_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe 'apt_reboot_required fact' do + subject { Facter.fact(:apt_reboot_required).value } + + after(:each) { Facter.clear } + + describe 'if a reboot is required' do + before(:each) do + Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' + File.stubs(:file?).returns true + File.expects(:file?).at_least(1).with('/var/run/reboot-required').returns true + end + it { is_expected.to eq true } + end + + describe 'if a reboot is not required' do + before(:each) do + Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian' + File.stubs(:file?).returns true + File.expects(:file?).at_least(1).with('/var/run/reboot-required').returns false + end + it { is_expected.to eq false } + end +end diff --git a/code/environments/production/modules/apt/spec/unit/facter/apt_security_updates_spec.rb b/code/environments/production/modules/apt/spec/unit/facter/apt_security_updates_spec.rb new file mode 100644 index 0000000..fc93552 --- /dev/null +++ b/code/environments/production/modules/apt/spec/unit/facter/apt_security_updates_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe 'apt_security_updates fact' do + subject { Facter.fact(:apt_security_updates).value } + + after(:each) { Facter.clear } + + describe 'when apt has no updates' do + before(:each) do + Facter.fact(:apt_has_updates).stubs(:value).returns false + end + it { is_expected.to be nil } + end + + describe 'when apt has security updates' do + before(:each) do + Facter.fact(:osfamily).stubs(:value).returns 'Debian' + File.stubs(:executable?) # Stub all other calls + Facter::Util::Resolution.stubs(:exec) # Catch all other calls + File.expects(:executable?).with('/usr/bin/apt-get').returns true + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_get_upgrade_output + end + + describe 'on Debian' do + let(:apt_get_upgrade_output) do + "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ + "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ + "Inst curl [7.52.1-5] (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64]) []\n" \ + "Conf curl (7.52.1-5+deb9u2 Debian-Security:9/stable [amd64])\n" \ + end + + it { is_expected.to eq(1) } + end + + describe 'on Ubuntu' do + let(:apt_get_upgrade_output) do + "Inst tzdata [2016f-0ubuntu0.16.04] (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ + "Conf tzdata (2016j-0ubuntu0.16.04 Ubuntu:16.04/xenial-security, Ubuntu:16.04/xenial-updates [all])\n" \ + "Inst curl [7.47.0-1ubuntu2] (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64]) []\n" \ + "Conf curl (7.47.0-1ubuntu2.2 Ubuntu:16.04/xenial-security [amd64])\n" \ + "Inst procps [2:3.3.10-4ubuntu2] (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" \ + "Conf procps (2:3.3.10-4ubuntu2.3 Ubuntu:16.04/xenial-updates [amd64])\n" + end + + it { is_expected.to eq(2) } + end + end +end diff --git a/code/environments/production/modules/apt/spec/unit/facter/apt_update_last_success_spec.rb b/code/environments/production/modules/apt/spec/unit/facter/apt_update_last_success_spec.rb new file mode 100644 index 0000000..60d7273 --- /dev/null +++ b/code/environments/production/modules/apt/spec/unit/facter/apt_update_last_success_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe 'apt_update_last_success fact' do + subject { Facter.fact(:apt_update_last_success).value } + + before(:each) { Facter.clear } + after(:each) { Facter.clear } + + describe 'on Debian based distro which has not yet created the update-success-stamp file' do + it 'has a value of -1' do + Facter.fact(:osfamily).stubs(:value).returns 'Debian' + File.expects(:exist?).with('/var/lib/apt/periodic/update-success-stamp').returns false + is_expected.to eq(-1) + end + end + + describe 'on Debian based distro which has created the update-success-stamp' do + it 'has the value of the mtime of the file' do + Facter.fact(:osfamily).stubs(:value).returns 'Debian' + File.stubs(:exist?).returns true + File.stubs(:mtime).returns 1_407_660_561 + is_expected.to eq(1_407_660_561) + end + end +end diff --git a/code/environments/production/modules/apt/spec/unit/facter/apt_updates_spec.rb b/code/environments/production/modules/apt/spec/unit/facter/apt_updates_spec.rb new file mode 100644 index 0000000..d0a5dbb --- /dev/null +++ b/code/environments/production/modules/apt/spec/unit/facter/apt_updates_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe 'apt_updates fact' do + subject { Facter.fact(:apt_updates).value } + + after(:each) { Facter.clear } + + describe 'when apt has no updates' do + before(:each) do + Facter.fact(:apt_has_updates).stubs(:value).returns false + end + it { is_expected.to be nil } + end + + describe 'when apt has updates' do + before(:each) do + Facter.fact(:osfamily).stubs(:value).returns 'Debian' + File.stubs(:executable?) # Stub all other calls + Facter::Util::Resolution.stubs(:exec) # Catch all other calls + File.expects(:executable?).with('/usr/bin/apt-get').returns true + apt_output = "Inst tzdata [2015f-0+deb8u1] (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Conf tzdata (2015g-0+deb8u1 Debian:stable-updates [all])\n" \ + "Inst unhide.rb [13-1.1] (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" \ + "Conf unhide.rb (22-2~bpo8+1 Debian Backports:jessie-backports [all])\n" + puts apt_output + Facter::Util::Resolution.expects(:exec).with('/usr/bin/apt-get -s -o Debug::NoLocking=true upgrade 2>&1').returns apt_output + end + it { is_expected.to eq(2) } + end +end diff --git a/code/environments/production/modules/apt/spec/unit/puppet/type/apt_key_spec.rb b/code/environments/production/modules/apt/spec/unit/puppet/type/apt_key_spec.rb new file mode 100644 index 0000000..a25d827 --- /dev/null +++ b/code/environments/production/modules/apt/spec/unit/puppet/type/apt_key_spec.rb @@ -0,0 +1,212 @@ +require 'spec_helper' +require 'puppet' + +describe Puppet::Type.type(:apt_key) do + context 'with only namevar 32bit key id' do + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + ) + end + + it 'id is set' do + expect(resource[:id]).to eq 'EF8D349F' + end + + it 'name is set to id' do + expect(resource[:name]).to eq 'EF8D349F' + end + + it 'keyserver is default' do + expect(resource[:server]).to eq :'keyserver.ubuntu.com' + end + + it 'source is not set' do + expect(resource[:source]).to eq nil + end + + it 'content is not set' do + expect(resource[:content]).to eq nil + end + end + + context 'with a lowercase 32bit key id' do + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'ef8d349f', + ) + end + + it 'id is set' do + expect(resource[:id]).to eq 'EF8D349F' + end + end + + context 'with a 64bit key id' do + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'FFFFFFFFEF8D349F', + ) + end + + it 'id is set' do + expect(resource[:id]).to eq 'FFFFFFFFEF8D349F' + end + end + + context 'with a 0x formatted key id' do + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: '0xEF8D349F', + ) + end + + it 'id is set' do + expect(resource[:id]).to eq 'EF8D349F' + end + end + + context 'with a 0x formatted lowercase key id' do + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: '0xef8d349f', + ) + end + + it 'id is set' do + expect(resource[:id]).to eq 'EF8D349F' + end + end + + context 'with a 0x formatted 64bit key id' do + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: '0xFFFFFFFFEF8D349F', + ) + end + + it 'id is set' do + expect(resource[:id]).to eq 'FFFFFFFFEF8D349F' + end + end + + context 'with source' do + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + ) + end + + it 'source is set to the URL' do + expect(resource[:source]).to eq 'http://apt.puppetlabs.com/pubkey.gpg' + end + end + + context 'with content' do + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + content: 'http://apt.puppetlabs.com/pubkey.gpg', + ) + end + + it 'content is set to the string' do + expect(resource[:content]).to eq 'http://apt.puppetlabs.com/pubkey.gpg' + end + end + + context 'with keyserver' do + let(:resource) do + Puppet::Type.type(:apt_key).new( + id: 'EF8D349F', + server: 'http://keyring.debian.org', + ) + end + + it 'keyserver is set to Debian' do + expect(resource[:server]).to eq 'http://keyring.debian.org' + end + end + + context 'with validation' do + it 'raises an error if content and source are set' do + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + content: 'Completely invalid as a GPG key') + }.to raise_error(%r{content and source are mutually exclusive}) + end + + it 'raises an error if a weird length key is used' do + expect { + Puppet::Type.type(:apt_key).new(id: 'FEF8D349F', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + content: 'Completely invalid as a GPG key') + }.to raise_error(%r{Valid values match}) + end + + it 'raises an error when an invalid URI scheme is used in source' do + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'hkp://pgp.mit.edu') + }.to raise_error(%r{Valid values match}) + end + + it 'allows the http URI scheme in source' do + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'http://pgp.mit.edu') + }.not_to raise_error + end + + it 'allows the http URI with username and password' do + expect { + Puppet::Type.type(:apt_key).new(id: '4BD6EC30', + source: 'http://testme:Password2@pgp.mit.edu') + }.not_to raise_error + end + + it 'allows the https URI scheme in source' do + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'https://pgp.mit.edu') + }.not_to raise_error + end + + it 'allows the https URI with username and password' do + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'https://testme:Password2@pgp.mit.edu') + }.not_to raise_error + end + + it 'allows the ftp URI scheme in source' do + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'ftp://pgp.mit.edu') + }.not_to raise_error + end + + it 'allows an absolute path in source' do + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: '/path/to/a/file') + }.not_to raise_error + end + + it 'allows 5-digit ports' do + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'http://pgp.mit.edu:12345/key') + }.not_to raise_error + end + + it 'allows 5-digit ports when using key servers' do + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + server: 'http://pgp.mit.edu:12345') + }.not_to raise_error + end + end +end |