Skip to content

Commit

Permalink
pact verification fix when broker and file both present (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
silverblaze404 authored Apr 26, 2024
1 parent f1ee8d3 commit 8964182
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
21 changes: 7 additions & 14 deletions src/pact_verifier.erl
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,6 @@ verify_pacts(VerifierRef, ProviderOpts, ProviderPortDetails) ->
{Output, _OutputLog} = pact_utils:run_executable_async(
EscriptPath ++ " pactffi_nif verify_file_pacts " ++ ArgsString
),
case Protocol of
<<"message">> ->
pact_verifier:stop(HttpPid),
stop_verifier(VerifierRef);
_ ->
stop_verifier(VerifierRef)
end,
Output
end,
Output2 =
Expand Down Expand Up @@ -256,15 +249,15 @@ verify_pacts(VerifierRef, ProviderOpts, ProviderPortDetails) ->
{Output3, _OutputLog3} = pact_utils:run_executable_async(
EscriptPath ++ " pactffi_nif verify_broker_pacts " ++ ArgsString1
),
case Protocol of
<<"message">> ->
pact_verifier:stop(HttpPid),
stop_verifier(VerifierRef);
_ ->
stop_verifier(VerifierRef)
end,
Output3
end,
case Protocol of
<<"message">> ->
pact_verifier:stop(HttpPid),
stop_verifier(VerifierRef);
_ ->
stop_verifier(VerifierRef)
end,
combine_return_codes(Output1, Output2).

combine_return_codes(0, 0) -> 0;
Expand Down
19 changes: 12 additions & 7 deletions test/http_end_to_end_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ verify_producer(_Config) ->
FilePath = <<"./pacts">>,
Protocol = <<"http">>,
StateChangePath = list_to_binary("http://localhost:" ++ integer_to_list(Port) ++ "/pactStateChange"),
BrokerOpts = #{
broker_url => <<"http://localhost:9292/">>,
broker_username => <<"pact_workshop">>,
broker_password => <<"pact_workshop">>,
enable_pending => 1,
consumer_version_selectors => thoas:encode(#{})
},
ProviderOpts = #{
name => Name,
version => Version,
Expand All @@ -203,13 +210,7 @@ verify_producer(_Config) ->
port => Port,
base_url => Path,
branch => Branch,
pact_source_opts => #{
broker_url => <<"http://localhost:9292/">>,
broker_username => <<"pact_workshop">>,
broker_password => <<"pact_workshop">>,
enable_pending => 1,
consumer_version_selectors => thoas:encode(#{})
},
pact_source_opts => BrokerOpts,
state_change_url => StateChangePath,
% message_providers => #{
% <<"a weather data message">> => {message_pact_SUITE, generate_message, [23.5, 20, 75.0]}
Expand All @@ -222,6 +223,10 @@ verify_producer(_Config) ->
ProviderOpts1 = ProviderOpts#{pact_source_opts => #{file_path => FilePath}},
{ok, VerifierRef1} = pact_verifier:start_verifier(Name, ProviderOpts1),
Output1 = pact_verifier:verify(VerifierRef1),
ProviderOpts2 = ProviderOpts#{pact_source_opts => maps:put(file_path, FilePath, BrokerOpts)},
{ok, VerifierRef2} = pact_verifier:start_verifier(Name, ProviderOpts2),
Output2 = pact_verifier:verify(VerifierRef2),
?assertEqual(0, Output1),
?assertEqual(0, Output),
?assertEqual(0, Output2),
animal_service:stop(HttpdPid).

0 comments on commit 8964182

Please sign in to comment.