From 71c41699341c09268beb0fe48c4df41da203f59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 28 Jul 2021 19:00:56 +0000 Subject: [PATCH 1/3] test: isolate the configuration from the caller's environment This stops the existence or not of certain configuration settings in the environment outside the test from affecting what happens. --- test/test_helper.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 196c145e6..e66a9cad5 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -6,9 +6,22 @@ module Rugged class TestCase < Minitest::Test + # Set up some isolation for our tests so we don't try to touch any + # configuration from the user running the tests + def before_setup + @configdir ||= begin + path = Dir.mktmpdir("rugged-config") + Rugged::Settings['search_path_global'] = path + Rugged::Settings['search_path_xdg'] = path + Rugged::Settings['search_path_system'] = path + end + super + end + # Automatically clean up created fixture repos after each test run def after_teardown Rugged::TestCase::FixtureRepo.teardown + FileUtils.remove_entry_secure(@configdir) super end From 23c6a2869c69e7b483b5f7213f0d0a5bf81e0b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 5 Aug 2021 07:50:25 +0200 Subject: [PATCH 2/3] test: create the global config situation we expect --- test/config_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/config_test.rb b/test/config_test.rb index 99ea9b032..2e4362a83 100644 --- a/test/config_test.rb +++ b/test/config_test.rb @@ -3,6 +3,16 @@ class ConfigTest < Rugged::TestCase def setup @repo = FixtureRepo.from_rugged("testrepo.git") + + path = Dir.mktmpdir("rugged-global-config") + cfg = Rugged::Config.new(File.join(path, ".gitconfig")) + cfg['user.name'] = "The test suite" + Rugged::Settings['search_path_global'] = path + @glocalconfigdir = path + end + + def cleanup + FileUtils.remove_entry_secure(@globalconfigdir) end def test_multi_fetch From bbc8fa7b18a0182326e0b0a607fa773632bc269c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 5 Aug 2021 08:11:33 +0200 Subject: [PATCH 3/3] ci: remove user.name setting we had to work around lack of isolation --- script/travisbuild | 2 -- 1 file changed, 2 deletions(-) diff --git a/script/travisbuild b/script/travisbuild index 152606e25..5c83d1116 100755 --- a/script/travisbuild +++ b/script/travisbuild @@ -26,6 +26,4 @@ echo 'PasswordAuthentication yes' | sudo tee -a /etc/sshd_config eval $(ssh-agent) ssh-add $GITTEST_REMOTE_SSH_KEY -# We need the config so the tests don't fail -git config --global user.name 'The rugged tests are fragile' bundle exec rake || exit $?