test: Uisp.ConfigSnapshot.sync_configs success and error branches
This commit is contained in:
parent
dc72689aa9
commit
6481801447
1 changed files with 66 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ defmodule Towerops.Uisp.ConfigSnapshotTest do
|
||||||
use Towerops.DataCase, async: true
|
use Towerops.DataCase, async: true
|
||||||
use ExUnitProperties
|
use ExUnitProperties
|
||||||
|
|
||||||
|
alias Towerops.Uisp.Client
|
||||||
alias Towerops.Uisp.ConfigSnapshot
|
alias Towerops.Uisp.ConfigSnapshot
|
||||||
|
|
||||||
describe "compute_diff/2" do
|
describe "compute_diff/2" do
|
||||||
|
|
@ -200,6 +201,71 @@ defmodule Towerops.Uisp.ConfigSnapshotTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "sync_configs/2" do
|
||||||
|
setup do
|
||||||
|
user = Towerops.AccountsFixtures.user_fixture()
|
||||||
|
org = Towerops.OrganizationsFixtures.organization_fixture(user.id)
|
||||||
|
|
||||||
|
{:ok, site} =
|
||||||
|
Towerops.Sites.create_site(%{
|
||||||
|
name: "S-sync #{System.unique_integer([:positive])}",
|
||||||
|
organization_id: org.id
|
||||||
|
})
|
||||||
|
|
||||||
|
device =
|
||||||
|
Towerops.DevicesFixtures.device_fixture(%{
|
||||||
|
organization_id: org.id,
|
||||||
|
site_id: site.id,
|
||||||
|
name: "uisp-#{System.unique_integer([:positive])}"
|
||||||
|
})
|
||||||
|
|
||||||
|
integration = %{
|
||||||
|
credentials: %{
|
||||||
|
"url" => "http://uisp.example.com",
|
||||||
|
"api_key" => "test-key"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%{integration: integration, device: device}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "stores configs and counts stored vs unchanged", %{
|
||||||
|
integration: integration,
|
||||||
|
device: device
|
||||||
|
} do
|
||||||
|
counter = :counters.new(1, [:atomics])
|
||||||
|
|
||||||
|
Req.Test.stub(Client, fn conn ->
|
||||||
|
:counters.add(counter, 1, 1)
|
||||||
|
# Each request returns a different config so first store, second unchanged
|
||||||
|
Req.Test.json(conn, %{"id" => "uisp-1", "name" => "AP", "version" => 1})
|
||||||
|
end)
|
||||||
|
|
||||||
|
device_map = %{"uisp-1" => device}
|
||||||
|
|
||||||
|
assert {:ok, %{stored: 1, unchanged: 0}} =
|
||||||
|
ConfigSnapshot.sync_configs(integration, device_map)
|
||||||
|
|
||||||
|
# Same config — should be unchanged
|
||||||
|
assert {:ok, %{stored: 0, unchanged: 1}} =
|
||||||
|
ConfigSnapshot.sync_configs(integration, device_map)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "skips devices when fetch_device_config errors", %{
|
||||||
|
integration: integration,
|
||||||
|
device: device
|
||||||
|
} do
|
||||||
|
Req.Test.stub(Client, fn conn ->
|
||||||
|
Req.Test.transport_error(conn, :econnrefused)
|
||||||
|
end)
|
||||||
|
|
||||||
|
device_map = %{"uisp-1" => device}
|
||||||
|
|
||||||
|
assert {:ok, %{stored: 0, unchanged: 0}} =
|
||||||
|
ConfigSnapshot.sync_configs(integration, device_map)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "diff_snapshots/2" do
|
describe "diff_snapshots/2" do
|
||||||
setup do
|
setup do
|
||||||
user = Towerops.AccountsFixtures.user_fixture()
|
user = Towerops.AccountsFixtures.user_fixture()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue