inspec/test/unit/resources/pip_test.rb
Anthony Shaw d5f33f0b99 pip resource: support non-default pip locations, such as virtualenvs (#2097)
* Update pip resource for #516 allow user to set path to pip executable

Signed-off-by: Anthony Shaw <anthonyshaw@apache.org>

* support virtualenv path, pip file exec and better logic

Signed-off-by: Anthony Shaw <anthonyshaw@apache.org>

* add tests for the change to the pip path and resource

Signed-off-by: Anthony Shaw <anthonyshaw@apache.org>

* tests are case sensitive, although command line is not

Signed-off-by: Anthony Shaw <anthonyshaw@apache.org>

* use a path verification method instead of a class method

Signed-off-by: Anthony Shaw <anthonyshaw@apache.org>

* use guard clauses instead of conditionals

Signed-off-by: Anthony Shaw <anthonyshaw@apache.org>

* change the control flow to return nil when commands are not available

Signed-off-by: Anthony Shaw <anthonyshaw@apache.org>

* fix the return values when custom pip path is not valid

Signed-off-by: Anthony Shaw <anthonyshaw@apache.org>

* Refactor pip path detection to fix unit tests

Signed-off-by: Adam Leff <adam@leff.co>
2017-08-30 22:04:22 +02:00

27 lines
945 B
Ruby

# encoding: utf-8
# author: Christoph Hartmann
# author: Dominik Richter
require 'helper'
require 'inspec/resource'
describe 'Inspec::Resources::Pip' do
it 'verify pip package detail parsing' do
resource = load_resource('pip', 'jinja2')
pkg = {:name=>'Jinja2', :installed=>true, :version=>'2.8', :type=>'pip'}
_(resource.installed?).must_equal true
_(resource.info).must_equal pkg
end
it 'verify pip package default parsing' do
resource = load_resource('pip', 'django')
pkg = {:name=>'Django', :installed=>true, :version=>'1.10.5', :type=>'pip'}
_(resource.installed?).must_equal true
_(resource.info).must_equal pkg
end
it 'verify pip package non default parsing' do
resource = load_resource('pip', 'django', '/test/path/pip')
pkg = {:name=>'Django', :installed=>true, :version=>'1.11.4', :type=>'pip'}
_(resource.installed?).must_equal true
_(resource.info).must_equal pkg
end
end