pact 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae64ff5080cc286c9a913c8ad1e06d99c35961f687eabe3e99c5bcaac6078aeb
4
- data.tar.gz: 8fdbd4c74eb3e5c2cf57300ce269cb7e48f52fb83e5886f8e7aee08e97274d9a
3
+ metadata.gz: a7025748777b864b3e23efaf7ac0cbdd79f41e52300737651a2dc6f20023c44b
4
+ data.tar.gz: 27e691b749816d4cf746279bcb68f6fca740c1718b8213fa7d134ed8c9882e8c
5
5
  SHA512:
6
- metadata.gz: 7b01cb166524d3fdc62d7a34ecacd922281d63885cb4cc48cc4ba3d4d5007511d5b2263b6697060cc443fda3efcdec45d2d54d182e6b9f1e9a9d9f3ac593cb36
7
- data.tar.gz: acbf67bc8d3b23c85fbbcda46cdbf29297fd2eb859430536d58537ff055fb64ac4d6f9c28d6fee78324ebd33b9e534c6dd2e26dd454376dea9b8ea8aa28eb7e6
6
+ metadata.gz: 572d6976b61a36b63c46433bee409d0f45bb1fdb44139c1440f15b77d5c0ed7c6e15fd348d5ca392a1e1cf0dd0f0919d16bf54e129878e4a07bcd0dcee6fc517
7
+ data.tar.gz: ee765594f4b73945b8a9d2bbd1dfa199b6ac73863bd1aa066d1e795e71f87d5152c26ba057788e5c1bec2520345205137e03f8930767a570b6dc20a0c46dee45
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ <a name="v2.0.2"></a>
2
+ ### v2.0.2 (2026-08-12)
3
+
4
+ #### Bug Fixes
5
+
6
+ * ensure pactffi_init_with_log_level is called when instantiating pact ([efa5deb](/../../commit/efa5deb))
7
+ * consumer_version_selectors are silently discarded ([a0a9cf4](/../../commit/a0a9cf4))
8
+ * fail early if no pacts found for verification ([3546fdc](/../../commit/3546fdc))
9
+
1
10
  <a name="v2.0.1"></a>
2
11
  ### v2.0.1 (2026-05-29)
3
12
 
@@ -171,12 +171,10 @@ module Pact
171
171
  end
172
172
 
173
173
  def init_pact
174
+ PactFfi.init_with_log_level(Native::Logger::LOG_LEVELS[@pact_config.log_level])
174
175
  handle = PactFfi.new_pact(@pact_config.consumer_name, @pact_config.provider_name)
175
176
  PactFfi.with_specification(handle, PactFfi::FfiSpecificationVersion["SPECIFICATION_VERSION_V4"])
176
177
  PactFfi.with_pact_metadata(handle, "pact-ruby", "pact-ffi", PactFfi.version)
177
-
178
- Pact::Native::Logger.log_to_stdout(@pact_config.log_level)
179
-
180
178
  handle
181
179
  end
182
180
 
@@ -139,12 +139,11 @@ module Pact
139
139
  end
140
140
 
141
141
  def init_pact
142
+ PactFfi.init_with_log_level(Native::Logger::LOG_LEVELS[@pact_config.log_level])
142
143
  handle = PactFfi.new_pact(pact_config.consumer_name, pact_config.provider_name)
143
144
  PactFfi.with_specification(handle, PactFfi::FfiSpecificationVersion["SPECIFICATION_VERSION_#{pact_config.pact_specification}"])
144
145
  PactFfi.with_pact_metadata(handle, "pact-ruby", "pact-ffi", PactFfi.version)
145
146
 
146
- Pact::Native::Logger.log_to_stdout(pact_config.log_level)
147
-
148
147
  handle
149
148
  end
150
149
 
@@ -172,12 +172,10 @@ module Pact
172
172
  end
173
173
 
174
174
  def init_pact
175
+ PactFfi.init_with_log_level(Native::Logger::LOG_LEVELS[@pact_config.log_level])
175
176
  handle = PactFfi::MessageConsumer.new_message_pact(@pact_config.consumer_name, @pact_config.provider_name)
176
177
  PactFfi.with_specification(handle, PactFfi::FfiSpecificationVersion["SPECIFICATION_VERSION_V4"])
177
178
  PactFfi.with_pact_metadata(handle, "pact-ruby", "pact-ffi", PactFfi.version)
178
-
179
- Pact::Native::Logger.log_to_stdout(@pact_config.log_level)
180
-
181
179
  handle
182
180
  end
183
181
 
@@ -39,12 +39,11 @@ module Pact
39
39
  end
40
40
 
41
41
  def init_pact
42
+ PactFfi.init_with_log_level(Native::Logger::LOG_LEVELS[@log_level])
42
43
  handle = PactFfi.new_pact(consumer_name, provider_name)
43
44
  PactFfi.with_specification(handle, @pact_specification)
