Skip to content

Commit

Permalink
reformat files according to Elixir 1.16 Credo rules
Browse files Browse the repository at this point in the history
  • Loading branch information
tlux committed Feb 24, 2024
1 parent cbffd49 commit 0cfc348
Show file tree
Hide file tree
Showing 23 changed files with 150 additions and 150 deletions.
12 changes: 6 additions & 6 deletions lib/sftp_client/key_provider.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ defmodule SFTPClient.KeyProvider do
case File.read(full_path) do
{:ok, key_contents} ->
case decode_private_key_contents(key_contents, pass_phrase, algorithm) do
{:error, 'Unable to decode key'} = error ->
{:error, ~c"Unable to decode key"} = error ->
Logger.error("Unable to decode key: #{path}")
error

{:error, 'Passphrase required'} = error ->
{:error, ~c"Passphrase required"} = error ->
Logger.error("Passphrase required for key: #{path}")
error

Expand All @@ -59,7 +59,7 @@ defmodule SFTPClient.KeyProvider do

_ ->
Logger.error("Specified key not found: #{full_path}")
{:error, 'Key not found'}
{:error, ~c"Key not found"}
end
end

Expand All @@ -69,7 +69,7 @@ defmodule SFTPClient.KeyProvider do
|> List.first()
|> case do
nil ->
{:error, 'Unable to decode key'}
{:error, ~c"Unable to decode key"}

