aboutsummaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authorvarac <varacanero@zeromail.org>2015-12-07 00:22:50 +0100
committervarac <varacanero@zeromail.org>2015-12-07 13:29:41 +0100
commit6b27efb4346e61280f041b63dd8df7ad1f2e7f81 (patch)
treec7a636e41b703eb12ce2b4876a17819bd62b7388 /spec/unit
parentd372562329371c24df889d69ca4d476eda6497e9 (diff)
downloadpuppet-apt-6b27efb4346e61280f041b63dd8df7ad1f2e7f81.tar.gz
puppet-apt-6b27efb4346e61280f041b63dd8df7ad1f2e7f81.tar.bz2
Add inital puppet rspec test for custom facts
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/custom_facts_spec.rb67
1 files changed, 67 insertions, 0 deletions
diff --git a/spec/unit/custom_facts_spec.rb b/spec/unit/custom_facts_spec.rb
new file mode 100644
index 0000000..2d36bd7
--- /dev/null
+++ b/spec/unit/custom_facts_spec.rb
@@ -0,0 +1,67 @@
+require "spec_helper"
+
+describe "Facter::Util::Fact" do
+ before {
+ Facter.clear
+ }
+
+ describe 'custom facts' do
+
+ context 'Debian 7' do
+ before do
+ Facter.fact(:operatingsystem).stubs(:value).returns("Debian")
+ Facter.fact(:operatingsystemrelease).stubs(:value).returns("7.8")
+ Facter.fact(:lsbdistcodename).stubs(:value).returns("wheezy")
+ end
+
+ it "debian_release = oldstable" do
+ expect(Facter.fact(:debian_release).value).to eq('oldstable')
+ end
+
+ it "debian_codename = wheezy" do
+ expect(Facter.fact(:debian_codename).value).to eq('wheezy')
+ end
+ end
+
+ context 'Debian 8' do
+ before do
+ Facter.fact(:operatingsystem).stubs(:value).returns("Debian")
+ Facter.fact(:operatingsystemrelease).stubs(:value).returns("8.0")
+ Facter.fact(:lsbdistcodename).stubs(:value).returns("jessie")
+ end
+
+ it "debian_release = stable" do
+ expect(Facter.fact(:debian_release).value).to eq('stable')
+ end
+
+ it "debian_codename = jessie" do
+ expect(Facter.fact(:debian_codename).value).to eq('jessie')
+ end
+ end
+
+ context 'Ubuntu 15.10' do
+ before do
+ Facter.fact(:operatingsystem).stubs(:value).returns("Ubuntu")
+ Facter.fact(:operatingsystemrelease).stubs(:value).returns("15.10")
+ Facter.fact(:lsbdistcodename).stubs(:value).returns("Vivid")
+ end
+
+ it "ubuntu_codename = Vivid" do
+ expect(Facter.fact(:ubuntu_codename).value).to eq('Vivid')
+ end
+ end
+
+ end
+
+ describe "Test 'apt_running' fact" do
+ it "should return true when apt-get is running" do
+ Facter::Util::Resolution.stubs(:exec).with("pgrep apt-get >/dev/null 2>&1 && echo true || echo false").returns("true")
+ expect(Facter.fact(:apt_running).value).to eq('true')
+ end
+ it "should return false when apt-get is not running" do
+ Facter::Util::Resolution.stubs(:exec).with("pgrep apt-get >/dev/null 2>&1 && echo true || echo false").returns("false")
+ expect(Facter.fact(:apt_running).value).to eq('false')
+ end
+ end
+
+end