Class: DNSAdapter::MockClient

Inherits:
Object
  • Object
show all
Defined in:
lib/dns_adapter/mock_client.rb

Overview

A mock client for use in tests.

Instance Method Summary collapse

Constructor Details

#initialize(zone_data) ⇒ MockClient

Returns a new instance of MockClient.



6
7
8
9
10
11
# File 'lib/dns_adapter/mock_client.rb', line 6

def initialize(zone_data)
  @zone_data = {}
  zone_data.each do |k, v|
    @zone_data[k.downcase] = v.dup
  end
end

Instance Method Details

#fetch_a_records(domain) ⇒ Object



13
14
15
# File 'lib/dns_adapter/mock_client.rb', line 13

def fetch_a_records(domain)
  fetch_records(domain, 'A')
end

#fetch_aaaa_records(domain) ⇒ Object



17
18
19
# File 'lib/dns_adapter/mock_client.rb', line 17

def fetch_aaaa_records(domain)
  fetch_records(domain, 'AAAA')
end

#fetch_cname_records(domain) ⇒ Object



33
34
35
# File 'lib/dns_adapter/mock_client.rb', line 33

def fetch_cname_records(domain)
  fetch_records(domain, 'CNAME')
end

#fetch_mx_records(domain) ⇒ Object



21
22
23
# File 'lib/dns_adapter/mock_client.rb', line 21

def fetch_mx_records(domain)
  fetch_records(domain, 'MX')
end

#fetch_ns_records(domain) ⇒ Object



29
30
31
# File 'lib/dns_adapter/mock_client.rb', line 29

def fetch_ns_records(domain)
  fetch_records(domain, 'NS')
end

#fetch_ptr_records(arpa_address) ⇒ Object



25
26
27
# File 'lib/dns_adapter/mock_client.rb', line 25

def fetch_ptr_records(arpa_address)
  fetch_records(arpa_address, 'PTR')
end

#fetch_records(domain, type) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/dns_adapter/mock_client.rb', line 49

def fetch_records(domain, type)
  record_set = find_records_for_domain(domain)
  return [] if record_set.empty?
  records = records_for_type(record_set, type)
  if records.empty?
    check_for_timeout(record_set)
  else
    formatted_records(records, type)
  end
end

#fetch_spf_records(domain) ⇒ Object



41
42
43
# File 'lib/dns_adapter/mock_client.rb', line 41

def fetch_spf_records(domain)
  fetch_records(domain, 'SPF')
end

#fetch_txt_records(domain) ⇒ Object



37
38
39
# File 'lib/dns_adapter/mock_client.rb', line 37

def fetch_txt_records(domain)
  fetch_records(domain, 'TXT')
end

#timeouts=(timeouts) ⇒ Object



45
46
47
# File 'lib/dns_adapter/mock_client.rb', line 45

def timeouts=(timeouts)
  # Deliberate NOOP
end