Merge branch 'ipfs-dialyzer-fixes' into 'develop'
IPFS uploader: dialyzer fixes See merge request pleroma/pleroma!4129
This commit is contained in:
commit
acde8d0e0c
5 changed files with 55 additions and 62 deletions
|
|
@ -14,25 +14,6 @@ defmodule Pleroma.Uploaders.IPFSTest do
|
|||
|
||||
alias Pleroma.UnstubbedConfigMock, as: Config
|
||||
|
||||
describe "get_final_url" do
|
||||
setup do
|
||||
Config
|
||||
|> expect(:get, fn [Pleroma.Uploaders.IPFS] ->
|
||||
[post_gateway_url: "http://localhost:5001"]
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "it returns the final url for put_file" do
|
||||
assert IPFS.put_file_endpoint() == "http://localhost:5001/api/v0/add"
|
||||
end
|
||||
|
||||
test "it returns the final url for delete_file" do
|
||||
assert IPFS.delete_file_endpoint() == "http://localhost:5001/api/v0/files/rm"
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_file/1" do
|
||||
setup do
|
||||
Config
|
||||
|
|
@ -71,8 +52,8 @@ defmodule Pleroma.Uploaders.IPFSTest do
|
|||
describe "put_file/1" do
|
||||
setup do
|
||||
Config
|
||||
|> expect(:get, fn [Pleroma.Uploaders.IPFS] ->
|
||||
[post_gateway_url: "http://localhost:5001"]
|
||||
|> expect(:get, fn [Pleroma.Uploaders.IPFS, :post_gateway_url] ->
|
||||
"http://localhost:5001"
|
||||
end)
|
||||
|
||||
file_upload = %Pleroma.Upload{
|
||||
|
|
@ -92,7 +73,11 @@ defmodule Pleroma.Uploaders.IPFSTest do
|
|||
|
||||
test "save file", %{file_upload: file_upload} do
|
||||
with_mock Pleroma.HTTP,
|
||||
post: fn "http://localhost:5001/api/v0/add", _mp, [], params: ["cid-version": "1"] ->
|
||||
post: fn "http://localhost:5001/api/v0/add",
|
||||
_mp,
|
||||
[],
|
||||
params: ["cid-version": "1"],
|
||||
pool: :upload ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
|
|
@ -107,7 +92,11 @@ defmodule Pleroma.Uploaders.IPFSTest do
|
|||
|
||||
test "returns error", %{file_upload: file_upload} do
|
||||
with_mock Pleroma.HTTP,
|
||||
post: fn "http://localhost:5001/api/v0/add", _mp, [], params: ["cid-version": "1"] ->
|
||||
post: fn "http://localhost:5001/api/v0/add",
|
||||
_mp,
|
||||
[],
|
||||
params: ["cid-version": "1"],
|
||||
pool: :upload ->
|
||||
{:error, "IPFS Gateway upload failed"}
|
||||
end do
|
||||
assert capture_log(fn ->
|
||||
|
|
@ -118,7 +107,11 @@ defmodule Pleroma.Uploaders.IPFSTest do
|
|||
|
||||
test "returns error if JSON decode fails", %{file_upload: file_upload} do
|
||||
with_mock Pleroma.HTTP, [],
|
||||
post: fn "http://localhost:5001/api/v0/add", _mp, [], params: ["cid-version": "1"] ->
|
||||
post: fn "http://localhost:5001/api/v0/add",
|
||||
_mp,
|
||||
[],
|
||||
params: ["cid-version": "1"],
|
||||
pool: :upload ->
|
||||
{:ok, %Tesla.Env{status: 200, body: "invalid"}}
|
||||
end do
|
||||
assert capture_log(fn ->
|
||||
|
|
@ -130,7 +123,11 @@ defmodule Pleroma.Uploaders.IPFSTest do
|
|||
|
||||
test "returns error if JSON body doesn't contain Hash key", %{file_upload: file_upload} do
|
||||
with_mock Pleroma.HTTP, [],
|
||||
post: fn "http://localhost:5001/api/v0/add", _mp, [], params: ["cid-version": "1"] ->
|
||||
post: fn "http://localhost:5001/api/v0/add",
|
||||
_mp,
|
||||
[],
|
||||
params: ["cid-version": "1"],
|
||||
pool: :upload ->
|
||||
{:ok, %Tesla.Env{status: 200, body: "{\"key\": \"value\"}"}}
|
||||
end do
|
||||
assert IPFS.put_file(file_upload) == {:error, "JSON doesn't contain Hash key"}
|
||||
|
|
@ -141,8 +138,8 @@ defmodule Pleroma.Uploaders.IPFSTest do
|
|||
describe "delete_file/1" do
|
||||
setup do
|
||||
Config
|
||||
|> expect(:get, fn [Pleroma.Uploaders.IPFS] ->
|
||||
[post_gateway_url: "http://localhost:5001"]
|
||||
|> expect(:get, fn [Pleroma.Uploaders.IPFS, :post_gateway_url] ->
|
||||
"http://localhost:5001"
|
||||
end)
|
||||
|
||||
:ok
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue