Skip to content

Commit

Permalink
Safely start installer processes that will exit abnormally for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mobileoverlord committed Sep 4, 2024
1 parent bcf2d56 commit 53ab4c7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions test/peridiod/binary/installer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Peridiod.Binary.InstallerTest do
setup :setup_fwup

test "install task upgrade", %{binary_metadata: binary_metadata, opts: opts} = context do
Installer.start_link(binary_metadata, opts)
spawn_installer(binary_metadata, opts)
prn = binary_metadata.prn
assert_receive {Installer, ^prn, :complete}
assert File.exists?(context.upgrade_file)
Expand All @@ -21,8 +21,7 @@ defmodule Peridiod.Binary.InstallerTest do
@tag capture_log: true
test "install task error", %{binary_metadata: binary_metadata, opts: opts} do
binary_metadata = update_installer_opts(binary_metadata, "task", "does_not_exist")
Installer.start_link(binary_metadata, opts)

spawn_installer(binary_metadata, opts)
assert_receive {Installer, _, {:error, error}}
assert error =~ "does_not_exist"
end
Expand All @@ -31,8 +30,7 @@ defmodule Peridiod.Binary.InstallerTest do
test "invalid signature", %{binary_metadata: binary_metadata, opts: opts} do
untrusted = TestFixtures.untrusted_release_binary() |> Binary.metadata_from_manifest()
binary_metadata = Map.put(binary_metadata, :signatures, untrusted.signatures)
Installer.start_link(binary_metadata, opts)

spawn_installer(binary_metadata, opts)
assert_receive {Installer, _, {:error, :invalid_signature}}
end
end
Expand Down Expand Up @@ -68,4 +66,9 @@ defmodule Peridiod.Binary.InstallerTest do

%{binary_metadata | custom_metadata: custom_metadata}
end

defp spawn_installer(binary_metadata, opts) do
opts = Map.put(opts, :callback, self())
spawn(fn -> Installer.start_link(binary_metadata, opts) end)
end
end

0 comments on commit 53ab4c7

Please sign in to comment.