Skip to content

Commit

Permalink
Setup endpoint and test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Jan 7, 2025
1 parent 20c9328 commit bc8d0cc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/uplink/nodes/router.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule Uplink.Nodes.Router do
use Plug.Router
use Uplink.Web

alias Uplink.Secret
alias Uplink.Clients.LXD

plug :match

plug Plug.Parsers,
parsers: [:urlencoded, :json],
body_reader: {Uplink.Web.CacheBodyReader, :read_body, []},
json_decoder: Jason

plug Secret.VerificationPlug

plug :dispatch

get "/" do
nodes =
LXD.list_cluster_members()
|> Enum.map(fn member ->
LXD.get_node(member.server_name)
end)

json(conn, :ok, %{data: nodes})
end
end
20 changes: 20 additions & 0 deletions test/uplink/nodes/router_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
defmodule Uplink.Nodes.RouterTest do
use ExUnit.Case
use Plug.Test

setup do
bypass = Bypass.open()

Cache.put(:self, %{
"credential" => %{
"endpoint" => "http://localhost:#{bypass.port}"
}
})

response = File.read!("test/fixtures/lxd/cluster/members/list.json")

Cache.delete(:cluster_members)

{:ok, bypass: bypass, response: response}
end
end

0 comments on commit bc8d0cc

Please sign in to comment.