| 16 | # under the License. |
| 17 | |
| 18 | class PrepareTest < Test::Unit::TestCase |
| 19 | include GitRunnable |
| 20 | include VersionDetectable |
| 21 | |
| 22 | def setup |
| 23 | @current_commit = git_current_commit |
| 24 | detect_versions |
| 25 | |
| 26 | top_dir = Pathname(__dir__).parent.parent |
| 27 | @original_git_repository = top_dir + ".git" |
| 28 | Dir.mktmpdir do |dir| |
| 29 | @test_git_repository = Pathname(dir) + "arrow" |
| 30 | git("clone", @original_git_repository.to_s, @test_git_repository.to_s) |
| 31 | FileUtils.cp((top_dir + "dev" + "release" + ".env").to_s, |
| 32 | (@test_git_repository + "dev" + "release").to_s) |
| 33 | Dir.chdir(@test_git_repository) do |
| 34 | @release_branch = "testing-release-#{@release_version}-rc0" |
| 35 | git("checkout", "-b", @release_branch, @current_commit) |
| 36 | yield |
| 37 | end |
| 38 | FileUtils.rm_rf(@test_git_repository) |
| 39 | end |
| 40 | end |
| 41 | |
| 42 | def prepare(*targets) |
| 43 | if targets.last.is_a?(Hash) |
| 44 | additional_env = targets.pop |
| 45 | else |
| 46 | additional_env = {} |
| 47 | end |
| 48 | env = { "PREPARE_DEFAULT" => "0" } |
| 49 | targets.each do |target| |
| 50 | env["PREPARE_#{target}"] = "1" |
| 51 | end |
| 52 | env = env.merge(additional_env) |
| 53 | sh(env, "dev/release/01-prepare.sh", @release_version, @next_version, "0") |
| 54 | end |
| 55 | |
| 56 | data(:release_type, [nil, :major, :minor, :patch]) |
| 57 | def test_deb_package_names |
| 58 | omit_on_release_branch |
| 59 | current_commit = git_current_commit |
| 60 | stdout = prepare("DEB_PACKAGE_NAMES") |
| 61 | changes = parse_patch(git("log", "-p", "#{current_commit}..")) |
| 62 | sampled_changes = changes.collect do |change| |
| 63 | first_hunk = change[:hunks][0] |
| 64 | first_removed_line = first_hunk.find {|line| line.start_with?("-")} |
| 65 | first_added_line = first_hunk.find {|line| line.start_with?("+")} |
| 66 | last_hunk = change[:hunks][-1] |
| 67 | last_removed_line = last_hunk.find {|line| line.start_with?("-")} |
| 68 | last_added_line = last_hunk.find {|line| line.start_with?("+")} |
| 69 | { |
| 70 | first_sampled_diff: [first_removed_line, first_added_line], |
| 71 | last_sampled_diff: [last_removed_line, last_added_line], |
| 72 | path: change[:path], |
| 73 | } |
| 74 | end |
| 75 | case release_type |
no test coverage detected