Skip to content

Commit

Permalink
Merge pull request #15 from bdunne/ensure_shared_example_groups_use_s…
Browse files Browse the repository at this point in the history
…hared_resources

Ensure shared example groups use shared resources
  • Loading branch information
Fryguy authored Jul 19, 2017
2 parents b9c12e8 + 0d73ee8 commit 0de5507
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@

context "#poll" do
it "yields valid events" do
VCR.use_cassette(cassette_file) do
last_activity = subject.send(:last_activity)
# do something on tower that creates an activity in activity_stream
provider.connect.api.credentials.create!(:name => 'test_stream', :user => 1)
polled_event = nil
subject.poll do |event|
expect(event['id']).to eq(last_activity.id + 1)
subject.stop
polled_event = event
Spec::Support::VcrHelper.with_cassette_library_dir(ManageIQ::Providers::AnsibleTower::Engine.root.join("spec/vcr_cassettes")) do
VCR.use_cassette(cassette_file) do
last_activity = subject.send(:last_activity)
# do something on tower that creates an activity in activity_stream
provider.connect.api.credentials.create!(:name => 'test_stream', :user => 1)
polled_event = nil
subject.poll do |event|
expect(event['id']).to eq(last_activity.id + 1)
subject.stop
polled_event = event
end
expect(subject.send(:last_activity).id).to eq(polled_event['id'])
end
expect(subject.send(:last_activity).id).to eq(polled_event['id'])
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,38 @@
# this is to check if a project will be updated on tower
last_project_update = Time.zone.parse("2017-04-10 20:50:11.429285000 +0000") - 1.minute

2.times do
VCR.use_cassette(cassette_path) do
EmsRefresh.refresh([[configuration_script_source.class.to_s, configuration_script_source.id]])
Spec::Support::VcrHelper.with_cassette_library_dir(ManageIQ::Providers::AnsibleTower::Engine.root.join("spec/vcr_cassettes")) do
2.times do
VCR.use_cassette(cassette_path) do
EmsRefresh.refresh([[configuration_script_source.class.to_s, configuration_script_source.id]])

expect(automation_manager.reload.last_refresh_error).to be_nil
expect(automation_manager.configuration_script_sources.count).to eq(2)
expect(automation_manager.reload.last_refresh_error).to be_nil
expect(automation_manager.configuration_script_sources.count).to eq(2)

configuration_script_source.reload
configuration_script_source_other.reload
configuration_script_source.reload
configuration_script_source_other.reload

last_updated = Time.zone.parse(configuration_script_source.provider_object.last_updated)
expect(last_updated).to be >= last_project_update
last_project_update = last_updated
last_updated = Time.zone.parse(configuration_script_source.provider_object.last_updated)
expect(last_updated).to be >= last_project_update
last_project_update = last_updated

expect(configuration_script_source.name).to eq("targeted_refresh")
expect(ConfigurationScriptPayload.count).to eq(81)
expect(ConfigurationScriptPayload.where(:name => '2b_rm')).to be_empty
expect(configuration_script_source.configuration_script_payloads.count).to eq(81)
expect(
configuration_script_source.configuration_script_payloads.where(
:name => "test/utils/docker/httptester/httptester.yml"
).count
).to eq(1)
expect(configuration_script_source.authentication.name).to eq('db-github')
expect(credential.reload).to eq(credential)
expect(configuration_script_source.name).to eq("targeted_refresh")
expect(ConfigurationScriptPayload.count).to eq(81)
expect(ConfigurationScriptPayload.where(:name => '2b_rm')).to be_empty
expect(configuration_script_source.configuration_script_payloads.count).to eq(81)
expect(
configuration_script_source.configuration_script_payloads.where(
:name => "test/utils/docker/httptester/httptester.yml"
).count
).to eq(1)
expect(configuration_script_source.authentication.name).to eq('db-github')
expect(credential.reload).to eq(credential)

expect(configuration_script_source_other.name).to eq("Dont touch this")
expect(configuration_script_source_other.name).to eq("Dont touch this")
end
# check if a playbook will be added back in on the second run
configuration_script_source.configuration_script_payloads.where(:name => "test/utils/docker/httptester/httptester.yml").destroy_all
end
# check if a playbook will be added back in on the second run
configuration_script_source.configuration_script_payloads.where(:name => "test/utils/docker/httptester/httptester.yml").destroy_all
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,38 @@
# this is to check if a project will be updated on tower
last_project_update = Time.zone.parse("2017-04-26T07:57:08.810Z") - 1.minute

2.times do
VCR.use_cassette(cassette_path) do
EmsRefresh.refresh([[configuration_script_source.class.to_s, configuration_script_source.id]])
Spec::Support::VcrHelper.with_cassette_library_dir(ManageIQ::Providers::AnsibleTower::Engine.root.join("spec/vcr_cassettes")) do
2.times do
VCR.use_cassette(cassette_path) do
EmsRefresh.refresh([[configuration_script_source.class.to_s, configuration_script_source.id]])

