Matt (pactflow.io / pact-js / pact-go)
Vladimir Vásquez Hernández
07/16/2024, 2:28 PMVladimir Vásquez Hernández
07/16/2024, 8:16 PMVladimir Vásquez Hernández
07/16/2024, 8:37 PMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
--log
flag - wherever that is set the logs should beVladimir Vásquez Hernández
07/18/2024, 12:09 AM/tmp
folder nor pact interactions file too.
I also verify the SRCROOT
variable and it is proper.
Finally, I got the standalone pact bin value from the value of which pact-mock-service
i don't understand what is going wrong :sVladimir Vásquez Hernández
07/18/2024, 12:16 AMPATH=/opt/homebrew/bin/pact-mock-service:$PATH
pact-mock-service start --pact-specification-version 2.0.0 --log "${SRCROOT}/tmp/pact.log" --pact-dir "${SRCROOT}/tmp/pacts" -p 1234
Matt (pactflow.io / pact-js / pact-go)
/tmp
directory, it’s in a directory inside your project.Matt (pactflow.io / pact-js / pact-go)
/path/to/swift/project/tmp
I thinkMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Vladimir Vásquez Hernández
07/18/2024, 2:31 PM/path/to/swift/project/tmp
My badVladimir Vásquez Hernández
07/18/2024, 2:32 PMmock WARN: Please note: we are tracking events anonymously to gather important usage statistics like Pact-Ruby version and operating system. To disable tracking, set the 'PACT_DO_NOT_TRACK' environment variable to 'true'.
INFO WEBrick 1.8.1
INFO ruby 3.3.3 (2024-06-12) [arm64-darwin22]
INFO WEBrick::HTTPServer#start: pid=5982 port=1234
Vladimir Vásquez Hernández
07/18/2024, 2:35 PMpact.log
file, and a mock-service-1234.pid
file with 5982
content.Vladimir Vásquez Hernández
07/18/2024, 9:29 PMERROR -- : Error ocurred in mock service: NoMethodError - undefined method `empty?' for an instance of Pact::ArrayLike
ERROR -- : /opt/homebrew/Cellar/pact-ruby-standalone/2.4.6/lib/vendor/ruby/3.3.0/gems/pact-support-1.20.0/lib/pact/consumer_contract/query_string.rb:42:in `empty?'
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Vladimir Vásquez Hernández
07/18/2024, 10:37 PMMatt (pactflow.io / pact-js / pact-go)
Vladimir Vásquez Hernández
07/22/2024, 9:43 PMfailed - Failed to verify Pact! Actual request does not match expected interactions...
Reason:
Missing request
....
_NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <3DE3D57F-F4A8-4BC6-AC99-DC7B106F80D0>.<1>"
), NSLocalizedDescription=Could not connect to the server., NSErrorFailingURLStringKey=<http://127.0.0.1:4034/calculator?amount=5000.0&location=bogota&paymentMethod=&tip=0.15&vat=0.19>, NSErrorFailingURLKey=<http://127.0.0.1:4034/calculator?amount=5000.0&location=bogota&paymentMethod=&tip=0.15&vat=0.19>, _kCFStreamErrorDomainKey=1}
There are no logs generated :SMatt (pactflow.io / pact-js / pact-go)
Marko (IttyBittyApps / pact-swift)
07/22/2024, 10:38 PMpact_ffi
layer) sitting on a branch where it can be defined when instantiating the service. But, have absolutely no time to clean it up and make it RC.
But that doesn't seem to be the problem here. It's the Swift's API client implementation that's throwing the error because it's failing to make the request outside the consumer implementation for some reason. If it would have managed to hit pact_ffi
and there was an error on the mocked provider, the error would definitely not be a _NS
error.
pact-consumer-swift
relies on its own API client implementation that makes the request to pact-ruby-standalone
. Apple made some changes to how Swift's networking works and we figured using 127.0.0.1
was a workaround.
I'm quite sure I've never had to use anything else than <https://localhost>
when using PactSwift
.
There's logs that can be enabled by setting PACT_ENABLE_LOGGING=all
. I assume it's an Xcode project and not a library/executable in a Swift package?Marko (IttyBittyApps / pact-swift)
07/22/2024, 10:45 PMpact-consumer-swift
(for now, until I magically come up with extra time in a day and energy to get through it).
This: https://pact-foundation.slack.com/archives/C9VBGNT4K/p1721338177462059?thread_ts=1721083156.996839&cid=C9VBGNT4K is a Ruby issue. Something in pact-ruby-server
or pact-ruby-standalone
isn't quite right.Vladimir Vásquez Hernández
07/22/2024, 10:59 PMPactSwift: Setting up pact test: {"provider": ...."consumer":{"name":"Example-app-for-testing"}}
...
PactSwift: Setting up pact mock server for consumer verification: {"interactions" .. "consumer":{"name":"Example-app-for-testing"},"metadata":{"pactSpecification":{"version":"3.0.0"},"pactSwift":{"version":"1.1.0"}}}
..
PactSwift: Starting up mock server for pact interaction test:
..
PactSwift: Mock server started on port 4842:
..
failed - Failed to verify Pact! Actual request does not match expected interactions...
Reason:
Missing request
Expected:
GET /calculator
...
PactSwift: Shutting down mock server on port 4842:
PactSwift: Shutting down mock server on port 4842:
...
nw_socket_handle_socket_event [C1:2] Socket SO_ERROR [61: Connection refused]
Task <5E1EEB49-A516-4A65-9FB1-15DCE4D9EC3A>.<1> HTTP load failed, 0/0 bytes (error code: -1004 [1:61])
Task <5E1EEB49-A516-4A65-9FB1-15DCE4D9EC3A>.<1> finished with error [-1004] Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server."
...
_NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <5E1EEB49-A516-4A65-9FB1-15DCE4D9EC3A>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <5E1EEB49-A516-4A65-9FB1-15DCE4D9EC3A>.<1>"
), NSLocalizedDescription=Could not connect to the server., NSErrorFailingURLStringKey=<http://127.0.0.1:4842/calculator?amount=5000.0&location=bogota&paymentMethod=&tip=0.15&vat=0.19>, NSErrorFailingURLKey=<http://127.0.0.1:4842/calculator?amount=5000.0&location=bogota&paymentMethod=&tip=0.15&vat=0.19>, _kCFStreamErrorDomainKey=1}
Marko (IttyBittyApps / pact-swift)
07/22/2024, 11:06 PMGET /calculator
request successfully to the right address.
Your Swift code implementing your API client is faulty.
What's the transport protocol you've set up for mock service? Are you sure you want to use http and not https? Change the domain back to localhost
? What's the `URLSession`'s response when debugging?Matt (pactflow.io / pact-js / pact-go)
But that doesn’t seem to be the problem here.the problem is that Vladimir has to verify the contracts with a language that doesn’t supportn spec v3 or greater, so if they could set the spec version to 2 it would resolve that issue. As they can’t, then he needs to go back to the previous library and we need to look at the test setup as per https://pact-foundation.slack.com/archives/C9VBGNT4K/p1721340247509179?thread_ts=1721083156.996839&cid=C9VBGNT4K to find out why it’s not working. I think something is being set on the query string that’s incorrect, but I can’t see without the code
Marko (IttyBittyApps / pact-swift)
07/22/2024, 11:28 PMERROR -- : Error ocurred in mock service: NoMethodError - undefined method `empty?' for an instance of Pact::ArrayLike
ERROR -- : /opt/homebrew/Cellar/pact-ruby-standalone/2.4.6/lib/vendor/ruby/3.3.0/gems/pact-support-1.20.0/lib/pact/consumer_contract/query_string.rb:42:in `empty?'
I've given up on keeping up to date with pact-swift-standalone
when homebrew formula was transferred to pact-foundation
🤷Marko (IttyBittyApps / pact-swift)
07/22/2024, 11:29 PMMatt (pactflow.io / pact-js / pact-go)
Vladimir Vásquez Hernández
07/23/2024, 1:29 AM.withRequest(
method: .GET,
path: "/calculator",
query: [
"amount": [Matcher.SomethingLike(5000.0)],
"vat": [Matcher.SomethingLike(0.19)],
"tip": [Matcher.SomethingLike(0.15)],
"location": [Matcher.SomethingLike("bogota")],
"paymentMethod": [Matcher.SomethingLike("")]
]
)
It is important to say that amount, vat and tip are Double into our backendMarko (IttyBittyApps / pact-swift)
07/23/2024, 1:34 AMpaymentMethod
as a required query value?
And... and if I remember right, .withRequest
doesn't really support matchers. Also, you are (should be) in complete control of the request so you should be able to set the .withRequest
without matchers.Marko (IttyBittyApps / pact-swift)
07/23/2024, 1:35 AMMatt (pactflow.io / pact-js / pact-go)
Vladimir Vásquez Hernández
07/23/2024, 1:48 AMVladimir Vásquez Hernández
07/23/2024, 2:07 AMVladimir Vásquez Hernández
07/23/2024, 2:09 AMMarko (IttyBittyApps / pact-swift)
07/23/2024, 2:13 AMMarko (IttyBittyApps / pact-swift)
07/23/2024, 2:15 AMExampleAppForTesting
project. Any chance of sharing this project? Maybe through a private repo and allowing me access to it? First remove any sensitive info if present, obviously. It's a bit hard to debug through slack messages.Vladimir Vásquez Hernández
07/23/2024, 2:18 AMVladimir Vásquez Hernández
07/23/2024, 2:21 AMMarko (IttyBittyApps / pact-swift)
07/23/2024, 2:24 AM