forked from dnsimple/chef-dnsimple
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit and integration coverage with chefspec
- Loading branch information
Showing
7 changed files
with
238 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
language: ruby | ||
rvm: | ||
- 1.9.3 | ||
- 2.0.0 | ||
script: bundle exec rspec spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,126 @@ | ||
GIT | ||
remote: https://github.com/josacar/fog | ||
revision: a8268e90880da12696205238040a6e0b27ac47a7 | ||
specs: | ||
fog (1.19.0) | ||
builder | ||
excon (~> 0.31.0) | ||
formatador (~> 0.2.0) | ||
mime-types | ||
multi_json (~> 1.0) | ||
net-scp (~> 1.1) | ||
net-ssh (>= 2.1.3) | ||
nokogiri (~> 1.5) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
archive-tar-minitar (0.5.2) | ||
bunny (0.8.0) | ||
chef (10.12.0) | ||
bunny (>= 0.6.0) | ||
erubis | ||
highline (>= 1.6.9) | ||
json (>= 1.4.4, <= 1.6.1) | ||
mixlib-authentication (>= 1.1.0) | ||
mixlib-cli (>= 1.1.0) | ||
mixlib-config (>= 1.1.2) | ||
mixlib-log (>= 1.3.0) | ||
mixlib-shellout | ||
moneta | ||
net-ssh (~> 2.2.2) | ||
builder (3.2.2) | ||
chef (11.8.2) | ||
chef-zero (~> 1.6, >= 1.6.2) | ||
diff-lcs (~> 1.2, >= 1.2.4) | ||
erubis (~> 2.7) | ||
highline (~> 1.6, >= 1.6.9) | ||
json (>= 1.4.4, <= 1.7.7) | ||
mime-types (~> 1.16) | ||
mixlib-authentication (~> 1.3) | ||
mixlib-cli (~> 1.3) | ||
mixlib-config (~> 2.0) | ||
mixlib-log (~> 1.3) | ||
mixlib-shellout (~> 1.2) | ||
net-ssh (~> 2.6) | ||
net-ssh-multi (~> 1.1.0) | ||
ohai (>= 0.6.0) | ||
ohai (~> 6.0) | ||
pry (~> 0.9) | ||
puma (~> 1.6) | ||
rest-client (>= 1.0.4, < 1.7.0) | ||
treetop (~> 1.4.9) | ||
uuidtools | ||
yajl-ruby (~> 1.1) | ||
childprocess (0.3.5) | ||
ffi (~> 1.0, >= 1.0.6) | ||
coderay (0.9.8) | ||
chef-zero (1.7.2) | ||
hashie (~> 2.0) | ||
json | ||
mixlib-log (~> 1.3) | ||
moneta (< 0.7.0) | ||
rack | ||
chefspec (3.1.4) | ||
chef (~> 11.0) | ||
fauxhai (~> 2.0) | ||
i18n (>= 0.6.9, < 1.0.0) | ||
rspec (~> 2.14) | ||
coderay (1.1.0) | ||
diff-lcs (1.2.5) | ||
erubis (2.7.0) | ||
ffi (1.1.5) | ||
foodcritic (1.4.0) | ||
gherkin (~> 2.8.0) | ||
gist (~> 2.0.4) | ||
nokogiri (= 1.5.0) | ||
pry (~> 0.9.7.4) | ||
pry-doc (~> 0.3.0) | ||
rak (~> 1.4) | ||
treetop (~> 1.4.10) | ||
yajl-ruby (~> 1.1.0) | ||
gherkin (2.8.0) | ||
json (>= 1.4.6) | ||
gist (2.0.4) | ||
hashr (0.0.21) | ||
highline (1.6.13) | ||
i18n (0.6.0) | ||
excon (0.31.0) | ||
fauxhai (2.0.1) | ||
net-ssh | ||
ohai | ||
formatador (0.2.4) | ||
hashie (2.0.5) | ||
highline (1.6.20) | ||
i18n (0.6.9) | ||
ipaddress (0.8.0) | ||
json (1.5.4) | ||
librarian (0.0.24) | ||
archive-tar-minitar (>= 0.5.2) | ||
chef (>= 0.10) | ||
highline | ||
thor (~> 0.15) | ||
log4r (1.1.10) | ||
method_source (0.6.7) | ||
ruby_parser (>= 2.3.1) | ||
mime-types (1.19) | ||
json (1.7.7) | ||
method_source (0.8.2) | ||
mime-types (1.25.1) | ||
mini_portile (0.5.2) | ||
mixlib-authentication (1.3.0) | ||
mixlib-log | ||
mixlib-cli (1.2.2) | ||
mixlib-config (1.1.2) | ||
mixlib-log (1.4.1) | ||
mixlib-shellout (1.1.0) | ||
mixlib-cli (1.4.0) | ||
mixlib-config (2.1.0) | ||
mixlib-log (1.6.0) | ||
mixlib-shellout (1.3.0) | ||
moneta (0.6.0) | ||
net-scp (1.0.4) | ||
net-ssh (>= 1.99.1) | ||
net-ssh (2.2.2) | ||
net-ssh-gateway (1.1.0) | ||
net-ssh (>= 1.99.1) | ||
multi_json (1.8.4) | ||
net-scp (1.1.2) | ||
net-ssh (>= 2.6.5) | ||
net-ssh (2.7.0) | ||
net-ssh-gateway (1.2.0) | ||
net-ssh (>= 2.6.5) | ||
net-ssh-multi (1.1) | ||
net-ssh (>= 2.1.4) | ||
net-ssh-gateway (>= 0.99.0) | ||
nokogiri (1.5.0) | ||
ohai (6.14.0) | ||
nokogiri (1.6.1) | ||
mini_portile (~> 0.5.0) | ||
ohai (6.20.0) | ||
ipaddress | ||
mixlib-cli | ||
mixlib-config | ||
mixlib-log | ||
systemu | ||
mixlib-shellout | ||
systemu (~> 2.5.2) | ||
yajl-ruby | ||
polyglot (0.3.3) | ||
pry (0.9.7.4) | ||
coderay (~> 0.9.8) | ||
method_source (~> 0.6.7) | ||
ruby_parser (>= 2.3.1) | ||
slop (~> 2.1.0) | ||
pry-doc (0.3.0) | ||
pry (>= 0.9.0) | ||
yard (>= 0.6.4) | ||
rak (1.4) | ||
pry (0.9.12.4) | ||
coderay (~> 1.0) | ||
method_source (~> 0.8) | ||
slop (~> 3.4) | ||
puma (1.6.3) | ||
rack (~> 1.2) | ||
rack (1.5.2) | ||
rest-client (1.6.7) | ||
mime-types (>= 1.16) | ||
ruby_parser (2.3.1) | ||
sexp_processor (~> 3.0) | ||
sexp_processor (3.2.0) | ||
slop (2.1.0) | ||
rspec (2.14.1) | ||
rspec-core (~> 2.14.0) | ||
rspec-expectations (~> 2.14.0) | ||
rspec-mocks (~> 2.14.0) | ||
rspec-core (2.14.7) | ||
rspec-expectations (2.14.4) | ||
diff-lcs (>= 1.1.3, < 2.0) | ||
rspec-mocks (2.14.4) | ||
safe_yaml (0.9.7) | ||
slop (3.4.7) | ||
systemu (2.5.2) | ||
test-kitchen (0.5.2) | ||
foodcritic (~> 1.4.0) | ||
hashr (~> 0.0.20) | ||
highline (>= 1.6.9) | ||
librarian (~> 0.0.20) | ||
mixlib-cli (~> 1.2.2) | ||
vagrant (~> 1.0.2) | ||
yajl-ruby (~> 1.1.0) | ||
thor (0.16.0) | ||
treetop (1.4.10) | ||
polyglot | ||
polyglot (>= 0.3.1) | ||
uuidtools (2.1.3) | ||
vagrant (1.0.3) | ||
archive-tar-minitar (= 0.5.2) | ||
childprocess (~> 0.3.1) | ||
erubis (~> 2.7.0) | ||
i18n (~> 0.6.0) | ||
json (~> 1.5.1) | ||
log4r (~> 1.1.9) | ||
net-scp (~> 1.0.4) | ||
net-ssh (~> 2.2.2) | ||
yajl-ruby (1.1.0) | ||
yard (0.8.2.1) | ||
test-kitchen (1.1.1) | ||
mixlib-shellout (~> 1.2) | ||
net-scp (~> 1.1) | ||
net-ssh (~> 2.7) | ||
safe_yaml (~> 0.9) | ||
thor (~> 0.18) | ||
thor (0.18.1) | ||
yajl-ruby (1.2.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
chefspec (~> 3.0) | ||
fog! | ||
test-kitchen |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require_relative 'spec_helper' | ||
|
||
describe 'chef-dnsimple::default' do | ||
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } | ||
|
||
it 'installs libxml2-dev and libxslt1-dev packages' do | ||
expect(chef_run).to install_package 'libxml2-dev' | ||
expect(chef_run).to install_package 'libxslt1-dev' | ||
end | ||
|
||
it 'installs fog chef_gem' do | ||
expect(chef_run).to install_chef_gem 'fog' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
require 'spec_helper' | ||
|
||
class ChefSpec::Runner | ||
def append(recipe) | ||
runner = Chef::Runner.new(recipe.run_context) | ||
runner.converge | ||
self | ||
end | ||
end | ||
|
||
describe 'chef-dnsimple::record' do | ||
let(:chef_run) do | ||
runner = ChefSpec::Runner.new(:step_into => ['chef_dnsimple_record']) | ||
runner.converge | ||
end | ||
before do | ||
Fog.mock! | ||
Fog::Mock.reset | ||
create_domain_data | ||
end | ||
|
||
context 'with a no existing record with the same name' do | ||
it 'creates record' do | ||
chef_run_with_recipe('name', 'A', '1.1.1.1') | ||
record = dnsimple_zone.records.detect { |r| r.name == 'name' } | ||
expect(record.name).to eq 'name' | ||
expect(record.type).to eq 'A' | ||
expect(record.value).to eq '1.1.1.1' | ||
end | ||
end | ||
|
||
context 'with an existing record with the same name and ttl' do | ||
context 'and different type' do | ||
it 'does not delete existing record and creates new record' do | ||
chef_run_with_recipe('', 'A', '1.1.1.1') | ||
expected_records = { | ||
'NS' => '1.2.3.4', | ||
'A' => '1.1.1.1' | ||
} | ||
|
||
records = dnsimple_zone.records.select { |r| r.name == '' } | ||
expect(records.size).to eq 2 | ||
|
||
records.each do |record| | ||
expect(record.value).to eq expected_records[record.type] | ||
expected_records.delete(record.type) | ||
end | ||
expect(expected_records).to be_empty | ||
end | ||
end | ||
|
||
context 'and same type' do | ||
it 'deletes existing record and creates new record' do | ||
chef_run_with_recipe('existing', 'A', '1.1.1.1') | ||
|
||
record = dnsimple_zone.records.detect { |r| r.name == 'existing' } | ||
expect(record.value).to eq '1.1.1.1' | ||
end | ||
end | ||
end | ||
|
||
def dnsimple_client | ||
Fog::DNS.new(provider: "DNSimple", dnsimple_email: 'user@email.com', dnsimple_password: 'my123password') | ||
end | ||
|
||
def dnsimple_zone | ||
dnsimple_client.zones.get('example.com') | ||
end | ||
|
||
def create_domain_data | ||
dnsimple_client.zones.create({domain: 'example.com'}) | ||
dnsimple_zone.records.create({name: '', type: 'NS', value: '1.2.3.4', ttl: 3600}) | ||
dnsimple_zone.records.create({name: 'existing', type: 'A', value: '2.2.2.2', ttl: 3600}) | ||
end | ||
|
||
def chef_run_with_recipe(record_name, record_type, record_value) | ||
recipe = fake_recipe(chef_run, 'dnsimple_spec', 'record') do | ||
chef_dnsimple_record record_name do | ||
type record_type | ||
content record_value | ||
domain 'example.com' | ||
username 'user@email.com' | ||
password 'my123password' | ||
end | ||
end | ||
chef_run.append(recipe) | ||
end | ||
|
||
def fake_recipe(run, cookbook_name, recipe_name, &block) | ||
recipe = Chef::Recipe.new(cookbook_name, recipe_name, run.run_context) | ||
recipe.instance_eval(&block) | ||
end | ||
end |
Oops, something went wrong.