Caching can't work in async tests, so for them it is mocked to a null cache that is always empty. Synchronous tests are stubbed with the real Cachex, which is emptied after every test.stable
parent
713612c377
commit
95a9bdfc37
@ -0,0 +1,40 @@
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.CachexProxy do
|
||||
@behaviour Pleroma.Caching
|
||||
|
||||
@impl true
|
||||
defdelegate get!(cache, key), to: Cachex
|
||||
|
||||
@impl true
|
||||
defdelegate stream!(cache, key), to: Cachex
|
||||
|
||||
@impl true
|
||||
defdelegate put(cache, key, value, options), to: Cachex
|
||||
|
||||
@impl true
|
||||
defdelegate put(cache, key, value), to: Cachex
|
||||
|
||||
@impl true
|
||||
defdelegate get_and_update(cache, key, func), to: Cachex
|
||||
|
||||
@impl true
|
||||
defdelegate get(cache, key), to: Cachex
|
||||
|
||||
@impl true
|
||||
defdelegate fetch!(cache, key, func), to: Cachex
|
||||
|
||||
@impl true
|
||||
defdelegate expire_at(cache, str, num), to: Cachex
|
||||
|
||||
@impl true
|
||||
defdelegate exists?(cache, key), to: Cachex
|
||||
|
||||
@impl true
|
||||
defdelegate del(cache, key), to: Cachex
|
||||
|
||||
@impl true
|
||||
defdelegate execute!(cache, func), to: Cachex
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
Mox.defmock(Pleroma.CachexMock, for: Pleroma.Caching)
|
@ -0,0 +1,47 @@
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.NullCache do
|
||||
@moduledoc """
|
||||
A module simulating a permanently empty cache.
|
||||
"""
|
||||
@behaviour Pleroma.Caching
|
||||
|
||||
@impl true
|
||||
def get!(_, _), do: nil
|
||||
|
||||
@impl true
|
||||
def put(_, _, _, _ \\ nil), do: {:ok, true}
|
||||
|
||||
@impl true
|
||||
def stream!(_, _), do: []
|
||||
|
||||
@impl true
|
||||
def get(_, _), do: {:ok, nil}
|
||||
|
||||
@impl true
|
||||
def fetch!(_, _, func) do
|
||||
{_, res} = func.()
|
||||
res
|
||||
end
|
||||
|
||||
@impl true
|
||||
def get_and_update(_, _, func) do
|
||||
func.(nil)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def expire_at(_, _, _), do: {:ok, true}
|
||||
|
||||
@impl true
|
||||
def exists?(_, _), do: {:ok, false}
|
||||
|
||||
@impl true
|
||||
def execute!(_, func) do
|
||||
func.(:nothing)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def del(_, _), do: {:ok, true}
|
||||
end
|
Loading…
Reference in new issue