44
45
  PactFfi.with_pact_metadata(handle, "pact-ruby", "pact-ffi", PactFfi.version)
45
46
 
46
- Pact::Native::Logger.log_to_stdout(@log_level)
47
-
48
47
  handle
49
48
  end
50
49
  end
@@ -148,12 +148,10 @@ module Pact
148
148
  end
149
149
 
150
150
  def init_pact
151
+ PactFfi.init_with_log_level(Native::Logger::LOG_LEVELS[@pact_config.log_level])
151
152
  handle = PactFfi.new_pact(@pact_config.consumer_name, @pact_config.provider_name)
152
153
  PactFfi.with_specification(handle, PactFfi::FfiSpecificationVersion["SPECIFICATION_VERSION_V4"])
153
154
  PactFfi.with_pact_metadata(handle, "pact-ruby", "pact-ffi", PactFfi.version)
154
-
155
- Pact::Native::Logger.log_to_stdout(@pact_config.log_level)
156
-
157
155
  handle
158
156
  end
159
157
 
@@ -170,12 +170,10 @@ module Pact
170
170
  end
171
171
 
172
172
  def init_pact
173
+ PactFfi.init_with_log_level(Native::Logger::LOG_LEVELS[@pact_config.log_level])
173
174
  handle = PactFfi.new_pact(@pact_config.consumer_name, @pact_config.provider_name)
174
175
  PactFfi.with_specification(handle, PactFfi::FfiSpecificationVersion["SPECIFICATION_VERSION_V4"])
175
176
  PactFfi.with_pact_metadata(handle, "pact-ruby", "pact-ffi", PactFfi.version)
176
-
177
- Pact::Native::Logger.log_to_stdout(@pact_config.log_level)
178
-
179
177
  handle
180
178
  end
181
179
 
@@ -157,12 +157,10 @@ module Pact
157
157
  end
158
158
 
159
159
  def init_pact
160
+ PactFfi.init_with_log_level(Native::Logger::LOG_LEVELS[@pact_config.log_level])
160
161
  handle = PactFfi.new_pact(@pact_config.consumer_name, @pact_config.provider_name)
161
162
  PactFfi.with_specification(handle, PactFfi::FfiSpecificationVersion["SPECIFICATION_VERSION_V4"])
162
163
  PactFfi.with_pact_metadata(handle, "pact-ruby", "pact-ffi", PactFfi.version)
163
-
164
- Pact::Native::Logger.log_to_stdout(@pact_config.log_level)
165
-
166
164
  handle
167
165
  end
168
166
 
@@ -5,7 +5,7 @@ require 'pact/ffi/logger'
5
5
  module Pact
6
6
  module Native
7
7
  module Logger
