diff --git a/packages/npms.sls b/packages/npms.sls index f57a7a0..6315965 100644 --- a/packages/npms.sls +++ b/packages/npms.sls @@ -14,7 +14,12 @@ include: {% endfor %} {% endif %} -### REQ PKGS (without these, some of the WANTED PIPS will fail to install) +# As we depend on npm installed, if this state file is invoked every time +# if will fail with 'npm not found'. This condition makes sure it's run +# only when explicitly asking for adding/removing npms +{% if wanted_npms or unwanted_npms %} + +### REQ PKGS (without these, some of the WANTED NPMS will fail to install) npm_req_pkgs: pkg.installed: - pkgs: {{ req_pkgs | json }} @@ -66,3 +71,5 @@ wanted_npms: {{ upn }}: npm.removed {% endfor %} + +{% endif %} diff --git a/pillar.example b/pillar.example index 9212648..17d1b4b 100644 --- a/pillar.example +++ b/pillar.example @@ -62,10 +62,10 @@ packages: - goodbye-world npms: - # dir: /home/kitchen/npms # The target directory in which to install the package, or None for global installation - # user: kitchen # The user to run NPM with (and to assign to `dir`) - # group: kitchen # The group to assign to `dir` - # mode: 0755 # The permissions to assign to `dir` + dir: /home/kitchen/npms # The target directory in which to install the package, or None for global installation + user: kitchen # The user to run NPM with (and to assign to `dir`) + group: kitchen # The group to assign to `dir` + mode: 0755 # The permissions to assign to `dir` # registry: None # The NPM registry from which to install the package # env: None # A list of environment variables to be set prior to execution # force_reinstall: False # Install the package even if it is already installed diff --git a/test/integration/default/npms_spec.rb b/test/integration/default/npms_spec.rb index debcb46..829aed1 100644 --- a/test/integration/default/npms_spec.rb +++ b/test/integration/default/npms_spec.rb @@ -1,3 +1,8 @@ +## FIXME! inspec's npm resource fails to check correctly (sudo issues, path issues) +## so I added some "poor man's checks" to ensure, at least, that npms are in place + +npms_path = '/home/kitchen/npms' + wanted_npms = { 'hello-world-npm': '1.1.1', 'sax': '1.2.4', @@ -13,12 +18,16 @@ control 'Wanted/Required npm packages' do os.name == 'debian' end + describe directory(npms_path) do + it { should exist } + its('owner') { should cmp 'kitchen' } + its('group') { should cmp 'kitchen' } + its('mode') { should cmp '0755' } + end + wanted_npms.each do |p,v| - describe npm(p) do - it { should be_installed } - # FIXME! Testing for version is failing, seems an issue in inspec - # Same happens with testing path, as it performs a cd command and it fails when using sudo - # its('version') { should eq v } + describe directory("#{npms_path}/node_modules/#{p}") do + it { should exist } end end end