Commit 1a4a026e authored by minibikini's avatar minibikini

improve tests

parent 0bc3b77c
# PleromaJobQueue: A lightweight job queue
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule PleromaJobQueue.InstallVersionTest do
use ExUnit.Case, async: true
describe("install version check") do
test "README.md" do
assert_version("README.md")
end
test "lib/pleroma_job_queue.ex" do
assert_version("lib/pleroma_job_queue.ex")
end
end
defp assert_version(filename) do
app = Keyword.get(Mix.Project.config(), :app)
app_version = app |> Application.spec(:vsn) |> to_string()
file = File.read!(filename)
[_, file_versions] = Regex.run(~r/{:#{app}, "(.+)"}/, file)
assert Version.match?(
app_version,
file_versions
),
"""
Install version constraint in `#{filename}` does not match to current app version.
Current App Version: #{app_version}
`#{filename}` Install Versions: #{file_versions}
"""
end
end
......@@ -6,12 +6,12 @@ defmodule PleromaJobQueueTest do
use ExUnit.Case
defmodule Worker do
defp pid, do: Application.get_env(:test, :pid)
defp pid, do: Application.get_env(:pleroma_job_queue, :test_pid)
def perform, do: send(pid(), {:test, :no_args})
def perform(:skip), do: nil
def perform(:test_job), do: send(pid(), {:test, :test_job})
def perform(:test_job, a, b), do: send(pid(), {:test, {a, b}})
def perform(:test_job), do: send(pid(), :test_job)
def perform(:test_job, a, b), do: send(pid(), {:test_job, {a, b}})
def perform(:priority, priority), do: send(pid(), {:priority, priority})
end
......@@ -21,24 +21,23 @@ defmodule PleromaJobQueueTest do
set_pid()
assert :ok == PleromaJobQueue.enqueue(@queue_name, Worker)
assert :no_args == receive_result(:test)
assert_receive {:test, :no_args}
assert :ok == PleromaJobQueue.enqueue(@queue_name, Worker, [:test_job])
assert :test_job == receive_result(:test)
assert_receive :test_job
assert :ok == PleromaJobQueue.enqueue(@queue_name, Worker, [:test_job, :foo, :bar])
assert {:foo, :bar} == receive_result(:test)
assert_receive {:test_job, {:foo, :bar}}
end
test "max_jobs/1" do
assert Application.get_env(:pleroma_job_queue, @queue_name, 0) ==
assert Application.get_env(:pleroma_job_queue, @queue_name, 1) ==
PleromaJobQueue.max_jobs(@queue_name)
end
test "priority" do
set_pid()
PleromaJobQueue.enqueue(@queue_name, Worker, [:skip], 10)
PleromaJobQueue.enqueue(@queue_name, Worker, [:skip], 11)
PleromaJobQueue.enqueue(@queue_name, Worker, [:priority, 12], 12)
PleromaJobQueue.enqueue(@queue_name, Worker, [:priority, 13], 13)
......@@ -52,50 +51,9 @@ defmodule PleromaJobQueueTest do
PleromaJobQueue.enqueue(@queue_name, Worker, [:priority, 19], 19)
PleromaJobQueue.enqueue(@queue_name, Worker, [:priority, 1], 1)
assert 1 == receive_result(:priority)
assert_receive {:priority, priority}
assert priority == 1
end
test "README install version check" do
app = Keyword.get(Mix.Project.config(), :app)
app_version = app |> Application.spec(:vsn) |> to_string()
readme = File.read!("README.md")
[_, readme_versions] = Regex.run(~r/{:#{app}, "(.+)"}/, readme)
assert Version.match?(
app_version,
readme_versions
),
"""
Install version constraint in README.md does not match to current app version.
Current App Version: #{app_version}
Readme Install Versions: #{readme_versions}
"""
end
test "lib/pleroma_job_queue.ex install version check" do
app = Keyword.get(Mix.Project.config(), :app)
app_version = app |> Application.spec(:vsn) |> to_string()
readme = File.read!("lib/pleroma_job_queue.ex")
[_, readme_versions] = Regex.run(~r/{:#{app}, "(.+)"}/, readme)
assert Version.match?(
app_version,
readme_versions
),
"""
Install version constraint in `lib/pleroma_job_queue.ex` does not match to current app version.
Current App Version: #{app_version}
`lib/pleroma_job_queue.ex` Install Versions: #{readme_versions}
"""
end
defp receive_result(name) do
receive do
{^name, value} -> value
end
end
defp set_pid, do: Application.put_env(:test, :pid, self())
defp set_pid, do: Application.put_env(:pleroma_job_queue, :test_pid, self())
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment