From d4208cb63c2ce12c11a8b861c687e218df1d917f Mon Sep 17 00:00:00 2001 From: Sonu Saha <98935583+ahasunos@users.noreply.github.com> Date: Wed, 24 Jan 2024 18:34:21 +0530 Subject: [PATCH] CHEF-4571: Silence warning about transforming into git fetcher (#6946) * chore: change log-level for url fetcher transformation Signed-off-by: Sonu Saha * test: remove warning logs from url fetcher test Signed-off-by: Sonu Saha --------- Signed-off-by: Sonu Saha --- lib/inspec/fetcher/url.rb | 2 +- test/unit/fetchers/url_test.rb | 95 +++++++++++++--------------------- 2 files changed, 36 insertions(+), 61 deletions(-) diff --git a/lib/inspec/fetcher/url.rb b/lib/inspec/fetcher/url.rb index 18628cb0a..967f10a6a 100644 --- a/lib/inspec/fetcher/url.rb +++ b/lib/inspec/fetcher/url.rb @@ -93,7 +93,7 @@ module Inspec::Fetcher end if transformed_target - Inspec::Log.warn("URL target #{target} transformed to #{transformed_target}. Consider using the git fetcher") + Inspec::Log.debug("URL target #{target} transformed to #{transformed_target}. Consider using the git fetcher") transformed_target else target diff --git a/test/unit/fetchers/url_test.rb b/test/unit/fetchers/url_test.rb index 4b15f2e8a..cf20033e7 100644 --- a/test/unit/fetchers/url_test.rb +++ b/test/unit/fetchers/url_test.rb @@ -32,17 +32,6 @@ describe Inspec::Fetcher::Url do Mixlib::ShellOut.expects(:new).returns(git_remote_head_main) end - def expect_url_transform - @mock_logger = Minitest::Mock.new - @mock_logger.expect(:warn, nil, [/URL target.*transformed/]) - - Inspec::Log.stub :warn, (proc { |message| @mock_logger.warn(message) }) do - yield - end - - @mock_logger.verify - end - it "handles a http url" do url = "http://chef.io/some.tar.gz" res = Inspec::Fetcher::Url.resolve(url) @@ -82,44 +71,36 @@ describe Inspec::Fetcher::Url do http://github.com/chef/inspec.git http://www.github.com/chef/inspec.git}.each do |github| it "resolves a github url #{github}" do - expect_url_transform do - res = Inspec::Fetcher::Url.resolve(github) - res.expects(:open).returns(mock_open) - _(res).wont_be_nil - _(res.resolved_source).must_equal({ url: "https://github.com/chef/inspec/archive/main.tar.gz", sha256: expected_shasum }) - end + res = Inspec::Fetcher::Url.resolve(github) + res.expects(:open).returns(mock_open) + _(res).wont_be_nil + _(res.resolved_source).must_equal({ url: "https://github.com/chef/inspec/archive/main.tar.gz", sha256: expected_shasum }) end end it "resolves a github url with dot" do - expect_url_transform do - github = "https://github.com/mitre/aws-rds-oracle-mysql-ee-5.7-cis-baseline" - res = Inspec::Fetcher::Url.resolve(github) - res.expects(:open).returns(mock_open) - _(res).wont_be_nil - _(res.resolved_source).must_equal({ url: "https://github.com/mitre/aws-rds-oracle-mysql-ee-5.7-cis-baseline/archive/master.tar.gz", sha256: expected_shasum }) - end + github = "https://github.com/mitre/aws-rds-oracle-mysql-ee-5.7-cis-baseline" + res = Inspec::Fetcher::Url.resolve(github) + res.expects(:open).returns(mock_open) + _(res).wont_be_nil + _(res.resolved_source).must_equal({ url: "https://github.com/mitre/aws-rds-oracle-mysql-ee-5.7-cis-baseline/archive/master.tar.gz", sha256: expected_shasum }) end it "resolves a github branch url" do - expect_url_transform do - github = "https://github.com/hardening-io/tests-os-hardening/tree/2.0" - res = Inspec::Fetcher::Url.resolve(github) - res.expects(:open).returns(mock_open) - _(res).wont_be_nil - _(res.resolved_source).must_equal({ url: "https://github.com/hardening-io/tests-os-hardening/archive/2.0.tar.gz", sha256: expected_shasum }) - end + github = "https://github.com/hardening-io/tests-os-hardening/tree/2.0" + res = Inspec::Fetcher::Url.resolve(github) + res.expects(:open).returns(mock_open) + _(res).wont_be_nil + _(res.resolved_source).must_equal({ url: "https://github.com/hardening-io/tests-os-hardening/archive/2.0.tar.gz", sha256: expected_shasum }) end it "resolves a github commit url" do - expect_url_transform do - github = "https://github.com/hardening-io/tests-os-hardening/tree/48bd4388ddffde68badd83aefa654e7af3231876" - res = Inspec::Fetcher::Url.resolve(github) - res.expects(:open).returns(mock_open) - _(res).wont_be_nil - _(res.resolved_source).must_equal({ url: "https://github.com/hardening-io/tests-os-hardening/archive/48bd4388ddffde68badd83aefa654e7af3231876.tar.gz", - sha256: expected_shasum }) - end + github = "https://github.com/hardening-io/tests-os-hardening/tree/48bd4388ddffde68badd83aefa654e7af3231876" + res = Inspec::Fetcher::Url.resolve(github) + res.expects(:open).returns(mock_open) + _(res).wont_be_nil + _(res.resolved_source).must_equal({ url: "https://github.com/hardening-io/tests-os-hardening/archive/48bd4388ddffde68badd83aefa654e7af3231876.tar.gz", + sha256: expected_shasum }) end %w{https://bitbucket.org/chef/inspec @@ -129,34 +110,28 @@ describe Inspec::Fetcher::Url do http://bitbucket.org/chef/inspec.git http://www.bitbucket.org/chef/inspec.git}.each do |bitbucket| it "resolves a bitbucket url #{bitbucket}" do - expect_url_transform do - expect_git_remote_head_main(bitbucket) - res = Inspec::Fetcher::Url.resolve(bitbucket) - res.expects(:open).returns(mock_open) - _(res).wont_be_nil - _(res.resolved_source).must_equal({ url: "https://bitbucket.org/chef/inspec/get/main.tar.gz", sha256: expected_shasum }) - end + expect_git_remote_head_main(bitbucket) + res = Inspec::Fetcher::Url.resolve(bitbucket) + res.expects(:open).returns(mock_open) + _(res).wont_be_nil + _(res.resolved_source).must_equal({ url: "https://bitbucket.org/chef/inspec/get/main.tar.gz", sha256: expected_shasum }) end end it "resolves a bitbucket branch url" do - expect_url_transform do - bitbucket = "https://bitbucket.org/chef/inspec/branch/newbranch" - res = Inspec::Fetcher::Url.resolve(bitbucket) - res.expects(:open).returns(mock_open) - _(res).wont_be_nil - _(res.resolved_source).must_equal({ url: "https://bitbucket.org/chef/inspec/get/newbranch.tar.gz", sha256: expected_shasum }) - end + bitbucket = "https://bitbucket.org/chef/inspec/branch/newbranch" + res = Inspec::Fetcher::Url.resolve(bitbucket) + res.expects(:open).returns(mock_open) + _(res).wont_be_nil + _(res.resolved_source).must_equal({ url: "https://bitbucket.org/chef/inspec/get/newbranch.tar.gz", sha256: expected_shasum }) end it "resolves a bitbucket commit url" do - expect_url_transform do - bitbucket = "https://bitbucket.org/chef/inspec/commits/48bd4388ddffde68badd83aefa654e7af3231876" - res = Inspec::Fetcher::Url.resolve(bitbucket) - res.expects(:open).returns(mock_open) - _(res).wont_be_nil - _(res.resolved_source).must_equal({ url: "https://bitbucket.org/chef/inspec/get/48bd4388ddffde68badd83aefa654e7af3231876.tar.gz", sha256: expected_shasum }) - end + bitbucket = "https://bitbucket.org/chef/inspec/commits/48bd4388ddffde68badd83aefa654e7af3231876" + res = Inspec::Fetcher::Url.resolve(bitbucket) + res.expects(:open).returns(mock_open) + _(res).wont_be_nil + _(res.resolved_source).must_equal({ url: "https://bitbucket.org/chef/inspec/get/48bd4388ddffde68badd83aefa654e7af3231876.tar.gz", sha256: expected_shasum }) end end