2016-02-21 01:02:39 +00:00
|
|
|
# author: Dominik Richter
|
|
|
|
# author: Christoph Hartmann
|
|
|
|
|
|
|
|
require 'helper'
|
2016-09-13 10:03:24 +00:00
|
|
|
require 'bundles/inspec-supermarket/target'
|
|
|
|
require 'bundles/inspec-supermarket/api'
|
2016-02-21 01:02:39 +00:00
|
|
|
|
2019-05-15 06:27:18 +00:00
|
|
|
describe "Inspec::Fetcher" do
|
2016-02-21 01:02:39 +00:00
|
|
|
it 'loads the local fetcher for this file' do
|
|
|
|
res = Inspec::Fetcher.resolve(__FILE__)
|
|
|
|
res.must_be_kind_of Fetchers::Local
|
|
|
|
end
|
2016-08-24 14:06:12 +00:00
|
|
|
|
2016-09-13 10:03:24 +00:00
|
|
|
describe "without a source specified" do
|
2016-09-20 10:36:23 +00:00
|
|
|
let(:mock_open) {
|
|
|
|
m = Minitest::Mock.new
|
|
|
|
m.expect :meta, {'content-type' => 'application/gzip'}
|
|
|
|
m.expect :read, "fake content"
|
|
|
|
m
|
|
|
|
}
|
|
|
|
|
2016-09-13 10:03:24 +00:00
|
|
|
before do
|
|
|
|
Supermarket::API.expects(:exist?).returns(true)
|
|
|
|
Supermarket::API.expects(:find).returns({'tool_source_url' => "http://mock-url" })
|
|
|
|
end
|
|
|
|
|
|
|
|
it "defaults to supermarket if only a name is given" do
|
|
|
|
res = Inspec::Fetcher.resolve({:name => "mock/test-profile"})
|
2016-09-20 10:36:23 +00:00
|
|
|
res.expects(:open).returns(mock_open)
|
2016-09-13 10:03:24 +00:00
|
|
|
res.must_be_kind_of Fetchers::Url
|
2016-09-20 10:36:23 +00:00
|
|
|
res.resolved_source[:url].must_equal("http://mock-url")
|
2016-09-13 10:03:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores keys that might have come along for the ride" do
|
|
|
|
res = Inspec::Fetcher.resolve({:name => "mock/test-profile", cwd: "/tmp/inspec-test", cache: "ancache", backend: "test-backend"})
|
|
|
|
res.must_be_kind_of Fetchers::Url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 14:06:12 +00:00
|
|
|
it 'is able to handle Windows paths' do
|
|
|
|
# simulate a local windows path
|
|
|
|
file = __FILE__
|
|
|
|
file.tr!('/', '\\')
|
|
|
|
res = Inspec::Fetcher.resolve(file)
|
|
|
|
res.must_be_kind_of Fetchers::Local
|
|
|
|
res.target.must_equal __FILE__
|
|
|
|
end
|
2016-02-21 01:02:39 +00:00
|
|
|
end
|