Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akoutmos committed Oct 8, 2022
1 parent ed14033 commit aca77ff
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
25 changes: 25 additions & 0 deletions lib/github_release_fetcher/test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,29 @@ defmodule GithubReleaseFetcher.Test do
end
end
end

@doc """
Test that the specified version can be downloaded
"""
def test_version_for_current_platform(downloader_module, version) do
# Create a place to store the file downloads
tmp_github_release_fetcher_dir = Path.join(System.tmp_dir!(), "/github_release_fetcher_test_downloads")
File.mkdir_p!(tmp_github_release_fetcher_dir)

try do
# A dir for the output of the current build
current_build_output_dir = Path.join(tmp_github_release_fetcher_dir, version)
File.mkdir_p!(current_build_output_dir)

assert {:ok, _successful_files, _failed_files} =
downloader_module.download(current_build_output_dir, override_version: version)

File.rm_rf!(current_build_output_dir)
after
# Delete all of the file downloads
if File.exists?(tmp_github_release_fetcher_dir) do
File.rm_rf!(tmp_github_release_fetcher_dir)
end
end
end
end
12 changes: 9 additions & 3 deletions test/github_release_fetcher_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@ defmodule GithubReleaseFetcherTest do
github_repo: "benbjohnson/litestream",
download_versions: %{
"0.3.9" => [
{:linux, :amd64, "806e1cca4a2a105a36f219a4c212a220569d50a8f13f45f38ebe49e6699ab99f"}
{:linux, :amd64, "806e1cca4a2a105a36f219a4c212a220569d50a8f13f45f38ebe49e6699ab99f"},
{:macos, :amd64, "74599a34dc440c19544f533be2ef14cd4378ec1969b9b4fcfd24158946541869"},
{:macos, :arm64, "74599a34dc440c19544f533be2ef14cd4378ec1969b9b4fcfd24158946541869"}
],
"0.3.8" => [
{:linux, :amd64, "530723d95a51ee180e29b8eba9fee8ddafc80a01cab7965290fb6d6fc31381b3"}
]
}

@impl true
def download_name(version, :macos, arch), do: "litestream-v#{version}-darwin-#{arch}.zip"
def download_name(version, :macos, _arch), do: "litestream-v#{version}-darwin-amd64.zip"
def download_name(version, :linux, arch), do: "litestream-v#{version}-linux-#{arch}.tar.gz"
end

test "greets the world" do
test "Should download all of the specified versions" do
GithubReleaseFetcher.Test.test_all_supported_downloads(Litestream.Fetcher)
end

test "Should download the specified version on the current platform" do
GithubReleaseFetcher.Test.test_version_for_current_platform(Litestream.Fetcher, "0.3.9")
end
end

0 comments on commit aca77ff

Please sign in to comment.