|
| 1 | +defmodule ReleaseHexTest do |
| 2 | + use ExUnit.Case, async: true |
| 3 | + |
| 4 | + @script Path.expand("../../scripts/release_hex.sh", __DIR__) |
| 5 | + |
| 6 | + test "OTP-specific archives are built with the canonical internal directory" do |
| 7 | + tmp = Path.join(System.tmp_dir!(), "hex-release-#{System.unique_integer([:positive])}") |
| 8 | + bin = Path.join(tmp, "bin") |
| 9 | + |
| 10 | + on_exit(fn -> File.rm_rf!(tmp) end) |
| 11 | + |
| 12 | + File.rm_rf!(tmp) |
| 13 | + File.mkdir_p!(bin) |
| 14 | + File.mkdir_p!(Path.join(tmp, "tmp")) |
| 15 | + |
| 16 | + docker_log = Path.join(tmp, "docker.log") |
| 17 | + write_aws_stub(Path.join(bin, "aws")) |
| 18 | + write_docker_stub(Path.join(bin, "docker")) |
| 19 | + |
| 20 | + path = bin <> ":" <> System.get_env("PATH", "") |
| 21 | + |
| 22 | + {output, status} = |
| 23 | + System.cmd("bash", [@script, "--dry-run", "2.4.3"], |
| 24 | + cd: tmp, |
| 25 | + env: [{"PATH", path}, {"HEX_RELEASE_TEST_DOCKER_LOG", docker_log}], |
| 26 | + stderr_to_stdout: true |
| 27 | + ) |
| 28 | + |
| 29 | + assert status == 0, output |
| 30 | + |
| 31 | + docker_commands = File.read!(docker_log) |
| 32 | + |
| 33 | + assert docker_commands =~ "MIX_ENV=prod mix archive.build -o hex-2.4.3.ez" |
| 34 | + refute docker_commands =~ "MIX_ENV=prod mix archive.build -o hex-2.4.3-otp-" |
| 35 | + |
| 36 | + archives = Path.wildcard(Path.join([tmp, "tmp", "installs", "*", "hex-2.4.3-otp-*.ez"])) |
| 37 | + |
| 38 | + assert archives != [] |
| 39 | + assert Enum.all?(archives, &(File.read!(&1) == "hex-2.4.3.ez\n")) |
| 40 | + end |
| 41 | + |
| 42 | + defp write_aws_stub(path) do |
| 43 | + File.write!(path, """ |
| 44 | + #!/bin/sh |
| 45 | + if [ "$1" = "s3" ] && [ "$2" = "cp" ]; then |
| 46 | + src="$3" |
| 47 | + dest="$4" |
| 48 | +
|
| 49 | + case "$src" in |
| 50 | + s3://*) |
| 51 | + mkdir -p "$(dirname "$dest")" |
| 52 | + : > "$dest" |
| 53 | + exit 0 |
| 54 | + ;; |
| 55 | + esac |
| 56 | + fi |
| 57 | +
|
| 58 | + exit 0 |
| 59 | + """) |
| 60 | + |
| 61 | + File.chmod!(path, 0o755) |
| 62 | + end |
| 63 | + |
| 64 | + defp write_docker_stub(path) do |
| 65 | + File.write!(path, """ |
| 66 | + #!/bin/sh |
| 67 | + printf '%s\\n' "$*" >> "$HEX_RELEASE_TEST_DOCKER_LOG" |
| 68 | +
|
| 69 | + cmd="" |
| 70 | + while [ "$#" -gt 0 ]; do |
| 71 | + if [ "$1" = "-c" ]; then |
| 72 | + shift |
| 73 | + cmd="$1" |
| 74 | + break |
| 75 | + fi |
| 76 | +
|
| 77 | + shift |
| 78 | + done |
| 79 | +
|
| 80 | + output=$(printf '%s\\n' "$cmd" | sed -n 's/.*mix archive.build -o \\([^ "]*\\).*/\\1/p') |
| 81 | +
|
| 82 | + if [ -n "$output" ]; then |
| 83 | + printf '%s\\n' "$output" > "$output" |
| 84 | + fi |
| 85 | +
|
| 86 | + exit 0 |
| 87 | + """) |
| 88 | + |
| 89 | + File.chmod!(path, 0o755) |
| 90 | + end |
| 91 | +end |
0 commit comments