{{_, :new_openssh}, _key, _} ->
decode_new_openssh_private_key_contents(
Expand All @@ -82,7 +82,7 @@ defmodule SFTPClient.KeyProvider do
{:ok, :public_key.pem_entry_decode(entry)}

_entry when is_nil(pass_phrase) ->
{:error, 'Passphrase required'}
{:error, ~c"Passphrase required"}

entry ->
pass_phrase = String.to_charlist(pass_phrase)
Expand All @@ -105,7 +105,7 @@ defmodule SFTPClient.KeyProvider do
{decoded_key, _} <- List.first(decoded_keys) do
{:ok, decoded_key}
else
_result -> {:error, 'Unable to decode key'}
_result -> {:error, ~c"Unable to decode key"}
end
end
end
2 changes: 1 addition & 1 deletion lib/sftp_client/operations/list_dir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ defmodule SFTPClient.Operations.ListDir do

defp process_entries(entries) do
entries
|> Stream.reject(&(&1 in ['.', '..']))
|> Stream.reject(&(&1 in [~c".", ~c".."]))
|> Stream.map(&to_string/1)
|> Enum.sort()
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sftp_client/operations/read_dir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule SFTPClient.Operations.ReadDir do

defp process_entries(entries, dir_path) do
entries
|> Stream.reject(fn {filename, _} -> filename in ['.', '..'] end)
|> Stream.reject(fn {filename, _} -> filename in [~c".", ~c".."] end)
|> Stream.map(fn {filename, xfer_attr} ->
filename = to_string(filename)

Expand Down
4 changes: 2 additions & 2 deletions test/sftp_client/operation_util_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule SFTPClient.OperationUtilTest do

describe "handle_error/1" do
test "invalid option error" do
error = {:eoptions, {{:user_dir, 'my/key/path'}, :enoent}}
error = {:eoptions, {{:user_dir, ~c"my/key/path"}, :enoent}}

assert OperationUtil.handle_error(error) == %InvalidOptionError{
key: :user_dir,
Expand Down Expand Up @@ -64,7 +64,7 @@ defmodule SFTPClient.OperationUtilTest do
end

test "conn error" do
message = 'Something went wrong'
message = ~c"Something went wrong"

assert OperationUtil.handle_error(message) == %ConnError{
message: to_string(message)
Expand Down
46 changes: 23 additions & 23 deletions test/sftp_client/operations/connect_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ defmodule SFTPClient.Operations.ConnectTest do
{KeyProvider,
private_key_path: @config.private_key_path,
private_key_pass_phrase: @config.private_key_pass_phrase},
password: 'test-password',
password: ~c"test-password",
quiet_mode: true,
sftp_vsn: 2,
silently_accept_hosts: true,
system_dir: @config.system_dir |> Path.expand() |> String.to_charlist(),
user: 'test-user',
user: ~c"test-user",
user_dir: @config.user_dir |> Path.expand() |> String.to_charlist(),
user_interaction: false
]}
end

describe "connect/1" do
test "connect with SFTPClient.Config", %{opts: opts} do
expect(SFTPMock, :start_channel, fn 'test-host', 23, ^opts ->
expect(SFTPMock, :start_channel, fn ~c"test-host", 23, ^opts ->
{:ok, :channel_pid_stub, :conn_ref_stub}
end)

Expand All @@ -69,7 +69,7 @@ defmodule SFTPClient.Operations.ConnectTest do
end

test "connect with map options", %{opts: opts} do
expect(SFTPMock, :start_channel, fn 'test-host', 23, ^opts ->
expect(SFTPMock, :start_channel, fn ~c"test-host", 23, ^opts ->
{:ok, :channel_pid_stub, :conn_ref_stub}
end)

Expand All @@ -85,7 +85,7 @@ defmodule SFTPClient.Operations.ConnectTest do
end

test "connect with keyword options", %{opts: opts} do
expect(SFTPMock, :start_channel, fn 'test-host', 23, ^opts ->
expect(SFTPMock, :start_channel, fn ~c"test-host", 23, ^opts ->
{:ok, :channel_pid_stub, :conn_ref_stub}
end)

Expand All @@ -103,7 +103,7 @@ defmodule SFTPClient.Operations.ConnectTest do
test "omit option when nil", %{opts: opts} do
opts = Keyword.delete(opts, :user_dir)

expect(SFTPMock, :start_channel, fn 'test-host', 23, ^opts ->
expect(SFTPMock, :start_channel, fn ~c"test-host", 23, ^opts ->
{:ok, :channel_pid_stub, :conn_ref_stub}
end)

Expand All @@ -119,9 +119,9 @@ defmodule SFTPClient.Operations.ConnectTest do
end

test "connection error", %{opts: opts} do
message = 'Unable to connect using the available authentication methods'
message = ~c"Unable to connect using the available authentication methods"

expect(SFTPMock, :start_channel, fn 'test-host', 23, ^opts ->
expect(SFTPMock, :start_channel, fn ~c"test-host", 23, ^opts ->
{:error, message}
end)

Expand All @@ -130,8 +130,8 @@ defmodule SFTPClient.Operations.ConnectTest do
end

test "invalid option error", %{opts: opts} do
expect(SFTPMock, :start_channel, fn 'test-host', 23, ^opts ->
{:error, {:eoptions, {{:user_dir, 'my/key/path'}, :enoent}}}
expect(SFTPMock, :start_channel, fn ~c"test-host", 23, ^opts ->
{:error, {:eoptions, {{:user_dir, ~c"my/key/path"}, :enoent}}}
end)

assert Connect.connect(@config) ==
Expand Down Expand Up @@ -159,7 +159,7 @@ defmodule SFTPClient.Operations.ConnectTest do
describe "connect/2" do
test "success", %{opts: opts} do
SFTPMock
|> expect(:start_channel, fn 'test-host', 23, ^opts ->
|> expect(:start_channel, fn ~c"test-host", 23, ^opts ->
{:ok, :channel_pid_stub, :conn_ref_stub}
end)
|> expect(:stop_channel, fn :channel_pid_stub -> :ok end)
Expand All @@ -177,9 +177,9 @@ defmodule SFTPClient.Operations.ConnectTest do
end

test "connection error", %{opts: opts} do
message = 'Unable to connect using the available authentication methods'
message = ~c"Unable to connect using the available authentication methods"

expect(SFTPMock, :start_channel, fn 'test-host', 23, ^opts ->
expect(SFTPMock, :start_channel, fn ~c"test-host", 23, ^opts ->
{:error, message}
end)

Expand All @@ -194,7 +194,7 @@ defmodule SFTPClient.Operations.ConnectTest do

describe "connect!/1" do
test "connect with SFTPClient.Config", %{opts: opts} do
expect(SFTPMock, :start_channel, fn 'test-host', 23, ^opts ->
expect(SFTPMock, :start_channel, fn ~c"test-host", 23, ^opts ->
{:ok, :channel_pid_stub, :conn_ref_stub}
end)

Expand All @@ -207,7 +207,7 @@ defmodule SFTPClient.Operations.ConnectTest do
end

test "connect with map options", %{opts: opts} do
expect(SFTPMock, :start_channel, fn 'test-host', 23, ^opts ->
expect(SFTPMock, :start_channel, fn ~c"test-host", 23, ^opts ->
{:ok, :channel_pid_stub, :conn_ref_stub}
end)

Expand All @@ -222,7 +222,7 @@ defmodule SFTPClient.Operations.ConnectTest do
end

test "connect with keyword options", %{opts: opts} do
expect(SFTPMock, :start_channel, fn 'test-host', 23, ^opts ->
expect(SFTPMock, :start_channel, fn ~c"test-host", 23, ^opts ->
{:ok, :channel_pid_stub, :conn_ref_stub}
end)

Expand All @@ -237,9 +237,9 @@ defmodule SFTPClient.Operations.ConnectTest do
end

test "connection error", %{opts: opts} do
message = 'Unable to connect using the available authentication methods'
message = ~c"Unable to connect using the available authentication methods"

expect(SFTPMock, :start_channel, fn 'test-host', 23, ^opts ->
expect(SFTPMock, :start_channel, fn ~c"test-host", 23, ^opts ->
{:error, message}
end)

Expand All @@ -249,8 +249,8 @@ defmodule SFTPClient.Operations.ConnectTest do
end

test "invalid option error", %{opts: opts} do
expect(SFTPMock, :start_channel, fn 'test-host', 23, ^opts ->
{:error, {:eoptions, {{:user_dir, 'my/key/path'}, :enoent}}}
expect(SFTPMock, :start_channel, fn ~c"test-host", 23, ^opts ->
{:error, {:eoptions, {{:user_dir, ~c"my/key/path"}, :enoent}}}
end)

assert_raise InvalidOptionError,
Expand All @@ -271,7 +271,7 @@ defmodule SFTPClient.Operations.ConnectTest do
describe "connect!/2" do
test "success", %{opts: opts} do
SFTPMock
|> expect(:start_channel, fn 'test-host', 23, ^opts ->
|> expect(:start_channel, fn ~c"test-host", 23, ^opts ->
{:ok, :channel_pid_stub, :conn_ref_stub}
end)
|> expect(:stop_channel, fn :channel_pid_stub -> :ok end)
Expand All @@ -289,9 +289,9 @@ defmodule SFTPClient.Operations.ConnectTest do
end

test "connection error", %{opts: opts} do
message = 'Unable to connect using the available authentication methods'
message = ~c"Unable to connect using the available authentication methods"

expect(SFTPMock, :start_channel, fn 'test-host', 23, ^opts ->
expect(SFTPMock, :start_channel, fn ~c"test-host", 23, ^opts ->
{:error, message}
end)

Expand Down
8 changes: 4 additions & 4 deletions test/sftp_client/operations/delete_dir_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule SFTPClient.Operations.DeleteDirTest do
describe "delete_dir/2" do
test "success" do
expect(SFTPMock, :del_dir, fn :channel_pid_stub,
'my/test/path',
~c"my/test/path",
:infinity ->
:ok
end)
Expand All @@ -27,7 +27,7 @@ defmodule SFTPClient.Operations.DeleteDirTest do
reason = :error_stub

expect(SFTPMock, :del_dir, fn :channel_pid_stub,
'my/test/path',
~c"my/test/path",
:infinity ->
{:error, reason}
end)
Expand All @@ -40,7 +40,7 @@ defmodule SFTPClient.Operations.DeleteDirTest do
describe "delete_dir!/2" do
test "success" do
expect(SFTPMock, :del_dir, fn :channel_pid_stub,
'my/test/path',
~c"my/test/path",
:infinity ->
:ok
end)
Expand All @@ -52,7 +52,7 @@ defmodule SFTPClient.Operations.DeleteDirTest do
reason = :error_stub

expect(SFTPMock, :del_dir, fn :channel_pid_stub,
'my/test/path',
~c"my/test/path",
:infinity ->
{:error, reason}
end)
Expand Down
8 changes: 4 additions & 4 deletions test/sftp_client/operations/delete_file_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule SFTPClient.Operations.DeleteFileTest do
describe "delete_file/2" do
test "success" do
expect(SFTPMock, :delete, fn :channel_pid_stub,
'my/test/path',
~c"my/test/path",
:infinity ->
:ok
end)
Expand All @@ -27,7 +27,7 @@ defmodule SFTPClient.Operations.DeleteFileTest do
reason = :error_stub

expect(SFTPMock, :delete, fn :channel_pid_stub,
'my/test/path',
~c"my/test/path",
:infinity ->
{:error, reason}
end)
Expand All @@ -40,7 +40,7 @@ defmodule SFTPClient.Operations.DeleteFileTest do
describe "delete_file!/2" do
test "success" do
expect(SFTPMock, :delete, fn :channel_pid_stub,
'my/test/path',
~c"my/test/path",
:infinity ->
:ok
end)
Expand All @@ -52,7 +52,7 @@ defmodule SFTPClient.Operations.DeleteFileTest do
reason = :error_stub

expect(SFTPMock, :delete, fn :channel_pid_stub,
'my/test/path',
~c"my/test/path",
:infinity ->
{:error, reason}
end)
Expand Down

0 comments on commit 0cfc348

Please sign in to comment.