mirror of
https://github.com/inspec/inspec
synced 2024-11-14 17:07:09 +00:00
a9726910ff
* Fixes the npm package example to state 'npm' vs 'gem' * Fixes powershell resource to specify the resource instead of 'script' * Updates the example to rename variable 'script' While ruby would allow the local variable and the presence of the InSpec method at the same time I think that it is bad form. Other resource examples also use 'script'. * Changes pip to show generic example Other package like resources show a generic example in the default. Signed-off-by: Franklin Webber <franklin@chef.io>
75 lines
1.5 KiB
Text
75 lines
1.5 KiB
Text
---
|
|
title: About the npm Resource
|
|
---
|
|
|
|
# npm
|
|
|
|
Use the `npm` InSpec audit resource to test if a global NPM package is installed. NPM is the the package manager for Node.js packages (https://docs.npmjs.com), such as Bower and StatsD.
|
|
|
|
|
|
## Syntax
|
|
|
|
A `npm` resource block declares a package and (optionally) a package version:
|
|
|
|
describe npm('npm_package_name') do
|
|
it { should be_installed }
|
|
end
|
|
|
|
where
|
|
|
|
* `('npm_package_name')` must specify an NPM package, such as `'bower'` or `'statsd'`
|
|
* `be_installed` is a valid matcher for this resource
|
|
|
|
|
|
## Matchers
|
|
|
|
This InSpec audit resource has the following matchers:
|
|
|
|
### be
|
|
|
|
<%= partial "/shared/matcher_be" %>
|
|
|
|
### be_installed
|
|
|
|
The `be_installed` matcher tests if the named Gem package and package version (if specified) is installed:
|
|
|
|
it { should be_installed }
|
|
|
|
### cmp
|
|
|
|
<%= partial "/shared/matcher_cmp" %>
|
|
|
|
### eq
|
|
|
|
<%= partial "/shared/matcher_eq" %>
|
|
|
|
### include
|
|
|
|
<%= partial "/shared/matcher_include" %>
|
|
|
|
### match
|
|
|
|
<%= partial "/shared/matcher_match" %>
|
|
|
|
### version
|
|
|
|
The `version` matcher tests if the named package version is on the system:
|
|
|
|
its('version') { should eq '1.2.3' }
|
|
|
|
## Examples
|
|
|
|
The following examples show how to use this InSpec audit resource.
|
|
|
|
### Verify that bower is installed, with a specific version
|
|
|
|
describe npm('bower') do
|
|
it { should be_installed }
|
|
its('version') { should eq '1.4.1' }
|
|
end
|
|
|
|
### Verify that statsd is not installed
|
|
|
|
describe npm('statsd') do
|
|
it { should_not be_installed }
|
|
end
|