8
- LOG_LEVELS = {
8
+ LOG_FILTERS = {
9
9
  off: PactFfi::FfiLogLevelFilter['LOG_LEVEL_OFF'],
10
10
  error: PactFfi::FfiLogLevelFilter['LOG_LEVEL_ERROR'],
11
11
  warn: PactFfi::FfiLogLevelFilter['LOG_LEVEL_WARN'],
@@ -14,10 +14,19 @@ module Pact
14
14
  trace: PactFfi::FfiLogLevelFilter['LOG_LEVEL_TRACE']
15
15
  }.freeze
16
16
 
17
+ LOG_LEVELS = {
18
+ off: PactFfi::FfiLogLevel['LOG_LEVEL_OFF'],
19
+ error: PactFfi::FfiLogLevel['LOG_LEVEL_ERROR'],
20
+ warn: PactFfi::FfiLogLevel['LOG_LEVEL_WARN'],
21
+ info: PactFfi::FfiLogLevel['LOG_LEVEL_INFO'],
22
+ debug: PactFfi::FfiLogLevel['LOG_LEVEL_DEBUG'],
23
+ trace: PactFfi::FfiLogLevel['LOG_LEVEL_TRACE']
24
+ }.freeze
25
+
17
26
  def self.log_to_stdout(log_level)
18
- raise 'invalid log level for PactFfi::FfiLogLevelFilter' unless LOG_LEVELS.key?(log_level)
27
+ raise 'invalid log level for PactFfi::FfiLogLevelFilter' unless LOG_FILTERS.key?(log_level)
19
28
 
20
- PactFfi::Logger.log_to_stdout(LOG_LEVELS[log_level]) unless log_level == :off
29
+ PactFfi::Logger.log_to_stdout(LOG_FILTERS[log_level]) unless log_level == :off
21
30
  end
22
31
  end
23
32
  end
@@ -3,6 +3,7 @@
3
3
  require 'pact/ffi/verifier'
4
4
  require 'pact/native/logger'
5
5
  require 'pact/native/blocking_verifier'
6
+ require 'json'
6
7
 
7
8
  module Pact
8
9
  module Provider
@@ -175,7 +176,7 @@ module Pact
175
176
  PactFfi::Verifier.set_provider_info(pact_handle, @pact_config.provider_name, '', '', 0, '')
176
177
  end
177
178
 
178
- def add_provider_transport(pact_handle)
179
+ def add_provider_transport(_pact_handle)
179
180
  raise PactImplementationRequired, 'Implement #add_provider_transport in a subclass'
180
181
  end
181
182
 
@@ -200,6 +201,7 @@ module Pact
200
201
  if @pact_config.pact_broker_proxy_url.blank? && @pact_config.pact_uri.blank?
201
202
  path = @pact_config.pact_dir || (defined?(Rails) ? Rails.root.join('pacts').to_s : 'pacts')
202
203
  logger.info("[verifier] pact broker url or pact uri is not set, using directory #{path} as a verification source") # rubocop:disable Layout/LineLength
204
+ ensure_provider_has_matching_pacts!(path)
203
205
  return PactFfi::Verifier.add_directory_source(handle, path)
204
206
  end
205
207
 
@@ -213,15 +215,15 @@ module Pact
213
215
  PactFfi::Verifier.add_file_source(handle, @pact_config.pact_uri)
214
216
  end
215
217
  else
216
- logger.info("[verifier] using pact broker url #{@pact_config.broker_url} with consumer selectors: #{JSON.dump(consumer_selectors)} as a verification source") # rubocop:disable Layout/LineLength
217
- consumer_selectors = [] if consumer_selectors.nil?
218
- filters = consumer_selectors.map do |selector|
218
+ selectors = consumer_selectors || []
219
+ logger.info("[verifier] using pact broker url #{@pact_config.broker_url} with consumer selectors: #{JSON.dump(selectors)} as a verification source") # rubocop:disable Layout/LineLength
220
+ filters = selectors.map do |selector|
219
221
  FFI::MemoryPointer.from_string(JSON.dump(selector).to_s)
220
222
  end
221
223
  filters_ptr = FFI::MemoryPointer.new(:pointer, filters.size + 1)
222
224
  filters_ptr.write_array_of_pointer(filters)
223
225
  PactFfi::Verifier.broker_source_with_selectors(handle, @pact_config.pact_broker_proxy_url,
224
- @pact_config.broker_username, @pact_config.broker_password, @pact_config.broker_token, bool_to_int(@pact_config.enable_pending), @pact_config.include_wip_pacts_since, c_provider_version_tags, c_provider_version_tags_size, @pact_config.provider_version_branch, filters_ptr, consumer_selectors.size, c_consumer_version_tags, c_consumer_version_tags_size) # rubocop:disable Layout/LineLength
226
+ @pact_config.broker_username, @pact_config.broker_password, @pact_config.broker_token, bool_to_int(@pact_config.enable_pending), @pact_config.include_wip_pacts_since, c_provider_version_tags, c_provider_version_tags_size, @pact_config.provider_version_branch, filters_ptr, selectors.size, c_consumer_version_tags, c_consumer_version_tags_size) # rubocop:disable Layout/LineLength
225
227
  end
226
228
  end
227
229
 
@@ -254,6 +256,27 @@ module Pact
254
256
 
255
257
  [DEFAULT_CONSUMER_SELECTORS]
256
258
  end
259
+
260
+ def ensure_provider_has_matching_pacts!(path)
261
+ return unless @pact_config.fail_if_no_pacts_found
262
+
263
+ pact_paths = Dir.glob(File.join(path, '**', '*.json'))
264
+ raise VerifierError.new("No pact files found in #{path}") if pact_paths.empty?
265
+
266
+ return if pact_paths.any? { |p| pact_file_provider_name(p) == @pact_config.provider_name }
267
+
268
+ providers = pact_paths.map { |p| pact_file_provider_name(p) }.compact.uniq.sort
269
+ raise VerifierError.new(
270
+ "No pacts found for provider \"#{@pact_config.provider_name}\" in directory #{path}. " \
271
+ "Found providers: #{providers.join(', ')}"
272
+ )
273
+ end
274
+
275
+ def pact_file_provider_name(path)
276
+ JSON.parse(File.read(path)).dig('provider', 'name')
277
+ rescue StandardError
278
+ nil
279
+ end
257
280
  end
258
281
  end
259
282
  end
data/lib/pact/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # Remember to bump pact-provider-proxy when this changes major version
2
2
  module Pact
3
- VERSION = "2.0.1"
3
+ VERSION = "2.0.2"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Fraser
@@ -513,7 +513,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
513
513
  - !ruby/object:Gem::Version
514
514
  version: '0'
515
515
  requirements: []
516
- rubygems_version: 4.0.14
516
+ rubygems_version: 4.0.18
517
517
  specification_version: 4
518
518
  summary: Enables consumer driven contract testing, providing a mock service and DSL
519
519
  for the consumer project, and interaction playback and verification for the service