Skip to content

Commit

Permalink
Mock tests now produce same results
Browse files Browse the repository at this point in the history
  • Loading branch information
dldinternet committed Apr 1, 2017
1 parent 05d530a commit bc98539
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/fog/digitalocean/requests/dns/create_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ def create_record(name, rec={})
# noinspection RubyStringKeysInHashInspection
class Mock
def create_record(name, rec={})
success_status = 201
response = Excon::Response.new
if rec.with_indifferent_access[:type] =~ /^A/
if rec.with_indifferent_access[:type] =~ /^(A|SRV)/
if rec.with_indifferent_access[:data] !~ /^[0-9]+/
response.status = 422
response.body = {
Expand All @@ -46,23 +47,33 @@ def create_record(name, rec={})
"message" => "IP address did not match IPv6 format (e.g. 2001:db8::ff00:42:8329)."
}
else
response.status = 200
response.status = success_status
end
else
response.status = 200
response.status = success_status
end
end
elsif rec.with_indifferent_access[:type] =~ /TXT/
if rec.with_indifferent_access[:data] =~ /[\r\n]/
response.status = 422
response.body = {
"id" => "unprocessable_entity",
"message" => "Data must not contain newlines"
}
else
response.status = success_status
end
elsif rec.with_indifferent_access[:data] !~ /\.$/
response.status = 422
response.body = {
"id" => "unprocessable_entity",
"message" => "Data needs to end with a dot (.)"
}
else
response.status = 200
response.status = success_status
end

if response.status == 200
if response.status == success_status
data[:domain_records][name] << rec.dup
last = data[:domain_records][name].last
#last['name'] = %(#{last['name']}.#{name}.) unless last['name'].match(%r{\.$}) unless last['name'].eql?('@') #|| last['name'].eql?('*')
Expand Down

0 comments on commit bc98539

Please sign in to comment.