Showing with 89 additions and 56 deletions.
  1. +12 −12 .travis.yml
  2. +7 −0 Gemfile
  3. +1 −1 Modulefile
  4. +9 −0 Rakefile
  5. +42 −41 spec/classes/init_spec.rb
  6. +18 −2 templates/resolv.conf.erb
24 changes: 12 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
language: ruby
before_script: "gem install --no-ri --no-rdoc bundler"
after_script:
script: "rake spec"
---
env:
- PUPPET_VERSION=2.7.23
- PUPPET_VERSION=3.3.2
notifications:
email: false
email: false
rvm:
- 1.9.3
- 1.8.7
env:
- PUPPET_VERSION=2.7.13
- PUPPET_VERSION=3.2.1
gemfile: .gemfile
- 1.9.3
- 1.8.7
matrix:
allow_failures:
- rvm: 1.9.3
- env: PUPPET_VERSION=2.7.23
language: ruby
before_script: "gem install --no-ri --no-rdoc bundler"
script: 'bundle exec rake validate && bundle exec rake lint && SPEC_OPTS="--format documentation" bundle exec rake spec'
gemfile: Gemfile
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source "https://rubygems.org"

puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7']
gem 'puppet', puppetversion
gem 'puppetlabs_spec_helper', '>= 0.1.0'
gem 'puppet-lint', '>= 0.3.2'
gem 'facter', '>= 1.7.0', "< 1.8.0"
2 changes: 1 addition & 1 deletion Modulefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name 'ghoneycutt-dnsclient'
version '3.0.4'
version '3.0.5'
source 'git://github.com/ghoneycutt/puppet-module-dnsclient.git'
author 'ghoneycutt'
license 'Apache License, Version 2.0'
Expand Down
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
require 'rubygems'
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp"]

desc "Run puppet in noop mode and check for syntax errors."
task :validate do
Dir['manifests/**/*.pp'].each do |path|
sh "puppet parser validate --noop #{path}"
end
end
83 changes: 42 additions & 41 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'
describe 'dnsclient' do

describe 'when using default values for class' do
context 'when using default values for class' do
it {
should contain_file('dnsclient_resolver_config_file').with({
'ensure' => 'file',
Expand All @@ -20,7 +20,7 @@
}
end

describe 'with parameter nameservers set' do
context 'with parameter nameservers set' do
let :params do
{ :nameservers => ['4.2.2.2', '4.2.2.1'] }
end
Expand All @@ -43,7 +43,7 @@
}
end

describe 'with parameter nameservers set to a single nameserver as a string ' do
context 'with parameter nameservers set to a single nameserver as a string' do
let :params do
{ :nameservers => '4.2.2.2' }
end
Expand All @@ -65,7 +65,7 @@
}
end

describe 'with no options' do
context 'with no options' do
let :params do
{ :options => 'UNSET' }
end
Expand All @@ -87,7 +87,7 @@
}
end

describe 'with options set to a single value' do
context 'with options set to a single value' do
let :params do
{ :options => 'ndots:2' }
end
Expand All @@ -110,7 +110,7 @@
}
end

describe 'with options set to multiple values' do
context 'with options set to multiple values' do
let :params do
{ :options => ['ndots:2', 'rotate'] }
end
Expand All @@ -133,7 +133,7 @@
}
end

describe 'with search set to multiple values' do
context 'with search set to multiple values' do
let :params do
{ :search => ['foo.example.tld', 'example.tld'] }
end
Expand All @@ -157,7 +157,7 @@
}
end

describe 'with search set to a single value' do
context 'with search set to a single value' do
let :params do
{ :search => 'example.tld' }
end
Expand All @@ -181,7 +181,7 @@
}
end

describe 'with search and domain set' do
context 'with search and domain set' do
let :params do
{
:search => ['foo.example.tld', 'example.tld'],
Expand All @@ -208,7 +208,7 @@
}
end

describe 'with domain set' do
context 'with domain set' do
let :params do
{ :domain => 'valid.tld' }
end
Expand All @@ -232,7 +232,7 @@
}
end

describe 'with domain and no options set' do
context 'with domain and no options set' do
let :params do
{
:domain => 'valid.tld',
Expand All @@ -258,31 +258,31 @@
}
end

# TODO - does not actually catch the fail()
describe 'with search set to an invalid single value' do
context 'with search set to an invalid single value' do
let :params do
{ :search => '-notvalid.tld' }
end

it {
# GH: this does not seem to work. if search is valid it should fail and does not
should raise_error()
}
it 'should fail' do
expect {
should raise_error(Puppet::Error, /search parameter does not match regex./)
}
end
end

# TODO - does not actually catch the fail()
describe 'with search set to an invalid value in an array' do
context 'with search set to an invalid value in an array' do
let :params do
{ :search => ['valid.tld', '-notvalid.tld'] }
end

