lib/pact/mock_service/app.rb in pact-mock_service-3.4.0 vs lib/pact/mock_service/app.rb in pact-mock_service-3.5.0

- old
+ new

@@ -15,10 +15,11 @@ end class App def initialize options = {} logger = Logger.from_options(options) + @options = options stubbing = options[:stub_pactfile_paths] && options[:stub_pactfile_paths].any? @name = options.fetch(:name, "MockService") @session = Session.new(options.merge(logger: logger, warn_on_too_many_interactions: !stubbing)) setup_stub(options[:stub_pactfile_paths]) if stubbing request_handlers = RequestHandlers.new(@name, logger, @session, options) @@ -38,11 +39,11 @@ end def setup_stub stub_pactfile_paths interactions = stub_pactfile_paths.collect do | pactfile_path | $stdout.puts "INFO: Loading interactions from #{pactfile_path}" - hash_interactions = JSON.parse(Pact::PactFile.read(pactfile_path))['interactions'] + hash_interactions = JSON.parse(Pact::PactFile.read(pactfile_path, pactfile_options))['interactions'] hash_interactions.collect { | hash | Interaction.from_hash(hash) } end.flatten @session.set_expected_interactions interactions end @@ -54,9 +55,23 @@ end end def to_s "#{@name} #{super.to_s}" + end + + private + + def pactfile_options + { + :token => broker_token, + :username => @options[:broker_username], + :password => @options[:broker_password], + } + end + + def broker_token + @options[:broker_token] || ENV['PACT_BROKER_TOKEN'] end end # Can't write to a file in a TRAP, might deadlock # Not sure why we can still write to the pact file though