Skip to content

Commit

Permalink
Merge pull request #36 from wolfspyre/iss27_iss33_refactor
Browse files Browse the repository at this point in the history
refactor to address issues 27 and 33
  • Loading branch information
hunner committed Jul 12, 2013
2 parents b5e70b0 + 837dab4 commit 6223d95
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 56 deletions.
73 changes: 45 additions & 28 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,65 @@
#
class nodejs(
$dev_package = false,
$manage_repo = false,
$proxy = ''
) inherits nodejs::params {
#input validation
validate_bool($dev_package)
validate_bool($manage_repo)

case $::operatingsystem {
'Debian': {
include 'apt'

apt::source { 'sid':
location => 'http://ftp.us.debian.org/debian/',
release => 'sid',
repos => 'main',
pin => 100,
include_src => false,
before => Anchor['nodejs::repo'],
if $manage_repo {
#only add apt source if we're managing the repo
include 'apt'
apt::source { 'sid':
location => 'http://ftp.us.debian.org/debian/',
release => 'sid',
repos => 'main',
pin => 100,
include_src => false,
before => Anchor['nodejs::repo'],
}
}

}

'Ubuntu': {
include 'apt'

# Only use PPA when necessary.
if $::lsbdistcodename != 'Precise'{
apt::ppa { 'ppa:chris-lea/node.js':
before => Anchor['nodejs::repo'],
if $manage_repo {
#only add apt source if we're managing the repo
include 'apt'
# Only use PPA when necessary.
if $::lsbdistcodename != 'Precise'{
apt::ppa { 'ppa:chris-lea/node.js':
before => Anchor['nodejs::repo'],
}
}
}
}

'Fedora', 'RedHat', 'CentOS', 'OEL', 'OracleLinux', 'Amazon': {
package { 'nodejs-stable-release':
ensure => absent,
before => Yumrepo['nodejs-stable'],
}

yumrepo { 'nodejs-stable':
descr => 'Stable releases of Node.js',
baseurl => $nodejs::params::baseurl,
enabled => 1,
gpgcheck => $nodejs::params::gpgcheck,
gpgkey => 'http://patches.fedorapeople.org/oldnode/stable/RPM-GPG-KEY-tchol',
before => Anchor['nodejs::repo'],
if $manage_repo {
package { 'nodejs-stable-release':
ensure => absent,
before => Yumrepo['nodejs-stable'],
}
yumrepo { 'nodejs-stable':
descr => 'Stable releases of Node.js',
baseurl => $nodejs::params::baseurl,
enabled => 1,
gpgcheck => $nodejs::params::gpgcheck,
gpgkey => 'http://patches.fedorapeople.org/oldnode/stable/RPM-GPG-KEY-tchol',
before => Anchor['nodejs::repo'],
}
file {'nodejs_repofile':
ensure => 'file',
before => Anchor['nodejs::repo'],
group => 'root',
mode => '0444',
owner => 'root',
path => '/etc/yum.repos.d/nodejs-stable.repo',
require => Yumrepo['nodejs-stable']
}
}
}

Expand Down
16 changes: 11 additions & 5 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@
'' => regsubst($::operatingsystemrelease,'^(\d+)\.(\d+)','\1'),
default => $::lsbmajdistrelease,
}
$node_pkg = 'nodejs-compat-symlinks'

case $majdistrelease {
'5': {
$gpgcheck = 0
$node_pkg = 'nodejs-compat-symlinks'
}
default: {
$gpgcheck = 1
$node_pkg = 'nodejs'
}
}
$npm_pkg = 'npm'
$baseurl = 'http://patches.fedorapeople.org/oldnode/stable/el$releasever/$basearch/'
$gpgcheck = $majdistrelease ? {
'5' => 0,
default => 1,
}
}

'Fedora': {
Expand Down
160 changes: 137 additions & 23 deletions spec/classes/nodejs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,46 @@

describe 'nodejs', :type => :class do

describe 'input validation' do
let :facts do {} end
let :params do {} end
it 'when deploying on an unsupported os' do
facts.merge!({:operatingsystem => 'SparklePony'})
params.merge!({:dev_package => true, :manage_repo => true })
expect { subject }.to raise_error(Puppet::Error, /Class nodejs does not support SparklePony/)
end
['dev_package','manage_repo'].each do |boolz|
it "should fail when #{boolz} is not a boolean" do
facts.merge!({:operatingsystem => 'Debian'})
params.merge!({boolz => 'BOGON'})
expect { subject }.to raise_error(Puppet::Error, /"BOGON" is not a boolean. It looks to be a String/)
end
end
end
describe 'when deploying on debian' do
let :facts do
{
:operatingsystem => 'Debian',
:lsbdistcodename => 'sid',
}
end

it { should contain_class('apt') }
it { should contain_apt__source('sid').with({
'location' => 'http://ftp.us.debian.org/debian/',
}) }
let :params do
{ :dev_package => true, :manage_repo => true }
end
context 'when manage_repo is true' do
it { should contain_class('apt') }
it 'should contain the apt source' do
should contain_apt__source('sid').with({
'location' => 'http://ftp.us.debian.org/debian/',
})
end
end
context 'when manage_repo is false' do
it 'should not contain the apt source' do
params.merge!({:manage_repo => false})
should_not contain_apt__source('sid')
end
end
it { should contain_package('nodejs').with({
'name' => 'nodejs',
'require' => 'Anchor[nodejs::repo]',
Expand All @@ -34,11 +62,19 @@
end

let :params do
{ :dev_package => true, }
{ :dev_package => true, :manage_repo => true }
end
context 'when manage_repo is true' do
it { should contain_class('apt') }
it { should contain_apt__ppa('ppa:chris-lea/node.js') }
end
context 'when manage_repo is false' do
it 'should not create the ppa' do
params.merge!({:manage_repo => false})
should_not contain_class('apt')
should_not contain_apt__ppa('ppa:chris-lea/node.js')
end
end

it { should contain_class('apt') }
it { should contain_apt__ppa('ppa:chris-lea/node.js') }
it { should contain_package('nodejs') }
it { should contain_package('nodejs').with({
'name' => 'nodejs',
Expand All @@ -53,27 +89,104 @@
end

{ 'Redhat' => 'el$releasever',
'CentOS' => 'el$releasever',
'Fedora' => 'f$releasever',
'CentOS' => 'el$releasever'
}.each do |os, repo|
{ '5' => 'nodejs-compat-symlinks',
'6' => 'nodejs'
}.each do |major, package|
describe "when deploying on (#{os}) #{major}" do
let :facts do
{ :operatingsystem => os,
:operatingsystemrelease => "#{major}.4",
:lsbmajdisrelease => major
}
end

let :params do
{ :dev_package => true,:manage_repo => true}
end

context 'when manage_repo is true' do
it 'should remove the node-js-stable-release package' do
should contain_package('nodejs-stable-release').with({
'ensure' => 'absent',
})
end
it 'should add the nodejs-stable yumrepo' do
should contain_yumrepo('nodejs-stable').with({
'baseurl' => "http://patches.fedorapeople.org/oldnode/stable/#{repo}/$basearch/",
'before' => 'Anchor[nodejs::repo]',
})
end
it 'should add the yumrepo file resource' do
should contain_file('nodejs_repofile')
end
end
context 'when manage_repo is false' do
let (:params) {{:manage_repo => false}}
it 'should not remove the nodejs-stable-release package if present' do
should_not contain_package('nodejs-stable-release')
end
it 'should not contain the yumrepo' do
should_not contain_yumrepo('nodejs-stable')
end
it 'should not contain the yumrepo file' do
should_not contain_file('nodejs_repofile')
end
end
it { should contain_package('nodejs').with({
'name' => package,
'require' => 'Anchor[nodejs::repo]',
}) }
it { should contain_package('npm').with({
'name' => 'npm',
'require' => 'Anchor[nodejs::repo]',
}) }
it { should_not contain_package('nodejs-dev') }
end
end
end
{ 'Fedora' => 'f$releasever',
'Amazon' => 'amzn1'
}.each do |os, repo|
describe 'when deploying on RedHat' do
describe "when deploying on (#{os})" do
let :facts do
{ :operatingsystem => os, }
{ :operatingsystem => os,
}
end

let :params do
{ :dev_package => true, }
{ :dev_package => true,:manage_repo => true }
end
context 'when manage_repo is true' do
it 'should remove the node-js-stable-release package' do
should contain_package('nodejs-stable-release').with({
'ensure' => 'absent',
})
end
it 'should add the nodejs-stable yumrepo' do
should contain_yumrepo('nodejs-stable').with({
'baseurl' => "http://patches.fedorapeople.org/oldnode/stable/#{repo}/$basearch/",
'before' => 'Anchor[nodejs::repo]',
})
end
it 'should contain the yumrepo file' do
should contain_file('nodejs_repofile')
end
end

context 'when manage_repo is false' do
let (:params) {{:manage_repo => false}}
it 'should not remove the nodejs-stable-release package if present' do
should_not contain_package('nodejs-stable-release')
end
it 'should not contain the yumrepo' do
should_not contain_yumrepo('nodejs-stable')
end
it 'should not contain the yumrepo file' do
should_not contain_file('nodejs_repofile')
end
end

it { should contain_package('nodejs-stable-release').with({
'ensure' => 'absent',
}) }
it { should contain_yumrepo('nodejs-stable').with({
'baseurl' => "http://patches.fedorapeople.org/oldnode/stable/#{repo}/$basearch/",
'gpgcheck' => '1',
'before' => 'Anchor[nodejs::repo]',
}) }
it { should contain_package('nodejs').with({
'name' => 'nodejs-compat-symlinks',
'require' => 'Anchor[nodejs::repo]',
Expand All @@ -86,6 +199,7 @@
end
end


describe 'when deploying with proxy' do
let :facts do
{
Expand Down

0 comments on commit 6223d95

Please sign in to comment.