Sha256: 56a7cb07fb9f04efa60a701f98ace4c0c3c4f3373a195efc7a9bbfd089a77aab

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

require 'fileutils'

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

3 entries across 3 versions & 1 rubygems

Version Path
git_local-0.0.4 lib/git_local/test_helpers.rb
git_local-0.0.3 lib/git_local/test_helpers.rb
git_local-0.0.2 lib/git_local/test_helpers.rb