Skip to content

Commit

Permalink
Merge pull request #12 from nanliu/tb/proxy
Browse files Browse the repository at this point in the history
Add support for npm proxy configuration.
  • Loading branch information
Branan Purvine-Riley committed Jun 8, 2012
2 parents 6703b80 + b7d48c9 commit 5f57562
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
11 changes: 10 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
# Usage:
#
class nodejs(
$dev_package = false
$dev_package = false,
$proxy = ''
) inherits nodejs::params {

case $::operatingsystem {
Expand Down Expand Up @@ -67,6 +68,14 @@
require => Anchor['nodejs::repo']
}

if $proxy {
exec { 'npm_proxy':
command => "npm config set proxy ${proxy}",
path => $::path,
require => Package['npm'],
}
}

if $dev_package and $nodejs::params::dev_pkg {
package { 'nodejs-dev':
name => $nodejs::params::dev_pkg,
Expand Down
3 changes: 3 additions & 0 deletions manifests/npm.pp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
path => $::path,
require => Class['nodejs'],
}

# Conditionally require npm_proxy only if resource exists.
Exec<| title=='npm_proxy' |> -> Exec["npm_install_${name}"]
} else {
exec { "npm_remove_${name}":
command => "npm remove ${npm_pkg}",
Expand Down
29 changes: 29 additions & 0 deletions spec/classes/nodejs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@
}
end

let :params do
{ :dev_package => true, }
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',
'require' => 'Anchor[nodejs::repo]',
}) }
it { should contain_package('nodejs-dev') }
it { should contain_package('npm').with({
'name' => 'npm',
'require' => 'Anchor[nodejs::repo]',
Expand Down Expand Up @@ -76,5 +81,29 @@
it { should_not contain_package('nodejs-dev') }
end
end

describe 'when deploying with proxy' do
let :facts do
{
:operatingsystem => 'Ubuntu',
:lsbdistcodename => 'edgy',
}
end

let :params do
{ :proxy => 'http://proxy.puppetlabs.lan:80/' }
end

it { should contain_package('npm').with({
'name' => 'npm',
'require' => 'Anchor[nodejs::repo]',
}) }
it { should contain_exec('npm_proxy').with({
'command' => 'npm config set proxy http://proxy.puppetlabs.lan:80/',
'require' => 'Package[npm]',
}) }
it { should_not contain_package('nodejs-stable-release') }
end

end

0 comments on commit 5f57562

Please sign in to comment.