spec/scooter/httpdispatchers/puppetdbdispatcher_spec.rb in scooter-3.2.19 vs spec/scooter/httpdispatchers/puppetdbdispatcher_spec.rb in scooter-4.1.0

- old
+ new

@@ -2,27 +2,30 @@ module Scooter describe HttpDispatchers::PuppetdbDispatcher do let(:host) { double('host') } + let(:logger) { double('logger')} let(:credentials) { double('credentials') } let(:credentials) { { login: 'Ziggy', password: 'Stardust' } } subject { HttpDispatchers::PuppetdbDispatcher.new(host) } unixhost = { roles: ['test_role'], 'platform' => 'debian-7-x86_64' } - let(:host) { Beaker::Host.create('test.com', unixhost, {}) } + let(:host) { Beaker::Host.create('test.com', unixhost, {:logger => logger}) } + let(:host2) { Beaker::Host.create('test2.com', unixhost, {:logger => logger}) } before do - expect(Scooter::Utilities::BeakerUtilities).to receive(:pe_ca_cert_file).and_return('cert file') - expect(Scooter::Utilities::BeakerUtilities).to receive(:pe_private_key).and_return('key file') - expect(Scooter::Utilities::BeakerUtilities).to receive(:pe_hostcert).and_return('host cert') + allow_any_instance_of(Beaker::Http::FaradayBeakerLogger).to receive(:info) { true } + allow_any_instance_of(Beaker::Http::FaradayBeakerLogger).to receive(:debug) { true } expect(OpenSSL::PKey).to receive(:read).and_return('Pkey') expect(OpenSSL::X509::Certificate).to receive(:new).and_return('client_cert') - expect(Scooter::Utilities::BeakerUtilities).to receive(:get_public_ip).and_return('public_ip') - expect(subject).not_to be_nil + allow_any_instance_of(HttpDispatchers::HttpDispatcher).to receive(:get_host_cert) {'host cert'} + allow_any_instance_of(HttpDispatchers::HttpDispatcher).to receive(:get_host_private_key) {'key file'} + allow_any_instance_of(HttpDispatchers::HttpDispatcher).to receive(:get_host_cacert) {'cert file'} + expect(subject).to be_kind_of(HttpDispatchers::PuppetdbDispatcher) end context 'with a beaker host passed in' do describe '.query_nodes' do before do @@ -207,40 +210,42 @@ expect(subject.send(:reports_match?, [{ 'hash' => 'hash_value', 'producer_timestamp' => 'time' }])).to be true end end - describe '.database_matches_self?' do + describe '.replica_db_synced_with_master_db?' do before do # find the index of the default Faraday::Adapter::NetHttp handler # and replace it with the Test adapter index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp) subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub| stub.post('/pdb/query/v4/nodes') { |env| env[:url].to_s == "https://test.com:8081/pdb/query/v4/nodes" ? - [200, [], [{ 'certname' => 'name', 'facts_timestamp' => 'facts_time', 'report_timestamp' => 'reports_time', 'catalog_timestamp' => 'catalog_time' }]] : - [200, [], [{ 'certname' => 'name2', 'facts_timestamp' => 'facts_time', 'report_timestamp2' => 'reports_time', 'catalog_timestamp' => 'catalog_time2' }]] } + [200, [], [{ 'certname' => 'test.com', 'facts_timestamp' => 'facts_time', 'report_timestamp' => 'reports_time', 'catalog_timestamp' => 'catalog_time' }, { 'certname' => 'test.com', 'facts_timestamp' => 'facts_time', 'report_timestamp' => 'reports_time', 'catalog_timestamp' => 'catalog_time' }]] : + [200, [], [{ 'certname' => 'test.com', 'facts_timestamp' => 'facts_time', 'report_timestamp' => 'reports_time', 'catalog_timestamp' => 'catalog_time' }, { 'certname' => 'test.com', 'facts_timestamp' => 'facts_time', 'report_timestamp' => 'reports_time', 'catalog_timestamp' => 'catalog_time' }]] } stub.post('/pdb/query/v4/catalogs') { |env| env[:url].to_s == "https://test.com:8081/pdb/query/v4/catalogs" ? - [200, [], [{ 'catalog_uuid' => 'catalog_uuid_1', 'producer_timestamp' => 'time' }]] : - [200, [], [{ 'catalog_uuid' => 'catalog_uuid_2', 'producer_timestamp' => 'time2' }]] } + [200, [], [{ 'certname' => 'test.com', 'catalog_uuid' => 'catalog_uuid_1', 'producer_timestamp' => 'time' }]] : + [200, [], [{ 'certname' => 'test2.com', 'catalog_uuid' => 'catalog_uuid_2', 'producer_timestamp' => 'time2' }]] } stub.post('/pdb/query/v4/facts') { |env| env[:url].to_s == "https://test.com:8081/pdb/query/v4/facts" ? [200, [], [{ 'name' => 'name', 'value' => 'value' }]] : [200, [], [{ 'name' => 'name2', 'value' => 'value2' }]] } stub.post('/pdb/query/v4/reports') { |env| env[:url].to_s == "https://test.com:8081/pdb/query/v4/reports" ? - [200, [], [{ 'hash' => 'hash_value', 'producer_timestamp' => 'time' }]] : - [200, [], [{ 'hash' => 'hash_value2', 'producer_timestamp' => 'time2' }]] } + [200, [], [{ 'certname' => 'test.com', 'hash' => 'hash_value', 'producer_timestamp' => 'time' }]] : + [200, [], [{ 'certname' => 'test2.com', 'hash' => 'hash_value2', 'producer_timestamp' => 'time2' }]] } end - expect(subject).to receive(:create_default_connection).with(any_args).twice.and_return(subject.connection) - expect(Scooter::Utilities::BeakerUtilities).to receive(:get_public_ip).and_return('public_ip') + expect(subject).to receive(:is_resolvable).exactly(8).times.and_return(true) + expect(subject).to receive(:master_has_node?).twice.and_return(true) end it 'compare with self' do - expect(subject.database_matches_self?('test.com')).to be_truthy + expect(subject.replica_db_synced_with_master_db?(host, [subject.host])).to be_truthy end it 'compare with different' do - expect(subject.faraday_logger).to receive(:warn).with /Nodes do not match/ - expect(subject.database_matches_self?('test2.com')).to be_falsey + expect(subject.host.logger).to receive(:warn).with /master doesn't have catalog with hash/ + expect(subject.host.logger).to receive(:warn).with /\*\*\* fact sync failure: no Master fact matches Replica fact:/ + expect(subject.host.logger).to receive(:warn).with /master doesn't have report with hash/ + expect(subject.host.logger).to receive(:warn).with /Catalogs not synced\r\nFacts not synced\r\nReports not synced/ + expect(subject.replica_db_synced_with_master_db?(host2, [subject.host])).to be_falsey end end - end end end