私は私のチームに契約テストを導入しようとしています.Pactは、信頼性の高い唯一のツールだと思われます。パイプラインなしで1つのコンテナでCIの契約テストにpactを使用しますか?
ドキュメントでは、マイクロサービスでそれをCIパイプラインの一部として使用することが示唆されています。しかし、私たちはインフラストラクチャーに大きな変更を加えることはできません。代わりに私たちのニーズに合うようにPactの使用法を修正しようとします。
REST API経由でJavaScript(Karma + Mocha)フロントエンドとRails(Rspec)バックエンド間の通信をテストするためにPactを使用したいと考えています。 CI(Circle CI)で確実に動作させることができない限り、すべてうまくいっています。 Pactドキュメントで提案されているように、CIパイプラインはありません。コンシューマテストとプロバイダーテストを1つのコンテナで順番に実行する必要があります。アーティファクトはコンテナ内の一時フォルダに格納され、後で削除されます。
質問:パイプラインなしで、1つのコンテナ内でCIに対するPactテストを実行する確立された信頼性の高い方法はありますか?それともPactはこの仕事に最適なツールではありませんか?
私はそれを達成するためにRubyスクリプトを書いたが、それは多くの場合、タイムアウトでクラッシュ:
def test_pact
# wait for pact server to start, identify it by pid in the STDOUT
server_init_message = "WEBrick::HTTPServer#start: pid="
server_error_message = "(Errno::EADDRINUSE)"
read_stream, write_stream = IO.pipe
proc = ChildProcess.build("bundle", "exec", "rake", "pact:server")
proc.io.stdout = proc.io.stderr = write_stream
proc.leader = true # makes sure to kill all child forks of this process when it dies
begin
proc.start
output_line = read_stream.gets
until output_line.include?(server_init_message)
puts "Waiting for Pact server to boot: #{Time.now}"
output_line = read_stream.gets
puts "Server output: #{output_line}"
raise "Server boot error" if output_line.include?(server_error_message)
end
puts "Pact Server is booted"
# Run JS tests:
Dir.chdir("js") do
run_or_exit("./build-support/circle.js", 'contract-karma.conf.js')
end
proc.stop
# Run Ruby tests:
run_or_exit("bundle exec rake pact:verify")
rescue ChildProcess::TimeoutError, RuntimeError
proc.stop
end
end
そしてrakeタスク:
require 'pact/tasks'
task :default => 'pact:verify'
# rake pact:server
namespace :pact do
desc 'Run Pact Mock Server'
task server: :environment do
puts 'starting Pact mock server'
system 'pact-mock-service --host localhost --port 1234 --pact_dir spec/contracts --consumer "Some Service" --provider "Some Service Provider" --pact_specification_version 2'
end
end
私はすでに 'ありがとう! –