Skip to content

Commit

Permalink
Add ability to patch instance
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Jul 17, 2024
1 parent 1f0205f commit 14c2120
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/lexdee.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ defmodule Lexdee do
to: Instances,
as: :create

defdelegate update_instance(client, id, params, opts \\ []),
to: Instances,
as: :update

defdelegate show_instance_log(client, instance, file_name, opts \\ []),
to: Instances.Logs,
as: :show
Expand Down
5 changes: 5 additions & 0 deletions lib/lexdee/instances.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ defmodule Lexdee.Instances do
def create(client, params, opts \\ []),
do: post(client, @path, params, opts)

@spec update(Tesla.Client.t(), binary(), map, Keyword.t()) ::
{:error, any} | {:ok, Tesla.Env.t()}
def update(client, id, params, options \\ []),
do: patch(client, Path.join(@path, id), params, options)

@spec remove(Tesla.Client.t(), binary(), Keyword.t()) ::
{:ok, Tesla.Env.t()} | {:error, any()}
def remove(client, id, options \\ []),
Expand Down
38 changes: 38 additions & 0 deletions test/lexdee/instances_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,44 @@ defmodule Lexdee.InstancesTest do
end
end

describe "update instance" do
setup do
response =
File.read!("test/support/fixtures/responses/instances/update.json")

{:ok, response: response}
end

test "return success for updated instance", %{
bypass: bypass,
client: client,
response: response
} do
Bypass.expect(
bypass,
"PATCH",
"/1.0/instances/something",
fn conn ->
assert conn.query_string == "target=lxd-experiment"

conn
|> Plug.Conn.put_resp_header("content-type", "application/json")
|> Plug.Conn.resp(200, response)
end
)

assert {:ok, _data} =
Lexdee.update_instance(
client,
"something",
%{
"profiles" => ["some-profile"]
},
query: [target: "lxd-experiment"]
)
end
end

describe "delete instance" do
setup do
response =
Expand Down
5 changes: 5 additions & 0 deletions test/support/fixtures/responses/instances/update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"status": "Success",
"status_code": 200,
"type": "sync"
}

0 comments on commit 14c2120

Please sign in to comment.