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/2 takes the global configuration lock; switching on creates a KSK in :ready and a ZSK in :active, ksk_submitted/1 makes the KSK :active (and is {:error, :no_ksk_ready} otherwise), ds_records/1 returns a stable fake DS for the KSK, switching off drops the keys. Signing records are not materialised in read_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

zone_state()

@type zone_state() :: %{
  records: %{required({String.t(), String.t(), String.t()}) => pos_integer()},
  txn: nil | %{records: map(), soa_written?: boolean()}
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

fail_next(op, reason)

@spec fail_next(atom(), term()) :: :ok

Makes the next op (:ensure_zone, :remove_zone, :apply_changes, :read_zone, :set_dnssec, :ksk_submitted, :sync_organisation) fail with reason.

followed()

@spec followed() :: [String.t()]

The zones this Fake follows (set by follow/2), sorted.

hold_follow(on?)

@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.

log()

@spec log() :: [term()]

Every operation applied so far, oldest first (for ordering assertions).

organisation(id)

@spec organisation(integer()) :: map() | nil

The last spec written for the organisation, or nil.

peer_address()

@spec peer_address() :: String.t() | nil

The address point_peer/1 last set, or nil.

put_edges(edges)

@spec put_edges([SaltDns.Knot.edge()]) :: :ok

Sets the edges edges/0 reports (a list of SaltDns.Knot.edge/0).

put_record(zone, change)

@spec put_record(String.t(), SaltDns.Zones.Change.t()) :: :ok

Directly edits a zone behind the bridge's back (drift).

refreshed()

@spec refreshed() :: [String.t()]

The zone names refresh_zones/1 was asked for, in order.

reset()

@spec reset() :: :ok

Wipes all zones, as if Knot lost its state.

set_loaded(names)

@spec set_loaded([String.t()] | :all) :: :ok

Test control: the names loaded_zones/0 reports (default: every zone the Fake has).

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

template(zone)

@spec template(String.t()) :: String.t() | nil

The catalog template the zone was last ensured with (nil if absent).

violations()

@spec violations() :: [term()]

Violations of the transaction discipline seen so far (oldest first).

zones()

@spec zones() :: [String.t()]

Names of the zones Knot currently has.