Module: KeaApiStubs

Defined in:
spec/fixtures/kea_api_stubs.rb

Overview

This module provides a set of helper methods that return mock data structures, mimicking the JSON responses from the ISC Kea API. This allows us to test the client and services without needing a live Kea server.

Instance Method Summary collapse

Instance Method Details

#error_responseHash

An error response from the API.

Returns:

  • (Hash)

    A hash representing a generic API error.



51
52
53
# File 'spec/fixtures/kea_api_stubs.rb', line 51

def error_response
  { "result" => 1, "text" => "Something went wrong." }
end

#successful_config_getHash

A successful response for a 'config-get' command.

Returns:

  • (Hash)

    A hash representing the Kea DHCPv4 configuration.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'spec/fixtures/kea_api_stubs.rb', line 9

def successful_config_get
  {
    "Dhcp4" => {
      "subnet4" => [
        {
          "id" => 1,
          "subnet" => "192.168.1.0/24",
          "pools" => [{ "pool" => "192.168.1.10-192.168.1.20" }],
          "option-data" => [{ "name" => "routers", "data" => "192.168.1.1" }],
          "reservations" => [
            { "hw-address" => "aa:bb:cc:dd:ee:ff", "ip-address" => "192.168.1.5", "hostname" => "test-host" }
          ]
        }
      ]
    }
  }
end

#successful_lease_getHash

A successful response for a 'lease4-get-all' command with one active lease.

Returns:

  • (Hash)

    A hash containing a list of leases.



29
30
31
32
33
34
35
# File 'spec/fixtures/kea_api_stubs.rb', line 29

def successful_lease_get
  {
    "leases" => [
      { "ip-address" => "192.168.1.11", "hw-address" => "ff:ee:dd:cc:bb:aa", "cltt" => 1678886400, "expire" => 1678890000 }
    ]
  }
end

#successful_reservation_addHash

A successful response for a 'reservation-add' command.

Returns:

  • (Hash)

    A hash indicating success.



39
40
41
# File 'spec/fixtures/kea_api_stubs.rb', line 39

def successful_reservation_add
  { "result" => 0, "text" => "Reservation added successfully." }
end

#successful_reservation_delHash

A successful response for a 'reservation-del' command.

Returns:

  • (Hash)

    A hash indicating success.



45
46
47
# File 'spec/fixtures/kea_api_stubs.rb', line 45

def successful_reservation_del
  { "result" => 0, "text" => "Reservation deleted successfully." }
end