Skip to content

Commit

Permalink
Merge pull request #883 from libgit2/cmn/isolate-config-tests
Browse files Browse the repository at this point in the history
Isolate the configuration in the tests
  • Loading branch information
carlosmn committed Aug 5, 2021
2 parents 98dfda8 + bbc8fa7 commit 31a4ff7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 0 additions & 2 deletions script/travisbuild
Expand Up @@ -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 $?
10 changes: 10 additions & 0 deletions test/config_test.rb
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions test/test_helper.rb
Expand Up @@ -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

Expand Down

0 comments on commit 31a4ff7

Please sign in to comment.