it {
# GH: this does not seem to work. if search is valid it should fail and does not
should raise_error()
}
it 'should fail' do
expect {
should raise_error(Puppet::Error, /search parameter does not match regex./)
}
end
end

describe 'with only search' do
context 'with only search' do
let :params do
{
:search => 'valid.tld',
Expand All @@ -307,7 +307,7 @@
}
end

describe 'with search and sortlist' do
context 'with search and sortlist' do
let :params do
{
:search => 'valid.tld',
Expand All @@ -334,7 +334,7 @@
}
end

describe 'with search, sortlist, and options' do
context 'with search, sortlist, and options' do
let :params do
{
:search => 'valid.tld',
Expand All @@ -361,7 +361,7 @@
}
end

describe 'with sortlist set to an array of values' do
context 'with sortlist set to an array of values' do
let :params do
{ :sortlist => ['10.10.10.0/24', '10.10.11.0/24'] }
end
Expand All @@ -385,7 +385,7 @@
}
end

describe 'with sortlist, options, and domain' do
context 'with sortlist, options, and domain' do
let :params do
{
:sortlist => ['10.10.10.0/24', '10.10.11.0/24'],
Expand Down Expand Up @@ -413,7 +413,7 @@
}
end

describe 'with sortlist, no options, and domain' do
context 'with sortlist, no options, and domain' do
let :params do
{
:sortlist => ['10.10.10.0/24', '10.10.11.0/24'],
Expand Down Expand Up @@ -441,7 +441,7 @@
}
end

describe 'with sortlist set to a single value' do
context 'with sortlist set to a single value' do
let :params do
{ :sortlist => '10.10.10.0/24' }
end
Expand All @@ -465,18 +465,19 @@
}
end

# TODO - write test
describe 'with parameter resolver_config_file_ensure not set to \'file\' \'present\' or \'absent\'' do
context 'with parameter resolver_config_file_ensure not set to \'file\' \'present\' or \'absent\'' do
let :params do
{ :resolver_config_file_ensure => 'invalid' }
end

it {
# GH: code to catch fail()
}
it 'should fail' do
expect {
should raise_error(Puppet::Error, /Valid values for \$resolver_config_file_ensure are \'absent\', \'file\', or \'present\'. Specified value is invalid/)
}
end
end

describe 'with parameter resolver_config_file_ensure set to present' do
context 'with parameter resolver_config_file_ensure set to present' do
let :params do
{ :resolver_config_file_ensure => 'present' }
end
Expand All @@ -499,7 +500,7 @@
}
end

describe 'with parameter resolver_config_file_ensure set to absent' do
context 'with parameter resolver_config_file_ensure set to absent' do
let :params do
{ :resolver_config_file_ensure => 'absent' }
end
Expand All @@ -511,7 +512,7 @@
}
end

describe 'with parameter resolver_config_file set' do
context 'with parameter resolver_config_file set' do
let :params do
{ :resolver_config_file => '/tmp/resolv.conf' }
end
Expand All @@ -523,7 +524,7 @@
}
end

describe 'with parameter resolver_config_file_owner set' do
context 'with parameter resolver_config_file_owner set' do
let :params do
{ :resolver_config_file_owner => 'foo' }
end
Expand All @@ -535,7 +536,7 @@
}
end

describe 'with parameter resolver_config_file_group set' do
context 'with parameter resolver_config_file_group set' do
let :params do
{ :resolver_config_file_group => 'bar' }
end
Expand All @@ -547,7 +548,7 @@
}
end

describe 'with parameter resolver_config_file_mode set' do
context 'with parameter resolver_config_file_mode set' do
let :params do
{ :resolver_config_file_mode => '0777' }
end
Expand Down
20 changes: 18 additions & 2 deletions templates/resolv.conf.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
# This file is being maintained by Puppet.
# DO NOT EDIT
<% if @search[0] != 'UNSET' -%>
search<% @search.each do |search_domain| %> <%= search_domain %><% end %>
<% if @search.class == String -%>
search <%= @search %>
<% else -%>
search <%= @search.join(' ') %>
<% end -%>
<% end -%>
<% if @sortlist[0] != 'UNSET' -%>
sortlist<% @sortlist.each do |sortlist_address| %> <%= sortlist_address%><% end %>
<% if @sortlist.class == String -%>
sortlist <%= @sortlist %>
<% else -%>
sortlist <%= @sortlist.join(' ') %>
<% end -%>
<% end -%>
<% if @domain != 'UNSET' and @search[0] == 'UNSET' -%>
domain <%= @domain %>
<% end -%>
<% if @options != 'UNSET' -%>
<% if @options.class == String -%>
options <%= @options %>
<% else -%>
options<% @options.each do |option| %> <%= option %><% end %>
<% end -%>
<% end -%>
<% if @nameservers.class == String -%>
nameserver <%= @nameservers %>
<% else -%>
<% @nameservers.each do |nameserver| -%>
nameserver <%= nameserver %>
<% end -%>
<% end -%>