expect(automation_manager.reload.last_refresh_error).to be_nil
expect(automation_manager.configuration_script_sources.count).to eq(2)
expect(automation_manager.reload.last_refresh_error).to be_nil
expect(automation_manager.configuration_script_sources.count).to eq(2)

configuration_script_source.reload
configuration_script_source_other.reload
configuration_script_source.reload
configuration_script_source_other.reload

last_updated = Time.zone.parse(configuration_script_source.provider_object.last_updated)
expect(last_updated).to be >= last_project_update
last_project_update = last_updated
last_updated = Time.zone.parse(configuration_script_source.provider_object.last_updated)
expect(last_updated).to be >= last_project_update
last_project_update = last_updated

expect(configuration_script_source.name).to eq("targeted_refresh")
expect(ConfigurationScriptPayload.count).to eq(60)
expect(ConfigurationScriptPayload.where(:name => '2b_rm')).to be_empty
expect(configuration_script_source.configuration_script_payloads.count).to eq(60)
expect(
configuration_script_source.configuration_script_payloads.where(
:name => "jboss-standalone/demo-aws-launch.yml"
).count
).to eq(1)
expect(configuration_script_source.authentication.name).to eq('db-github')
expect(credential.reload).to eq(credential)
expect(configuration_script_source.name).to eq("targeted_refresh")
expect(ConfigurationScriptPayload.count).to eq(60)
expect(ConfigurationScriptPayload.where(:name => '2b_rm')).to be_empty
expect(configuration_script_source.configuration_script_payloads.count).to eq(60)
expect(
configuration_script_source.configuration_script_payloads.where(
:name => "jboss-standalone/demo-aws-launch.yml"
).count
).to eq(1)
expect(configuration_script_source.authentication.name).to eq('db-github')
expect(credential.reload).to eq(credential)

expect(configuration_script_source_other.name).to eq("Dont touch this")
expect(configuration_script_source_other.name).to eq("Dont touch this")
end
# check if a playbook will be added back in on the second run
configuration_script_source.configuration_script_payloads.where(:name => "jboss-standalone/demo-aws-launch.yml").destroy_all
end
# check if a playbook will be added back in on the second run
configuration_script_source.configuration_script_payloads.where(:name => "jboss-standalone/demo-aws-launch.yml").destroy_all
end
end
end
28 changes: 15 additions & 13 deletions spec/support/ansible_shared/automation_manager/refresher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,22 @@
it "will perform a full refresh" do
expected_counterpart_vm

2.times do
# to re-record cassettes see comment at the beginning of this file
VCR.use_cassette(cassette_path) do
EmsRefresh.refresh(automation_manager)
expect(automation_manager.reload.last_refresh_error).to be_nil
Spec::Support::VcrHelper.with_cassette_library_dir(ManageIQ::Providers::AnsibleTower::Engine.root.join("spec/vcr_cassettes")) do
2.times do
# to re-record cassettes see comment at the beginning of this file
VCR.use_cassette(cassette_path) do
EmsRefresh.refresh(automation_manager)
expect(automation_manager.reload.last_refresh_error).to be_nil
end
assert_counts
assert_configured_system
assert_configuration_script_with_nil_survey_spec
assert_configuration_script_with_survey_spec
assert_inventory_root_group
assert_configuration_script_sources
assert_playbooks
assert_credentials
end
assert_counts
assert_configured_system
assert_configuration_script_with_nil_survey_spec
assert_configuration_script_with_survey_spec
assert_inventory_root_group
assert_configuration_script_sources
assert_playbooks
assert_credentials
end
end

Expand Down
28 changes: 15 additions & 13 deletions spec/support/ansible_shared/automation_manager/refresher_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,22 @@
it "will perform a full refresh" do
expected_counterpart_vm

2.times do
VCR.use_cassette("#{cassette_path}_v2") do
EmsRefresh.refresh(automation_manager)
expect(automation_manager.reload.last_refresh_error).to be_nil
Spec::Support::VcrHelper.with_cassette_library_dir(ManageIQ::Providers::AnsibleTower::Engine.root.join("spec/vcr_cassettes")) do
2.times do
VCR.use_cassette("#{cassette_path}_v2") do
EmsRefresh.refresh(automation_manager)
expect(automation_manager.reload.last_refresh_error).to be_nil
end

assert_counts
assert_configured_system
assert_configuration_script_with_nil_survey_spec
assert_configuration_script_with_survey_spec
assert_inventory_root_group
assert_configuration_script_sources
assert_playbooks
assert_credentials
end

assert_counts
assert_configured_system
assert_configuration_script_with_nil_survey_spec
assert_configuration_script_with_survey_spec
assert_inventory_root_group
assert_configuration_script_sources
assert_playbooks
assert_credentials
end
end

Expand Down
15 changes: 15 additions & 0 deletions spec/support/vcr_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Spec
module Support
module VcrHelper
def self.with_cassette_library_dir(new_path)
old_path = VCR.configuration.cassette_library_dir
VCR.configure { |c| c.cassette_library_dir = new_path }

yield

ensure
VCR.configure { |c| c.cassette_library_dir = old_path }
end
end
end
end

0 comments on commit 0de5507

Please sign in to comment.