SaltDns. Knot. Fake
(Salt v1.0.0)
In-memory SaltDns.Knot for unit tests.
It models the parts of Knot that the bridge depends on and returns the same tagged errors as the real adapter when the transaction discipline is broken:
- at most one configuration transaction at a time, globally
(
{:error, :transaction_in_progress}) - at most one transaction per zone (
{:error, :transaction_in_progress}) - a zone transaction needs a configured zone (
{:error, :no_such_zone}) - a record set shares one TTL; adding an existing record and removing an absent one succeed
- DNSSEC:
set_dnssec/2takes the global configuration lock; switching on creates a KSK in:readyand a ZSK in:active,ksk_submitted/1makes the KSK:active(and is{:error, :no_ksk_ready}otherwise),ds_records/1returns a stable fake DS for the KSK, switching off drops the keys. Signing records are not materialised inread_zone/1. - every commit raises the SOA serial (unixtime policy: the larger of now and previous + 1), unless the transaction wrote the SOA itself
Like SaltDns.Knot.Knotc, ensure_zone/2 and remove_zone/1 take the
global configuration lock, and apply_changes/2 holds a zone transaction,
as separate steps. Two callers that overlap therefore collide here exactly
as they would on a real Knot. Violations are also recorded and available
from violations/0.
Tests drive it with start_supervised!(SaltDns.Knot.Fake) and
config :salt_dns, :knot_adapter, SaltDns.Knot.Fake.
Summary
Functions
Returns a specification to start this module under a supervisor.
Makes the next op (:ensure_zone, :remove_zone, :apply_changes, :read_zone, :set_dnssec, :ksk_submitted, :sync_organisation) fail with reason.
The zones this Fake follows (set by follow/2), sorted.
Test control: while on, follow/2 calls wait (the Fake answers them when it is turned
off again). Promotion and demotion both call it, so a test can stop a replica in the
middle of a transition and look at it there.
Every operation applied so far, oldest first (for ordering assertions).
The last spec written for the organisation, or nil.
The address point_peer/1 last set, or nil.
Sets the edges edges/0 reports (a list of SaltDns.Knot.edge/0).
Directly edits a zone behind the bridge's back (drift).
The zone names refresh_zones/1 was asked for, in order.
Wipes all zones, as if Knot lost its state.
Test control: the names loaded_zones/0 reports (default: every zone the Fake has).
The catalog template the zone was last ensured with (nil if absent).
Violations of the transaction discipline seen so far (oldest first).
Names of the zones Knot currently has.
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Makes the next op (:ensure_zone, :remove_zone, :apply_changes, :read_zone, :set_dnssec, :ksk_submitted, :sync_organisation) fail with reason.
@spec followed() :: [String.t()]
The zones this Fake follows (set by follow/2), sorted.
@spec hold_follow(boolean()) :: :ok
Test control: while on, follow/2 calls wait (the Fake answers them when it is turned
off again). Promotion and demotion both call it, so a test can stop a replica in the
middle of a transition and look at it there.
@spec log() :: [term()]
Every operation applied so far, oldest first (for ordering assertions).
The last spec written for the organisation, or nil.
@spec peer_address() :: String.t() | nil
The address point_peer/1 last set, or nil.
@spec put_edges([SaltDns.Knot.edge()]) :: :ok
Sets the edges edges/0 reports (a list of SaltDns.Knot.edge/0).
@spec put_record(String.t(), SaltDns.Zones.Change.t()) :: :ok
Directly edits a zone behind the bridge's back (drift).
@spec refreshed() :: [String.t()]
The zone names refresh_zones/1 was asked for, in order.
@spec reset() :: :ok
Wipes all zones, as if Knot lost its state.
@spec set_loaded([String.t()] | :all) :: :ok
Test control: the names loaded_zones/0 reports (default: every zone the Fake has).
@spec start_link(keyword()) :: GenServer.on_start()
The catalog template the zone was last ensured with (nil if absent).
@spec violations() :: [term()]
Violations of the transaction discipline seen so far (oldest first).
@spec zones() :: [String.t()]
Names of the zones Knot currently has.