|
1 | | -defmodule ErlangSshBehaviour do |
2 | | - @moduledoc false |
| 1 | +require Gen |
3 | 2 |
|
4 | | - @type conn() :: term() |
| 3 | +Gen.defbehaviour(ErlangSsh.Behaviour, :ssh) |
| 4 | +Gen.defdelegated(ErlangSsh, :ssh, behaviour: ErlangSsh.Behaviour) |
| 5 | +Mox.defmock(MockErlangSsh, for: ErlangSsh.Behaviour) |
5 | 6 |
|
6 | | - @callback connect(binary(), integer(), keyword(), timeout()) :: {:ok, conn()} | {:error, term()} |
7 | | - @callback close(conn()) :: :ok |
8 | | -end |
| 7 | +Gen.defbehaviour(ErlangSshConnection.Behaviour, :ssh_connection) |
| 8 | +Gen.defdelegated(ErlangSshConnection, :ssh_connection, behaviour: ErlangSshConnection.Behaviour) |
| 9 | +Mox.defmock(MockErlangSshConnection, for: ErlangSshConnection.Behaviour) |
9 | 10 |
|
10 | | -defmodule ErlangSsh do |
11 | | - @moduledoc false |
12 | | - |
13 | | - @behaviour ErlangSshBehaviour |
14 | | - |
15 | | - defdelegate connect(host, port, options, timeout), to: :ssh |
16 | | - defdelegate close(conn), to: :ssh |
17 | | -end |
18 | | - |
19 | | -Mox.defmock(MockErlangSsh, for: ErlangSshBehaviour) |
20 | | - |
21 | | -defmodule ErlangSshConnectionBehaviour do |
22 | | - @moduledoc false |
23 | | - |
24 | | - @type conn() :: term() |
25 | | - @type chan() :: integer() |
26 | | - |
27 | | - @callback session_channel(conn(), integer(), integer(), timeout()) :: |
28 | | - {:ok, chan()} | {:error, term()} |
29 | | - @callback subsystem(conn(), chan(), charlist(), timeout()) :: |
30 | | - :success | :failure | {:error, :timeout} | {:error, :closed} |
31 | | - @callback close(conn(), chan()) :: :ok |
32 | | - @callback exec(conn(), chan(), binary(), timeout()) :: |
33 | | - :success | :failure | {:error, :timeout} | {:error, :closed} |
34 | | - @callback ptty_alloc(conn(), chan(), keyword(), timeout()) :: |
35 | | - :success | :failure | {:error, :timeout} | {:error, :closed} |
36 | | - @callback send(conn(), chan(), 0..1, binary(), timeout()) :: |
37 | | - :ok | {:error, :timeout} | {:error, :closed} |
38 | | - @callback send_eof(conn(), chan()) :: :ok | {:error, :closed} |
39 | | - @callback adjust_window(conn(), chan(), integer()) :: :ok |
40 | | -end |
41 | | - |
42 | | -defmodule ErlangSshConnection do |
43 | | - @moduledoc false |
44 | | - |
45 | | - @behaviour ErlangSshConnectionBehaviour |
46 | | - |
47 | | - defdelegate session_channel(conn, initial_window_size, max_packet_size, timeout), |
48 | | - to: :ssh_connection |
49 | | - |
50 | | - defdelegate subsystem(conn, chan, name, timeout), to: :ssh_connection |
51 | | - defdelegate close(conn, chan), to: :ssh_connection |
52 | | - defdelegate exec(conn, chan, command, timeout), to: :ssh_connection |
53 | | - defdelegate ptty_alloc(conn, chan, keyword, timeout), to: :ssh_connection |
54 | | - defdelegate send(conn, chan, type, data, timeout), to: :ssh_connection |
55 | | - defdelegate send_eof(conn, chan), to: :ssh_connection |
56 | | - defdelegate adjust_window(conn, chan, size), to: :ssh_connection |
57 | | -end |
58 | | - |
59 | | -Mox.defmock(MockErlangSshConnection, for: ErlangSshConnectionBehaviour) |
60 | | - |
61 | | -defmodule ErlangSshSftpBehaviour do |
62 | | - @moduledoc false |
63 | | - |
64 | | - @type conn() :: term() |
65 | | - @type chan() :: pid() |
66 | | - |
67 | | - # TODO |
68 | | - @callback start_channel(conn(), keyword()) :: {:ok, chan()} | {:error, term()} |
69 | | -end |
70 | | - |
71 | | -defmodule ErlangSshSftp do |
72 | | - @moduledoc false |
73 | | - |
74 | | - @behaviour ErlangSshSftpBehaviour |
75 | | - |
76 | | - defdelegate start_channel(conn, options), to: :ssh_sftp |
77 | | -end |
78 | | - |
79 | | -Mox.defmock(MockErlangSshSftp, for: ErlangSshSftpBehaviour) |
| 11 | +Gen.defbehaviour(ErlangSshSftp.Behaviour, :ssh_sftp) |
| 12 | +Gen.defdelegated(ErlangSshSftp, :ssh_sftp, behaviour: ErlangSshSftp.Behaviour) |
| 13 | +Mox.defmock(MockErlangSshSftp, for: ErlangSshSftp.Behaviour) |
0 commit comments