From 76226c618f0b6085c5a356552ffd59fcb73925a5 Mon Sep 17 00:00:00 2001 From: Zack Siri Date: Fri, 10 Jan 2025 13:27:47 +0700 Subject: [PATCH] Update test case for availability --- test/uplink/availability_test.exs | 2 +- test/uplink/nodes/router_test.exs | 91 ------------------------------- 2 files changed, 1 insertion(+), 92 deletions(-) delete mode 100644 test/uplink/nodes/router_test.exs diff --git a/test/uplink/availability_test.exs b/test/uplink/availability_test.exs index aad8280..6c41fd9 100644 --- a/test/uplink/availability_test.exs +++ b/test/uplink/availability_test.exs @@ -93,7 +93,7 @@ defmodule Uplink.AvailabilityTest do assert {:ok, resources} = Availability.check!() - assert [%Availability.Resource{} = resource] = resources + assert [%Availability.Resource{}] = resources end end end diff --git a/test/uplink/nodes/router_test.exs b/test/uplink/nodes/router_test.exs deleted file mode 100644 index 6ba0336..0000000 --- a/test/uplink/nodes/router_test.exs +++ /dev/null @@ -1,91 +0,0 @@ -defmodule Uplink.Nodes.RouterTest do - use ExUnit.Case - use Plug.Test - - alias Uplink.Cache - alias Uplink.Nodes.Router - - @opts Router.init([]) - - @valid_body Jason.encode!(%{ - "actor" => %{ - "provider" => "instellar", - "identifier" => "zacksiri", - "id" => "1" - } - }) - - setup do - bypass = Bypass.open() - - Cache.put(:self, %{ - "credential" => %{ - "endpoint" => "http://localhost:#{bypass.port}" - } - }) - - members_response = File.read!("test/fixtures/lxd/cluster/members/list.json") - - resource_response = File.read!("test/fixtures/lxd/resources/show.json") - - Cache.delete(:cluster_members) - - {:ok, - bypass: bypass, - members_response: members_response, - resource_response: resource_response} - end - - describe "list nodes" do - setup do - signature = - :crypto.mac(:hmac, :sha256, Uplink.Secret.get(), @valid_body) - |> Base.encode16() - |> String.downcase() - - {:ok, signature: signature} - end - - test "can successfully fetch list of nodes", %{ - bypass: bypass, - signature: signature, - members_response: members_response, - resource_response: resource_response - } do - Bypass.expect_once(bypass, "GET", "/1.0/cluster/members", fn conn -> - assert %{"recursion" => "1"} = conn.query_params - - conn - |> Plug.Conn.put_resp_header("content-type", "application/json") - |> Plug.Conn.resp(200, members_response) - end) - - Bypass.expect_once(bypass, "GET", "/1.0/resources", fn conn -> - assert %{"target" => "ubuntu-s-1vcpu-1gb-sgp1-01"} = conn.params - - conn - |> Plug.Conn.put_resp_header("content-type", "application/json") - |> Plug.Conn.resp(200, resource_response) - end) - - conn = - conn(:post, "/", @valid_body) - |> put_req_header("x-uplink-signature-256", "sha256=#{signature}") - |> put_req_header("content-type", "application/json") - |> Router.call(@opts) - - assert %{"data" => nodes} = Jason.decode!(conn.resp_body) - - [node] = nodes - - assert %{ - "cpu_cores_count" => _, - "name" => _, - "total_memory" => _, - "total_storage" => _ - } = node - - assert conn.status == 200 - end - end -end