Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isolate the configuration in the tests #883

Merged
merged 3 commits into from Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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