pact-foundation / pact-stub-server-archived Goto Github PK
View Code? Open in Web Editor NEWWraps the Pact Rust mock server in a Docker container
License: MIT License
Wraps the Pact Rust mock server in a Docker container
License: MIT License
We have been using the pact-stub-server in our CI systems since version v0.0.10 with great success, but noticed the new version is now broken when using our existing pact files against it.
We've noticed that if we curl a 'GET' request to a running container, it works, as do all 'GET' request interactions. However on using a 'POST' the curl request sits and does nothing, and the container does not register any connection or matching taking place as it does with a GET request. There is no output at all and the container is then non-responsive from that point after. Trying a previously working 'GET' to this container now does not work, with no container output.
We've tested this in parallel with a v0.0.10 container image, which works perfectly. As you do not appear to be maintaining a large number of previous tags in Dockerhub, we run the risk of our now pinned container image version being removed.
Any ideas why this might be the case with 'POST' requests?
Hello,
We were using the pact-stub-server on version 0.2.1, however we realized that it's not fast enough.
Our microservice was running on springBoot and does 2 syncrhonous calls in succession, however the pact server is only able to respond to the first one, and on the second one we get a I/O error and we don't see any requests going the pact server.
It seems that the pact-server doesn't close the port quick enough? something in that matter that caused it to not being able to react fast enough to the second request.
If you want code samples or versioning please write me, We fixed it by switching to mock-server but it'd be nice if we can still use the pact-server.
I have a interaction which expects the following request,
withRequest: { method: 'GET', path: '/api/objects', query: { page: somethingLike('1') } }
the pact file generated for this interaction has the following matchers,
"Get object", "request": { "method": "GET", "path": "/api/objects", "query": "page=1", "matchingRules": { "$.query.page[0]": { "match": "type" } } }
while using the stub server, i am getting the response only when i make the call with "/api/objects?page=1", when i change the request parameter value ""/api/objects?page=2" it is not getting matched, because of which no response is returned.
Please find below the logs from pact-stub-server,
===> Received request: Request { method: "GET", path: "/api/objects", query: Some({"page": ["2"]}), headers: Some({"Postman-Token": "866f0fef-1ecd-122c-801b-4480d74c63d2", "Authorization": "Basic Og==", "Accept": "/", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36", "Host": "localhost:18119", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,en;q=0.9,it;q=0.8", "Connection": "keep-alive", "Content-Type": "application/json", "Cache-Control": "no-cache"}), body: Empty, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }
service | 16:27:40 [INFO] body: ''
service |
service | 16:27:40 [INFO] comparing to expected request: Request { method: "GET", path: "/api/objects", query: Some({"page": ["1"]}), headers: None, body: Missing, matching_rules: MatchingRules { rules: {"query": Category { name: "query", rules: {"page[0]": RuleList { rules: [Type], rule_logic: And }} }} }, generators: Generators { categories: {} } }
service | 16:27:40 [WARN] No matching request found, sending 404 Not Found
Hi,
On OSX 10.13.6 (High-Sierra)
Docker CE: tested on both 18.03.1-ce-mac65 (24312)
and 18.06.0-ce-mac70 (26399)
(both are on the stable channel)
command:
docker run -t -p 7777:7777 -v "$(pwd)/project/pacts:/app/pacts" pactfoundation/pact-stub-server -p 7777 -d pacts
fails with the following output:
/app/pact-stub-server: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
when trying with tagged image v0.0.10 it's working fine
So , I have pact file which successfully works till v0.0.9
But when i try to upgrade the version , pact file which contains
Please note : other pact files are working fine .
I cant see any logs getting published to it when it is upgraded version higher than v0.0.9
Logs : Attaching to flex-master
flex-master | 13:28:43 [INFO] Server started on port 30044
flex-search-app-flex-master.txt
Also console shows 200 response but no data under response
I have uploaded the json file which is generated after running the test
Please let me know if any further information is required
Docs are suggesting you can use existing pact definitions to drive the stub server.
How do you put the server into different states?
Eg. resource exists for /item/123 but return error 404 for /item/0
NB:- an example repo with this issue is available here
https://github.com/YOU54F/pact-consumer-example-typescript
Where a pact provider is setup with the following 2 request matchers
withRequest: {
body: requestResponse.TestRequest("happyPath"),
headers: {
"Content-Type": "application/json"
},
method: "POST",
path: "/test"
}
};
withRequest: {
body: requestResponse.TestRequest(""),
headers: {
"Content-Type": "application/json"
},
method: "POST",
path: "/test"
}
When a request is sent with no body, a duplicate match is found and the first result is returned
curl -X POST \
http://localhost:8080/test \
-H 'Content-Type: application/json'
Pact stub server logs :- [WARN] Found more than one pact request for method POST and path '/test', using the first one
Actual Result :- Returns the first matching response (false positive)
Expected Result :- Return a 404 and no body, as only a portion of the request was matched (no body)
git clone [email protected]:YOU54F/pact-consumer-example-typescript.git
yarn install
yarn build
yarn run pact-test
docker-compose up
Run the following request -
curl -X POST \
http://localhost:8080/test \
-H 'Content-Type: application/json'
Expected Result = Returns an empty response body and a 404
Actual Result = Returns the below body and a 200
{
"testResult": "validRequest"
}
Pact stub server logs spit out the following
[WARN] Found more than one pact request for method POST and path '/test', using the first one
When using 'docker stop' the container is stopped after 10 seconds. This means that SIGTERM is not enough and docker-stop sends SIGKILL.
Dockerfile uses exec form of ENTRYPOINT (https://www.ctl.io/developers/blog/post/gracefully-stopping-docker-containers/), so I don't understand why SIGTERM does not work. Maybe some magic with Rust comes into play.
Since yesterday we're not able to pull the older version..did something break releasing the newer version?
We've updated to v.0.2.0 and we're still working but maybe you can have a look why it's broken
Pact stub version 0.2.3
I am trying to stub some api using pact stub (I use pact file from pact broker by URL). By pact stub cannot match my api URL that contains regular expression with saved pact file.
Note: pact stab can only match path if I will replace '\' to '' in pact file.
C# test that created pact file:
[Fact]
public async Task SearchHistoryAndSettingsController_TrackingStatus_ReturnedTrue()
{
const string path = "/api/user/tracking";
_mockProviderService.UponReceiving("Get Tracking Status")
.With(new ProviderServiceRequest
{
Method = HttpVerb.Get,
Path = Match.Regex(path, $"(?i)({path})"), #ignore url case
Headers = new Dictionary<string, object>
{
{ "Accept", "text/plain" }
},
})
.WillRespondWith(new ProviderServiceResponse
{
Status = StatusCodes.Status200OK,
Headers = new Dictionary<string, object>
{
{ "Content-Type", "text/plain; charset=utf-8" }
},
Body = Match.Regex("true", "(?i)(true)")
});
..
}
Pact file from pact Broker:
{
"consumer": {
"name": "SearchHistory"
},
"provider": {
"name": "Settings"
},
"interactions": [
{
"description": "Get Tracking Status",
"request": {
"method": "get",
"path": "/api/user/tracking",
"headers": {
"Accept": "text/plain"
},
"matchingRules": {
"$.path": {
"match": "regex",
"regex": "(?i)(\\/api\\/user\\/tracking)"
}
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "text/plain; charset=utf-8"
},
"body": "true",
"matchingRules": {
"$.body": {
"match": "regex",
"regex": "(?i)(true)"
}
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
This is error from Pact stub debug console:
10:39:01 [INFO] comparing to expected Request ( method: GET, path: /api/user/tracking, query: None, headers: Some({"Accept": "text/plain"}), body: Missing )
10:39:01 [DEBUG] pact_matching: body: ''
10:39:01 [DEBUG] pact_matching: matching_rules: MatchingRules { rules: {"path": Category { name: "path", rules: {"": RuleList { rules: [Regex("(?i)(\/api\/user\/tracking)")], rule_logic: And }} }} }
10:39:01 [DEBUG] pact_matching: generators: Generators { categories: {} }
10:39:01 [DEBUG] pact_matching::matchers: String -> String: comparing '/api/user/tracking' to '/api/user/tracking' using Regex("(?i)(\/api\/user\/tracking)")
10:39:01 [DEBUG] pact_matching: expected content type = 'text/plain', actual content type = 'text/plain'
10:39:01 [DEBUG] pact_matching: --> Mismatches: [PathMismatch { expected: "/api/user/tracking", actual: "/api/user/tracking", mismatch: "'(?i)(\/api\/user\/tracking)' is not a valid regular expression - regex parse error:\n (?i)(\/api\/user\/tracking)\n ^^\nerror: unrecognized escape sequence" }]
10:39:01 [WARN] No matching request found, sending 404 Not Found
10:39:01 [INFO] <=== Sending Response ( status: 404, headers: None, body: Missing )
10:39:01 [DEBUG] pact_stub_server::pact_support: body: ''
10:39:01 [DEBUG] pact_stub_server::pact_support: matching_rules: MatchingRules { rules: {} }
10:39:01 [DEBUG] pact_stub_server::pact_support: generators: Generators { categories: {} }
10:39:01 [DEBUG] hyper::proto::h1::io: flushed 114 bytes
10:39:01 [DEBUG] tokio_reactor: dropping I/O source: 1
I'm trying to start the latest Docker image (v.0.4.4) but am getting the error:
./pact-stub-server: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by ./pact-stub-server)
v0.4.3 works just fine.
Thanks
Nick
I suspect the stub server is not working with Lerna, when dependencies are hoisted.
When starting the stub server, it throws a bunch of errors. The same pact file works when dependencies are not hoisted to the root.
Has anyone been able to use it with hoisted Lerna?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.