Permalink
Browse files

add spec

  • Loading branch information...
winebarrel
winebarrel committed Jul 28, 2013
1 parent 82010f8 commit 93b98bcd84dbe0c69008702b18ae60a06526cdb6
Showing with 92 additions and 1 deletion.
  1. +4 −0 Rakefile
  2. +1 −1 lib/roadworker/client.rb
  3. +1 −0 roadworker.gemspec
  4. +86 −0 spec/roadworker_spec.rb
@@ -1 +1,5 @@
require "bundler/gem_tasks"
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new('spec')
task :default => :spec
@@ -10,7 +10,7 @@ module Roadworker
class Client
include Roadworker::Log

def initialize(options)
def initialize(options = {})
@options = OpenStruct.new(options)
@options.logger ||= Logger.new($stdout)
String.colorize = @options.color
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
spec.add_dependency "term-ansicolor"
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
end
@@ -0,0 +1,86 @@
$: << File.expand_path("#{File.dirname __FILE__}/../lib")
require 'rubygems'
require 'roadworker'
require 'fileutils'

def routefile(options = {})
tempfile = `mktemp /tmp/#{File.basename(__FILE__)}.XXXXXX`.strip

begin
open(tempfile, 'wb') {|f| f.puts(yield) }
client = Roadworker::Client.new(options)
client.apply(tempfile)
ensure
FileUtils.rm_f(tempfile)
end
end

def rrs_list(rrs)
rrs.map {|i| i[:value] }.sort
end

describe Roadworker::Client do
before(:each) {
AWS.config({
:access_key_id => (ENV['TEST_AWS_ACCESS_KEY_ID'] || 'scott'),
:secret_access_key => (ENV['TEST_AWS_SECRET_ACCESS_KEY'] || 'tiger'),
})

routefile(:force => true) { '' }
@route53 = AWS::Route53.new
}

it {
expect(@route53.hosted_zones.to_a).to be_empty
}

it {
routefile {
<<-EOS
hosted_zone "winebarre.jp" do
end
EOS
}

zones = @route53.hosted_zones.to_a
expect(zones.length).to eq(1)

zone = zones[0]
expect(zone.name).to eq("winebarre.jp.")
expect(zone.resource_record_set_count).to eq(2)

expect(zone.rrsets['winebarre.jp.', 'NS'].ttl).to eq(172800)
expect(zone.rrsets['winebarre.jp.', 'SOA'].ttl).to eq(900)
}

it {
routefile {
<<-EOS
hosted_zone "winebarre.jp" do
rrset "www.winebarre.jp", "A" do
ttl 123
resource_records(
"127.0.0.1",
"127.0.0.2"
)
end
end
EOS
}

zones = @route53.hosted_zones.to_a
expect(zones.length).to eq(1)

zone = zones[0]
expect(zone.name).to eq("winebarre.jp.")
expect(zone.resource_record_set_count).to eq(3)

expect(zone.rrsets['winebarre.jp.', 'NS'].ttl).to eq(172800)
expect(zone.rrsets['winebarre.jp.', 'SOA'].ttl).to eq(900)

a = zone.rrsets['www.winebarre.jp.', 'A']
expect(a.name).to eq("www.winebarre.jp.")
expect(a.ttl).to eq(123)
expect(rrs_list(a.resource_records)).to eq(["127.0.0.1", "127.0.0.2"])
}
end

0 comments on commit 93b98bc

Please sign in to comment.