Sha256: 52b89adc47657e255c17f28ac5f28a3900d0f54c4f3f75a45b9864341f9f5a38

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

require "fileutils"
require "securerandom"

module GitLocal
  module TestHelpers
    def create_git_repository(org:, repo:, branch:, local_directory:, file_paths: [], size: nil)
      repo_path = GitLocal::Repository.new(org: org, repo: repo, branch: branch, local_directory: local_directory).path

      FileUtils.mkdir_p(repo_path)

      file_paths.each do |file_path|
        create_file("#{repo_path}/#{file_path}", size)
      end
    end

    def write_local_git_file(org:, repo:, branch:, file_path:, file_contents:, local_directory:)
      repo_path = GitLocal::Repository.new(org: org, repo: repo, branch: branch, local_directory: local_directory).path

      file = File.open("#{repo_path}/#{file_path}", "w")
      file.puts(file_contents)
      file.close
    end

    def remove_all_repositories(path)
      repositories = File.join(path, "**", "*")
      FileUtils.rm_rf Dir.glob(repositories)
    end

    def create_file(path, size = nil)
      dir = File.dirname(path)

      FileUtils.mkdir_p(dir) unless File.directory?(dir)

      File.new(path, "w")

      return if size.nil?

      File.open(path, "wb") do |f|
        size.to_i.times { f.write(SecureRandom.random_bytes(2**20)) }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
git_local-0.0.9 lib/git_local/test_helpers.rb
git_local-0.0.8 lib/git_local/test_helpers.rb
git_local-0.0.7 lib/git_local/test_helpers.rb
git_local-0.0.6 lib/git_local/test_helpers.rb
git_local-0.0.5 lib/git_local/test_helpers.rb