1
0
mirror of https://github.com/ardichoke/puppet-arpwatch.git synced 2026-05-11 02:15:37 -04:00

Convert to pdk module

This commit is contained in:
Ryan DeShone
2020-09-24 14:50:38 -04:00
parent 2284b701e9
commit 93243c7912
21 changed files with 665 additions and 103 deletions

View File

@@ -0,0 +1,15 @@
# frozen_string_literal: true
require 'spec_helper'
describe 'arpwatch' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }
it { is_expected.to compile }
it { is_expected.to contain_package('arpwatch') }
it { is_expected.to contain_service('arpwatch') }
end
end
end

View File

@@ -1,53 +0,0 @@
require 'spec_helper'
describe 'arpwatch', type: 'class' do
context 'On RedHat 7 with no parameters' do
let (:facts) { { osfamily: 'RedHat', operatingsystemmajrelease: '7' } }
it {
should contain_package('arpwatch').with({'ensure'=>'installed'})
should contain_file('/etc/sysconfig/arpwatch').with({'ensure'=>'file'})
should contain_service('arpwatch').with({'ensure'=>'running', 'enable'=>true})
}
end
context 'On RedHat 6 with no parameters' do
let (:facts) { { osfamily: 'RedHat', operatingsystemmajrelease: '6' } }
it {
should contain_package('arpwatch').with({'ensure'=>'installed'})
should contain_file('/etc/sysconfig/arpwatch').with({'ensure'=>'file'})
should contain_service('arpwatch').with({'ensure'=>'running', 'enable'=>true})
}
end
context 'On RedHat 5 with no parameters' do
let (:facts) { { osfamily: 'RedHat', operatingsystemmajrelease: '6' } }
it {
should contain_package('arpwatch').with({'ensure'=>'installed'})
should contain_file('/etc/sysconfig/arpwatch').with({'ensure'=>'file'})
should contain_service('arpwatch').with({'ensure'=>'running', 'enable'=>true})
}
end
context 'On Debian 6 with no parameters' do
let (:facts) { { osfamily: 'Debian', operatingsystemmajrelease: '6' }}
it {
should contain_package('arpwatch').with({'ensure'=>'installed'})
should contain_file('/etc/default/arpwatch').with({'ensure'=>'file'})
should contain_service('arpwatch').with({'ensure'=>'running', 'enable'=>true})
}
end
context 'On Debian 7 with no parameters' do
let (:facts) { { osfamily: 'Debian', operatingsystemmajrelease: '7' }}
it {
should contain_package('arpwatch').with({'ensure'=>'installed'})
should contain_file('/etc/default/arpwatch').with({'ensure'=>'file'})
should contain_service('arpwatch').with({'ensure'=>'running', 'enable'=>true})
}
end
context 'On an unknown OS' do
let :facts do
{
:osfamily => 'Darwin'
}
end
it {
expect { should raise_error(Puppet::Error) }
}
end
end

8
spec/default_facts.yml Normal file
View File

@@ -0,0 +1,8 @@
# Use default_module_facts.yml for module specific facts.
#
# Facts specified here will override the values provided by rspec-puppet-facts.
---
ipaddress: "172.16.254.254"
ipaddress6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA"
is_pe: false
macaddress: "AA:AA:AA:AA:AA:AA"

View File

@@ -1,6 +1,57 @@
require 'rspec-puppet'
fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
RSpec.configure do |c|
c.module_path = File.join(fixture_path, 'modules')
c.manifest_dir = File.join(fixture_path, 'manifests')
# frozen_string_literal: true
require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb'))
include RspecPuppetFacts
default_facts = {
puppetversion: Puppet.version,
facterversion: Facter.version,
}
default_fact_files = [
File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')),
File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')),
]
default_fact_files.each do |f|
next unless File.exist?(f) && File.readable?(f) && File.size?(f)
begin
default_facts.merge!(YAML.safe_load(File.read(f), [], [], true))
rescue => e
RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}"
end
end
# read default_facts and merge them over what is provided by facterdb
default_facts.each do |fact, value|
add_custom_fact fact, value
end
RSpec.configure do |c|
c.default_facts = default_facts
c.before :each do
# set to strictest setting for testing
# by default Puppet runs at warning level
Puppet.settings[:strict] = :warning
Puppet.settings[:strict_variables] = true
end
c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT']
c.after(:suite) do
end
end
# Ensures that a module is defined
# @param module_name Name of the module
def ensure_module_defined(module_name)
module_name.split('::').reduce(Object) do |last_module, next_module|
last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false)
last_module.const_get(next_module, false)
end
end
# 'spec_overrides' from sync.yml will appear below this line