diff --git a/spec/octocatalog-diff/fixtures/git-repos/simple-repo.tgz b/spec/octocatalog-diff/fixtures/git-repos/simple-repo.tgz new file mode 100644 index 00000000..4e676d00 Binary files /dev/null and b/spec/octocatalog-diff/fixtures/git-repos/simple-repo.tgz differ diff --git a/spec/octocatalog-diff/tests/spec_helper.rb b/spec/octocatalog-diff/tests/spec_helper.rb index 09340211..4cef0918 100644 --- a/spec/octocatalog-diff/tests/spec_helper.rb +++ b/spec/octocatalog-diff/tests/spec_helper.rb @@ -2,6 +2,7 @@ require 'logger' require 'rspec' require 'rspec/retry' +require 'rubygems/package' require 'tempfile' require 'tmpdir' @@ -210,7 +211,7 @@ def self.test_command(command) # Check out fixture repo. The repository is a tarball; this extracts it to a temporary directory and returns # the path where it was checked out. If the checkout fails, returns nil. Note: Be sure to include code in the # caller to clean up the temporary directory upon exit. - # @param repo [String] Name of repository (in fixtures/git-repos/{repo}.tar) + # @param repo [String] Name of repository (in fixtures/git-repos/{repo}.tgz) # @return [String] Path to checkout def self.extract_fixture_repo(repo) # If tar isn't here, don't do this @@ -218,15 +219,14 @@ def self.extract_fixture_repo(repo) return nil unless has_tar.nil? # Make sure tarball is there - repo_tarball = fixture_path("git-repos/#{repo}.tar") + repo_tarball = fixture_path("git-repos/#{repo}.tgz") raise Errno::ENOENT, "Repo tarball for #{repo} not found in #{repo_tarball}" unless File.file?(repo_tarball) # Extract to temporary directory extract_dir = Dir.mktmpdir - cmd = "tar -xf #{Shellwords.escape(repo_tarball)}" - extract_result, extract_code = Open3.capture2e(cmd, chdir: extract_dir) - return extract_dir if extract_code.exitstatus.zero? - raise "Failed to extract #{repo_tarball}: #{extract_result} (#{extract_code.exitstatus})" + io = File.open(repo_tarball, 'rb') + Gem::Package.new("").extract_tar_gz(io, extract_dir) + return extract_dir end # Clean up a temporary directory. This does nothing if the directory doesn't exist, or if it's nil.