mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
add a mock fetcher
This commit is contained in:
parent
c1d2da5bf3
commit
b7e438eabc
4 changed files with 75 additions and 6 deletions
27
lib/fetchers/mock.rb
Normal file
27
lib/fetchers/mock.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
# encoding: utf-8
|
||||
# author: Dominik Richter
|
||||
# author: Christoph Hartmann
|
||||
|
||||
module Fetchers
|
||||
class Mock < Inspec.fetcher(1)
|
||||
name 'mock'
|
||||
priority 0
|
||||
|
||||
def self.resolve(target)
|
||||
return nil unless target.is_a? Hash
|
||||
new(target)
|
||||
end
|
||||
|
||||
def initialize(data)
|
||||
@data = data
|
||||
end
|
||||
|
||||
def files
|
||||
@data.keys
|
||||
end
|
||||
|
||||
def read(file)
|
||||
@data[file]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,17 +3,11 @@
|
|||
# author: Christoph Hartmann
|
||||
|
||||
require 'helper'
|
||||
require 'train'
|
||||
|
||||
# activate hell!
|
||||
require 'minitest/hell'
|
||||
class Minitest::Test
|
||||
parallelize_me!
|
||||
end
|
||||
|
||||
CMD = Train.create('local').connection
|
||||
TMP_CACHE = {}
|
||||
|
||||
describe 'Inspec::InspecCLI' do
|
||||
let(:repo_path) { File.expand_path(File.join( __FILE__, '..', '..', '..')) }
|
||||
let(:exec_inspec) { File.join(repo_path, 'bin', 'inspec') }
|
||||
|
|
|
@ -29,6 +29,11 @@ require 'inspec/backend'
|
|||
require 'inspec/profile'
|
||||
require 'inspec/runner'
|
||||
require 'inspec/runner_mock'
|
||||
require 'fetchers/mock'
|
||||
|
||||
require 'train'
|
||||
CMD = Train.create('local').connection
|
||||
TMP_CACHE = {}
|
||||
|
||||
class MockLoader
|
||||
# collects emulation operating systems
|
||||
|
|
43
test/unit/fetchers/mock_test.rb
Normal file
43
test/unit/fetchers/mock_test.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
# encoding: utf-8
|
||||
# author: Dominik Richter
|
||||
# author: Christoph Hartmann
|
||||
|
||||
require 'helper'
|
||||
|
||||
describe Fetchers::Mock do
|
||||
let(:fetcher) { Fetchers::Mock }
|
||||
|
||||
it 'registers with the fetchers registry' do
|
||||
reg = Inspec::Fetcher.registry
|
||||
_(reg['mock']).must_equal fetcher
|
||||
end
|
||||
|
||||
it 'wont load nil' do
|
||||
fetcher.resolve(nil).must_be :nil?
|
||||
end
|
||||
|
||||
it 'wont load a string' do
|
||||
fetcher.resolve(rand.to_s).must_be :nil?
|
||||
end
|
||||
|
||||
describe 'applied to a map' do
|
||||
it 'must be resolved' do
|
||||
fetcher.resolve({}).must_be_kind_of fetcher
|
||||
end
|
||||
|
||||
it 'has no files on empty' do
|
||||
fetcher.resolve({}).files.must_equal []
|
||||
end
|
||||
|
||||
it 'has files' do
|
||||
f = rand.to_s
|
||||
fetcher.resolve({f => nil}).files.must_equal [f]
|
||||
end
|
||||
|
||||
it 'can read a file' do
|
||||
f = rand.to_s
|
||||
s = rand.to_s
|
||||
fetcher.resolve({f => s}).read(f).must_equal s
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue