2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
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
|
2019-06-11 22:24:35 +00:00
|
|
|
it "loads the local fetcher for this file" do
|
2019-11-22 15:09:51 +00:00
|
|
|
res = Inspec::Fetcher::Registry.resolve(__FILE__)
|
2019-11-18 18:20:35 +00:00
|
|
|
_(res).must_be_kind_of Inspec::Fetcher::Local
|
2016-02-21 01:02:39 +00:00
|
|
|
end
|
2016-08-24 14:06:12 +00:00
|
|
|
|
2016-09-13 10:03:24 +00:00
|
|
|
describe "without a source specified" do
|
2019-06-11 22:24:35 +00:00
|
|
|
let(:mock_open) do
|
2016-09-20 10:36:23 +00:00
|
|
|
m = Minitest::Mock.new
|
2019-06-11 22:24:35 +00:00
|
|
|
m.expect :meta, { "content-type" => "application/gzip" }
|
2016-09-20 10:36:23 +00:00
|
|
|
m.expect :read, "fake content"
|
|
|
|
m
|
2019-06-11 22:24:35 +00:00
|
|
|
end
|
2016-09-20 10:36:23 +00:00
|
|
|
|
2016-09-13 10:03:24 +00:00
|
|
|
before do
|
|
|
|
Supermarket::API.expects(:exist?).returns(true)
|
2019-06-11 22:24:35 +00:00
|
|
|
Supermarket::API.expects(:find).returns({ "tool_source_url" => "http://mock-url" })
|
2016-09-13 10:03:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "defaults to supermarket if only a name is given" do
|
2019-11-22 15:09:51 +00:00
|
|
|
res = Inspec::Fetcher::Registry.resolve({ name: "mock/test-profile" })
|
2016-09-20 10:36:23 +00:00
|
|
|
res.expects(:open).returns(mock_open)
|
2019-11-18 18:20:35 +00:00
|
|
|
_(res).must_be_kind_of Inspec::Fetcher::Url
|
2019-09-30 22:31:55 +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
|
2019-11-22 15:09:51 +00:00
|
|
|
res = Inspec::Fetcher::Registry.resolve({ name: "mock/test-profile", cwd: "/tmp/inspec-test", cache: "ancache", backend: "test-backend" })
|
2019-11-18 18:20:35 +00:00
|
|
|
_(res).must_be_kind_of Inspec::Fetcher::Url
|
2016-09-13 10:03:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "is able to handle Windows paths" do
|
2016-08-24 14:06:12 +00:00
|
|
|
# simulate a local windows path
|
|
|
|
file = __FILE__
|
2021-05-10 03:59:04 +00:00
|
|
|
file.tr!("/", "\\")
|
2019-11-22 15:09:51 +00:00
|
|
|
res = Inspec::Fetcher::Registry.resolve(file)
|
2019-11-18 18:20:35 +00:00
|
|
|
_(res).must_be_kind_of Inspec::Fetcher::Local
|
2019-09-30 22:31:55 +00:00
|
|
|
_(res.target).must_equal __FILE__
|
2016-08-24 14:06:12 +00:00
|
|
|
end
|
2016-02-21 01:02:39 +00:00
|
|
|
end
|