Module: GitLocal::TestHelpers

Defined in:
lib/git_local/test_helpers.rb

Instance Method Summary collapse

Instance Method Details

#create_file(path, size = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/git_local/test_helpers.rb', line 28

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

#create_git_repository(org:, repo:, branch:, local_directory:, file_paths: [], size: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/git_local/test_helpers.rb', line 5

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

#remove_all_repositories(path) ⇒ Object



23
24
25
26
# File 'lib/git_local/test_helpers.rb', line 23

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

#write_local_git_file(org:, repo:, branch:, file_path:, file_contents:, local_directory:) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/git_local/test_helpers.rb', line 15

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