From f4734896339f332c1cbb25b57cf3c0e759c996b1 Mon Sep 17 00:00:00 2001 From: Zack Siri Date: Thu, 9 Jan 2025 16:51:33 +0700 Subject: [PATCH] Setup test case and bypass for uplink nodes listing --- test/fixtures/instellar/monitors/list.json | 0 test/uplink/availability_test.exs | 36 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 test/fixtures/instellar/monitors/list.json diff --git a/test/fixtures/instellar/monitors/list.json b/test/fixtures/instellar/monitors/list.json new file mode 100644 index 00000000..e69de29b diff --git a/test/uplink/availability_test.exs b/test/uplink/availability_test.exs index f7c1d0b9..63a760bc 100644 --- a/test/uplink/availability_test.exs +++ b/test/uplink/availability_test.exs @@ -1,2 +1,38 @@ defmodule Uplink.AvailabilityTest do + use ExUnit.Case + + alias Uplink.Availability + + 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} + end + + describe "check availability of the nodes in the cluster" do + test "return availability check result", %{ + bypass: bypass, + response: 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, response) + end) + + assert {:ok, result} = Availability.check!() + end + end end