pact-foundation / pact-go Goto Github PK
View Code? Open in Web Editor NEWGolang version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
Home Page: http://pact.io
License: MIT License
Golang version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
Home Page: http://pact.io
License: MIT License
We don't need this any more.
Is there any way to limit which ports interactions can map to? i.e. main server is 6666 and then 20100-20200 are used for interactions?
Right now we just expose every port over 1024 in our container but would like a little more constraints than that.
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/william.cox/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/js/8ycxvlln2ljgdjyy834g14rr0000gq/T/go-build397368137=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
I'm trying to set up a test with a Pact::Term as part of the WithRequest.
It looks like this:
Given("The score_server has data to send us with model IDs").
UponReceiving("a GET request to v2 endpoint").
WithRequest(dsl.Request{
Method: "GET",
Path: "/scores/v2",
Query: "threshold=0.9",
Headers: map[string]string{
"If-Modified-Since": dsl.Term(imsString,
`[a-zA-Z]{3}, [0-9]{2} [a-zA-Z]{3} [0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2} [A-Z]{3}`),
"x-api-key": apiKey}, }).
...
Essentially I'm trying to allow for variable If-Modified-Since
datestrings in my Request headers
but when I run the tests I get errors saying,
* Expected "\n\t\t{\n\t\t\t\"json_class\": \"Pact::Term\",\n\t\t\t\"data\": {\n\t\t\t \"generate\": \"Tue, 20 Mar 2018 11:38:04 EDT\",\n\t\t\t \"matcher\": {\n\t\t\t \"json_class\": \"Regexp\",\n\t\t\t \"o\": 0,\n\t\t\t \"s\": \"[a-zA-Z]{3}, [0-9]{2} [a-zA-Z]{3} [0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2} [A-Z]{3}\"\n\t\t\t }\n\t\t\t}\n\t\t}" but got "Tue, 20 Mar 2018 11:38:04 EDT" at $.headers.If-Modified-Since
It appears that the dsl.Term
isn't being properly validated/parsed when in the WithRequest
.
Because, it sucks.
The Daemon was originally implemented due to two reasons:
npm
for NodeJS or 'pip' for Python. These package management facilities typically have build or installation hooks that allow us to customise the installation at package retrieval time. In those instances, it's easy to determine the current os/arch and pull in the appropriateA daemon was a separate install step that decoupled the DSL from this uglyness, in turn creating it's own uglyness:
go get
To work around the limitations and address the issues, these are some options that I can think of:
PATH
. The DSL will then attempt to start the pact-*
binaries and fail with a helpful error if it can't find them.
This could potentially be automated via OS package-managers like brew
, rpm
, curl
or chocolatey
for Windows
or perhaps could be provided by a CLI step provided by the package itself i.e.
go get github.com/pact-foundation/pact-go
sudo pact-go install
# pact is now fully installed, good to go!
When using a types.VerifyRequest with both a BrokerURL and Verbose: true
, the provider verification fails with the following output:
pact.go:264: Error: error verifying provider: invalid character 'D' looking for beginning of value STDERR: INFO: Reading pact at http://localhost/pacts/provider/Twilio%20Adapter/consumer/Message%20Router/version/0.0.0 STDOUT: DEBUG: Setting up provider state 'Short Code 33487 exists' for consumer 'Message Router' using provider state server at http://localhost:8000/setup
I, [2018-03-15T17:23:59.857280 #75950] INFO -- : post http://localhost:8000/setup
D, [2018-03-15T17:23:59.857358 #75950] DEBUG -- request: User-Agent: "Faraday v0.13.1"
Content-Type: "application/json"
I, [2018-03-15T17:23:59.861065 #75950] INFO -- Status: 200
D, [2018-03-15T17:23:59.861169 #75950] DEBUG -- response: date: "Thu, 15 Mar 2018 22:23:59 GMT"
content-length: "0"
connection: "close"
{"version":"3.7.0","examples":[{"id":"/Users/ahaynes/go/bin/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/provider/rspec.rb[1:1:1:1:1:1]","description":"has status code 200","full_description":"Verifying a pact between Message Router and Twilio Adapter Given Short Code 33487 exists A request to outbound with POST /outbound returns a response which has status code 200","status":"passed","file_path":"/Users/ahaynes/go/bin/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/provider/rspec.rb","line_number":127,"run_time":0.063953,"pending_message":null},{"id":"/Users/ahaynes/go/bin/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/provider/rspec.rb[1:1:1:1:1:3]","description":"has a matching body","full_description":"Verifying a pact between Message Router andTwilio Adapter Given Short Code 33487 exists A request to outbound with POST /outbound returns a response which has a matching body","status":"passed","file_path":"/Users/ahaynes/go/bin/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/provider/rspec.rb","line_number":144,"run_time":0.001683,"pending_message":null}],"summary":{"duration":0.106867,"example_count":2,"failure_count":0,"pending_count":0,"errors_outside_of_examples_count":0},"summary_line":"2 examples, 0 failures"}
FAIL
exit status 1
Setting Verbose to false
results in a passing verification.
go version
go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ahaynes/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/ahaynes/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/xq/1n2blw791kg99jzdqmw_ts30x0073c/T/go-build482731044=/tmp/go-build -gno-record-gcc-switches -fno-common"
Verbose mode should not cause failures that don't occur without it.
Verification fails to parse the output from something.
Error: error verifying provider: invalid character 'D' looking for beginning of value
pact.VerifyProvider(t, types.VerifyRequest{
ProviderBaseURL: "http://localhost:8000",
BrokerURL: "http://localhost:80",
ProviderStatesSetupURL: "http://localhost:8000/setup",
Verbose: true,
})
Consider forking the project and modifying the E2E test
Hi I'm trying to verify a create call that has a "name" field in which I want to pass "Jean-Marie de La Beaujardière"†
pact-go is blowing up in:
/usr/bin/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/json-1.8.3/lib/json/pure/parser.rb:171:in `encode': "\xC3" on US-ASCII (Encoding::InvalidByteSequenceError)
è in utf-8 is 0xc3 0xa8
If I change the è to e the pact verifies.
† a former co-worker whose name is great for finding bugs in name parsers, First name contains a hyphen, last name begins with a non-capital letter, has spaces in it, and has accented characters in it, whole name is longer than most.
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/william.cox/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/js/8ycxvlln2ljgdjyy834g14rr0000gq/T/go-build598867400=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
I'm writing Pact tests as part of a Golang application test system. I have several functions that each run a Pact test. They overwrite the previous functions pact definition such that my final pact.json
only has the last run test. How do I have separate test functions that all append to the pact test?
Example:
func TestDiffMetadataPact(t *testing.T) {
pact := &dsl.Pact{
Port: 6666,
Consumer: "Loader",
Provider: "score_server",
Host: "localhost",
}
defer pact.Teardown()
//....
var test = func() error {
URL := fmt.Sprintf("http://localhost:%d/scores", pact.Server.Port)
//test code goes here
return err
}
pact.
AddInteraction().
Given("There exists some data").
UponReceiving("A HEAD request").
WithRequest(dsl.Request{
Method: "HEAD",
Path: "/scores",
Query: "threshold=0.9",
Headers: map[string]string{"If-Modified-Since": imsString,
"x-api-key": "<api key>"},
}).
WillRespondWith(dsl.Response{
Status: 200,
Headers: map[string]string{"Content-Type": "text/plain",
"X-Api-Content-Length": contentLength,
"last-modified": time.Now().Format(time.RFC1123)},
})
// Verify
if err := pact.Verify(test); err != nil {
log.Fatalf("Error on Verify: %v", err)
}
}
func TestDiffContentPact(t *testing.T) {
pact := &dsl.Pact{
Port: 6666,
Consumer: "Loader",
Provider: "score_server",
Host: "localhost",
}
defer pact.Teardown()
// ...
var test = func() error {
URL := fmt.Sprintf("http://localhost:%d/scores", pact.Server.Port)
/// test code here ...
return err
}
pact.
AddInteraction().
Given("The score_server has data to send us").
UponReceiving("a GET request").
WithRequest(dsl.Request{
Method: "GET",
Path: "/scores",
Query: "threshold=0.9",
Headers: map[string]string{"If-Modified-Since": imsString,
"x-api-key": "<api key>"},
}).
WillRespondWith(dsl.Response{
Status: 200,
Headers: map[string]string{"Content-Type": "text/plain",
"X-Api-Content-Length": contentLength,
"last-modified": time.Now().Format(time.RFC1123)},
Body: "R 5510B5E8-A504-36DB-B46A-9478A03F84D4 0.0",
})
// Verify
if err := pact.Verify(test); err != nil {
log.Fatalf("Error on Verify: %v", err)
}
}
When those tests pass and I look in pacts/loader-score_server.json
I only see:
{
"consumer": {
"name": "Loader"
},
"provider": {
"name": "score_server"
},
"interactions": [
{
"description": "a GET request",
"providerState": "The score_server has data to send us",
"request": {
"method": "GET",
"path": "/scores",
"query": "threshold=0.9",
"headers": {
"If-Modified-Since": "Mon, 19 Mar 2018 16:48:29 EDT",
"x-api-key": "<api key>"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "text/plain",
"X-Api-Content-Length": "100",
"last-modified": "Mon, 19 Mar 2018 17:48:30 EDT"
},
"body": "R 5510B5E8-A504-36DB-B46A-9478A03F84D4 0.0"
}
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
but that's only the last run test, not both of them.
After running the pact release for Windows (v0.0.3) and verifying that the daemon was listening on 6666, the consumer example could not connect to the daemon therefore failing the consumer tests.
pact-go/dsl/client.go
net.Dial and net.DialHttp issues with connecting to localhost. Specifying localhost solved the issue in the server name. This may possibly be linked to IPv6.
After modifying client.go
and the daemon logs the connection we have this issue:
2017/02/09 13:50:44 [DEBUG] daemon - starting mock server
2017/02/09 13:50:44 [DEBUG] starting mock service on port: 53215
2017/02/09 13:50:44 [DEBUG] starting service
2017/02/09 13:50:45 [INFO] service: ERROR: "pact-mock-service.rb service" was called with arguments ["--port 53215", "--pact-specification-version 2", "--pact-dir H:\\pact-workshop\\pact-go-consumer\\pacts", "--log H:\\pact-workshop\\pact-go-consumer\\logs/pact.log", "--consumer ui", "--provider ruleservice"]
2017/02/09 13:50:45 [INFO] service: Usage: "pact-mock-service.rb service"
It looks like the pact-mock-service.rb doesn't like Windows paths.
This is a thought bubble for a potential feature.
Thanks to #57, we now have granular access to all of the failures in a particular Provider verification.
Prior to this, all failures for a Provider were wrapped into a single test case, which is quite annoying if you have a large volume of tests and want to see in a report (often in a CI server) exactly where something failed.
Conversely, it is also nice to know how many tests were actually performed as a metric, something which is obscured in the current interface.
One suggestion could be to modify or overload the VerifyProvider
to accept a parameter of type testing.T
which records all interactions as https://blog.golang.org/subtests.
A typical Provider side test would like something like:
func TestProvider_PactContract(t *testing.T) {
// Create Pact, connecting to local Daemon
// Ensure the port matches the daemon port!
pact := Pact{
Port: 6666,
}
go startMyAPI("http://localhost:8000")
pact.VerifyProvider(t, types.VerifyRequest{
ProviderBaseURL: "http://localhost:8000",
PactURLs: []string{"./pacts/my_consumer-my_provider.json"},
ProviderStatesSetupURL: "http://localhost:8000/setup",
})
}
Behind the scenes, this will automatically fail the test if there is an error, and record all of the verifications as subtests, giving us something like the following:
--- FAIL: TestProvider_PactContract (0.00s)
--- PASS:TestProvider_PactContract_GetHello (0.00s)
--- FAIL: TestProvider_PactContract_GetHello (0.00s)
provider_test.go:84: expected 200 but got 404
"interactions": [ { "description": "A request to test pact'", "providerState": "pact", "request": { "method": "POST", "path": "/Course/pact", "body": { "id":1 } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "id": 1, "name": "第1节 自我介绍", "chapter_no": 1, "source_path": "http://class100-ppt.oss-cn-shanghai.aliyuncs.com/0000000001/0000000001.20151018.3b3e9730-7541-11e5-9480-2f80e994f28c.json", "material_id": 1, "created_at": 1494397015, "material": { "id": 1, "name": "暑期全外教兴趣班(中级)", "press": "", "status": 1, "created_at": 1494397015 } } } } ],
which raise error when testing:
[TRACE] response from Ruby process pre-sanitisation: /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/json-1.8.6/lib/json/pure/parser.rb:242:in
rescue in parse_string': Caught Encoding::CompatibilityError at '{ (JSON::ParserError)
"consumer": {
': incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string)
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/json-1.8.6/lib/json/pure/parser.rb:213:in parse_string' from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/json-1.8.6/lib/json/pure/parser.rb:257:in
parse_value'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/json-1.8.6/lib/json/pure/parser.rb:121:in parse' from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/json-1.8.6/lib/json/common.rb:155:in
parse'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/json-1.8.6/lib/json/common.rb:334:in load' from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-support-1.1.2/lib/pact/consumer_contract/consumer_contract.rb:42:in
from_json'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/provider/rspec.rb:25:in honour_pactfile' api_test.go:30: Error: provider verification failed: /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/json-1.8.6/lib/json/pure/parser.rb:242:in
rescue in parse_string': Caught Encoding::CompatibilityError at '{ (JSON::ParserError)
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/provider/pact_spec_runner.rb:129:in block in initialize_specs' "consumer": { from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/provider/pact_spec_runner.rb:125:in
each'
': incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string)
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/provider/pact_spec_runner.rb:125:in initialize_specs' from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/json-1.8.6/lib/json/pure/parser.rb:213:in
parse_string'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/provider/pact_spec_runner.rb:34:in run' from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/cli/run_pact_verification.rb:60:in
run_with_pact_uri'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/json-1.8.6/lib/json/pure/parser.rb:257:in parse_value' from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/cli/run_pact_verification.rb:48:in
run_specs'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/cli/run_pact_verification.rb:22:in call' from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/json-1.8.6/lib/json/pure/parser.rb:121:in
parse'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/cli/run_pact_verification.rb:14:in call' from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/json-1.8.6/lib/json/common.rb:155:in
parse'
from /home/darou/software/pact-go/pact-provider-verifier/lib/app/lib/pact/provider_verifier/app.rb:66:in block in verify_pacts' from /home/darou/software/pact-go/pact-provider-verifier/lib/app/lib/pact/provider_verifier/app.rb:57:in
collect'
from /home/darou/software/pact-go/pact-provider-verifier/lib/app/lib/pact/provider_verifier/app.rb:57:in verify_pacts' from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/json-1.8.6/lib/json/common.rb:334:in
load'
from /home/darou/software/pact-go/pact-provider-verifier/lib/app/lib/pact/provider_verifier/cli.rb:21:in verify' from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/thor-0.19.4/lib/thor/command.rb:27:in
run'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in invoke_command' from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-support-1.1.2/lib/pact/consumer_contract/consumer_contract.rb:42:in
from_json'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/thor-0.19.4/lib/thor.rb:369:in dispatch' from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/provider/rspec.rb:25:in
honour_pactfile'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/thor-0.19.4/lib/thor/base.rb:444:in start' from /home/darou/software/pact-go/pact-provider-verifier/lib/app/pact-provider-verifier.rb:3:in
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/provider/pact_spec_runner.rb:125:in `each'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/provider/pact_spec_runner.rb:125:in `initialize_specs'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/provider/pact_spec_runner.rb:34:in `run'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/cli/run_pact_verification.rb:60:in `run_with_pact_uri'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/cli/run_pact_verification.rb:48:in `run_specs'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/cli/run_pact_verification.rb:22:in `call'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/pact-1.14.0/lib/pact/cli/run_pact_verification.rb:14:in `call'
from /home/darou/software/pact-go/pact-provider-verifier/lib/app/lib/pact/provider_verifier/app.rb:66:in `block in verify_pacts'
from /home/darou/software/pact-go/pact-provider-verifier/lib/app/lib/pact/provider_verifier/app.rb:57:in `collect'
from /home/darou/software/pact-go/pact-provider-verifier/lib/app/lib/pact/provider_verifier/app.rb:57:in `verify_pacts'
from /home/darou/software/pact-go/pact-provider-verifier/lib/app/lib/pact/provider_verifier/cli.rb:21:in `verify'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch'
from /home/darou/software/pact-go/pact-provider-verifier/lib/vendor/ruby/2.2.0/gems/thor-0.19.4/lib/thor/base.rb:444:in `start'
from /home/darou/software/pact-go/pact-provider-verifier/lib/app/pact-provider-verifier.rb:3:in `<main>'
Reading pact at /home/darou/workspace/class100/service-intellect-course/src/xclass/intellectclass/app/courseserv/api/../pact/course_pact.json`
I ended up bypassing the daemon and shelling out to the ruby pact-provider-verifier
directly because none of the verifier's output was being returned to me in my tests.
func verifyProvider(t *testing.T, baseURL, setupURL string, pactURLS []string) {
args := append(pactURLS,
"--provider-base-url", baseURL,
"--provider-states-setup-url", setupURL,
)
cmd := exec.Command("pact-provider-verifier", args...)
out, err := cmd.CombinedOutput()
if err != nil {
t.Errorf("Provider verification failed: %s:\n\n%s\n", err, out)
}
}
Running the verification as described in the README, I get something similar to this:
--- FAIL: TestPactProvider (0.10s)
pact_test.go:34: Error: provider verification failed:
exit status 1
It looks like sometimes we get test failures when connecting to the Pact Daemon/Mock service it provides. This is inconsistent when running the tests. It can fail a bunch of times and then pass.
This can cause CI to fail.
See below for sample output.
I've replaced the username with .
=== RUN TestRule_Exists
2017/02/09 15:48:10 Error on Verify: Post http://localhost:61841/interactions: dial tcp [::1]:61841: getsockopt: connection refused
exit status 1
FAIL consumer 1.074s
<USER>-rMBP:consumer <USER>$ go test -v
=== RUN TestRule_Exists
--- PASS: TestRule_Exists (0.44s)
=== RUN TestRule_DoesNotExists
--- PASS: TestRule_DoesNotExists (0.01s)
PASS
ok consumer 0.983s
After running the daemon, I opened http://localhost:6666 in local web-browsers as a quick check to see if the daemon was running and curious to see the default http response if any. But none of major web-browsers (Chrome, Firefox, Safari) were able to open http://localhost:6666. This misled me into thinking that the daemon was probably not running and I ended up spending time changing the ports in the daemon and the example src to verify the tests running.
Just found that 6666 is one of restricted ports and hence blocked. And the error messages from the browsers are not very helpful in diagnosing this issue (esp. Chrome). Think it might be better to switch to a unrestricted port to prevent confusion like this among beginners.
$ pact-go version
Pact Go CLI v0.0.11
1.9.2
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mohanrajr/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/d0/742yxrrx0glg93s4z_rwyzkxm0whbv/T/go-build176059632=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
http://localhost:6666 opens successfully in a web-browser
Error messages when opening http://localhost:6666
Chrome :
This site can’t be reached
The webpage at http://localhost:6666/ might be temporarily down or it may have moved permanently to a new web address.
ERR_UNSAFE_PORT
Firefox:
This address is restricted
This address uses a network port which is normally used for purposes other than Web browsing. Firefox has canceled the request for your protection.
./pact-go daemon -l DEBUG -v
Nothing relevant in the log files
Add support for asynchronous communication, including but not limited to the following types of integrations:
TODO:
[release/1.x.x](https://github.com/pact-foundation/pact-go/tree/release/1.x.x)
branchTODO
s in the codeWhen tests are run against https
URL, following error is returned
Error on Verify: Get https://localhost:63128/api/v2.6/grid: http: server gave HTTP response to HTTPS client
I have a server object under test which accepts hostname and based on the hostname passed in sets the base URL for the subsequent requests as https://<hostname>/api
. But testing this with pact gives the error http: server gave HTTP response to HTTPS client
. Is it possible to have a pact interaction work with https
scheme instead of http
?
$ pact-go version
Pact Go CLI v0.0.11
1.9.2
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mohanrajr/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/d0/742yxrrx0glg93s4z_rwyzkxm0whbv/T/go-build176059632=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
Pact tests are runnable against https
URL
Tests fail with following error message when running against https
url
Error on Verify: Get https://localhost:63128/api/v2.6/grid: http: server gave HTTP response to HTTPS client
https
url instead of http
// Pass in test case
var test = func() error {
u := fmt.Sprintf("https://localhost:%d", pact.Server.Port)
req, err := http.NewRequest(http.MethodGet, u, nil)
req.Header.Set("Content-Type", "application/json")
if err != nil {
return err
}
if _, err = http.DefaultClient.Do(req); err != nil {
return err
}
return err
}
No relevant logs in pact.log
go version go1.9 darwin/amd64
Test succeeds to run
provider antweiss$ go test -v
=== RUN TestPact_Provider
2017/10/03 16:19:42 [DEBUG] pact setup logging
2017/10/03 16:19:42 [DEBUG] pact setup
2017/10/03 16:19:42 API starting: port 61911 ([::]:61911)
2017/10/03 16:19:42 [DEBUG] pact provider verification
2017/10/03 16:19:42 [DEBUG] client: verifying a provider
2017/10/03 16:19:42 [DEBUG] waiting for port 61911 to become available
2017/10/03 16:19:42 [DEBUG] creating an HTTP client
2017/10/03 16:19:42 [DEBUG] waiting for port 6666 to become available
2017/10/03 16:19:42 [TRACE] response from Ruby process pre-sanitisation:
2017/10/03 16:19:42
--- FAIL: TestPact_Provider (0.12s)
user_service_test.go:34: Error: provider verification failed:
FAIL
exit status 1
FAIL github.com/pact-foundation/pact-go/examples/mux/provider 0.137s
Follow the instructions in README
Hi,
I downloaded the linux-amd64.tar.gz for my Ubuntu 64 bit and updated the PATH variable to contain the paths of the extracted content as follows:
PATH=$PATH:/etc/pact-mock-service/bin:/etc/pact-provider-verifier/bin
Even after doing this, when I run "pact-go", it says
pact-go: command not found
Using the custom header feature from pact-standalone
, allow users to add custom headers during verification - e.g. OAuth tokens.
This is a common question on forums - how to submit headers that aren't/can't be part of the contract.
I have go1.6 installed on mac, I followed the README step by step. When running "go run consumer.go" , it throws an error immediately:
Error on Verify: Post http://localhost:0/interactions: dial tcp [::1]:0: connect: can't assign requested address exit status 1
On the pact-go console also throws error as well:
[ERROR] service fork/exec /Users/ypwu1/dev/github/pact-go/pact-mock-service/bin/pact-mock-service: no such file or directory
here is my go env:
GOARCH="amd64"
GOBIN="/Users/ypwu1/.gopm/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/ypwu1/.gopm"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.6.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.6.2/libexec/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/bintliff/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/t2/pn8d2qc91_b8l60s1jq5lf0w0000gn/T/go-build850475455=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
Allow more than one item of the array when EachLike(x, 1)
is passed. The array provider returns contains two items.
Fails on verification with Pact::UnexpectedIndex
error
https://github.com/zbintliff/pact-ruby-standalone-e2e-example/tree/issue/unexpected-index
Recreatable above
I guess because Golang numeric types and Ruby numeric types have different ranges.
{ "json_class": "Pact::SomethingLike", "contents": XXXXX }
When "contents" is a large int, it becomes interpreted by Ruby as a Float instead of a Fixnum. Therefore the provider validation will fail because it will have a decimal place added to it (1466191703.0 instead of 1466191703)
See https://app.wercker.com/#Pact-Foundation/pact-go/Package/5788c83ee7431d0100773946?step=5788c857f64f1300014f31ff for more. This is currently preventing new releases!
Resolving dependencies...
Installing rake 10.0.4
Installing concurrent-ruby 1.0.2
Installing i18n 0.7.0
Installing minitest 5.9.0
Installing thread_safe 0.3.5
Installing addressable 2.4.0
Using awesome_print 1.7.0
Installing coderay 1.1.1
Installing safe_yaml 1.0.4
Using diff-lcs 1.2.5
Installing fakefs 0.9.0
Using multipart-post 2.0.0
Using find_a_port 1.0.1
Installing hashie 2.1.2
Installing json 2.0.1 with native extensions
Installing method_source 0.8.2
Installing rack 2.0.1
Gem::InstallError: rack requires Ruby version >= 2.2.2.
Using randexp 0.1.7
Installing rspec-support 3.5.0
Using tins 1.11.0
Using thor 0.19.1
Using webrick 1.3.1
Installing slop 3.6.0
Using bundler 1.12.5
Installing tzinfo 1.2.2
Installing crack 0.4.3
Using faraday 0.9.2
An error occurred while installing rack (2.0.1), and Bundler cannot continue.
Make sure that `gem install rack -v '2.0.1'` succeeds before bundling.
Makefile:6: recipe for target 'package' failed
make: *** [package] Error 5
To ensure a consistent experience across both Windows and *nix variants, we should have a Windows build for Pact Go.
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/haavardw/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build718662238=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
Working consumer and mux provider examples
Output from downloading and running go-pact daemon
:
$ mkdir new-bin && cd new-bin \
&& curl -OL https://github.com/pact-foundation/pact-go/releases/download/v0.0.9/pact-go_linux_amd64 \
&& chmod 755 pact-go_linux_amd64 && mv pact-go_linux_amd64 pact-go \
&& ./pact-go daemon -v -l DEBUG
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 609 0 609 0 0 979 0 --:--:-- --:--:-- --:--:-- 980
100 8904k 100 8904k 0 0 1895k 0 0:00:04 0:00:04 --:--:-- 2297k
2017/08/09 22:38:36 [DEBUG] setting up a service manager
2017/08/09 22:38:36 [DEBUG] setting up a service manager
2017/08/09 22:38:36 [DEBUG] setting up a service manager
2017/08/09 22:38:36 [DEBUG] setting up a service manager
2017/08/09 22:38:36 [INFO] daemon - starting daemon on network: tcp address: port: 6666
2017/08/09 22:38:36 method Shutdown has wrong number of ins: 1
2017/08/09 22:38:36 method StartDaemon has wrong number of ins: 4
2017/08/09 22:38:36 [DEBUG] starting service creation monitor
2017/08/09 22:38:36 [DEBUG] starting service creation monitor
2017/08/09 22:38:36 [DEBUG] starting service removal monitor
2017/08/09 22:38:36 [DEBUG] starting service creation monitor
2017/08/09 22:38:36 [DEBUG] starting service removal monitor
2017/08/09 22:38:36 [DEBUG] starting service creation monitor
2017/08/09 22:38:36 [DEBUG] starting service removal monitor
2017/08/09 22:38:36 [DEBUG] starting service removal monitor
2017/08/09 22:38:47 [DEBUG] daemon - starting mock server with args: [--pact-specification-version 2 --pact-dir /home/haavardw/go/src/github.com/pact-foundation/pact-go/examples/pacts --log /home/haavardw/go/src/github.com/pact-foundation/pact-go/examples/logs/pact.log --consumer MyConsumer --provider MyProvider]
2017/08/09 22:38:47 [DEBUG] starting mock service on port: 37349
2017/08/09 22:38:47 [DEBUG] starting service
2017/08/09 22:38:47 [ERROR] service fork/exec /home/haavardw/new-bin/pact-mock-service/bin/pact-mock-service: no such file or directory
Output from the consumer example:
$ cd ${GOPATH}/src/github.com/pact-foundation/pact-go/examples && go run -v consumer.go
github.com/pact-foundation/pact-go/dsl
command-line-arguments
2017/08/09 22:09:54 [DEBUG] pact setup logging
2017/08/09 22:09:54 [DEBUG] pact setup
2017/08/09 22:09:54 [DEBUG] client: starting a server
2017/08/09 22:09:54 [DEBUG] creating an HTTP client
2017/08/09 22:09:54 [DEBUG] waiting for port 6666 to become available
2017/08/09 22:09:54 [ERROR] rpc: unexpected EOF
2017/08/09 22:09:54 [DEBUG] pact add interaction
2017/08/09 22:09:54 [DEBUG] pact setup logging
2017/08/09 22:09:54 [DEBUG] pact setup
2017/08/09 22:09:54 [DEBUG] pact add interaction
2017/08/09 22:09:54 [DEBUG] pact setup logging
2017/08/09 22:09:54 [DEBUG] pact setup
2017/08/09 22:09:54 [DEBUG] pact verify
2017/08/09 22:09:54 [DEBUG] mock service add interaction
2017/08/09 22:09:54 Error on Verify: Post http://localhost:0/interactions: dial tcp 127.0.0.1:0: getsockopt: connection refused
exit status 1
Same issue downloading v0.0.8 and v0.0.9 and the plan pact-go
binary (non-_linux_amd64
)
Mux example:
$ go test -v
=== RUN TestPact_Provider
2017/08/09 22:44:38 API starting: port 44041 ([::]:44041)
2017/08/09 22:44:38 [TRACE] response from Ruby process pre-sanitisation:
2017/08/09 22:44:38
--- FAIL: TestPact_Provider (0.10s)
user_service_test.go:33: Error: provider verification failed:
FAIL
exit status 1
FAIL github.com/pact-foundation/pact-go/examples/mux/provider 0.116s
./pact-go daemon -v -l DEBUG
2017/08/09 22:44:22 [DEBUG] setting up a service manager
2017/08/09 22:44:22 [DEBUG] setting up a service manager
2017/08/09 22:44:22 [DEBUG] setting up a service manager
2017/08/09 22:44:22 [DEBUG] setting up a service manager
2017/08/09 22:44:22 [INFO] daemon - starting daemon on network: tcp address: port: 6666
2017/08/09 22:44:22 method Shutdown has wrong number of ins: 1
2017/08/09 22:44:22 method StartDaemon has wrong number of ins: 4
2017/08/09 22:44:22 [DEBUG] starting service removal monitor
2017/08/09 22:44:22 [DEBUG] starting service creation monitor
2017/08/09 22:44:22 [DEBUG] starting service removal monitor
2017/08/09 22:44:22 [DEBUG] starting service creation monitor
2017/08/09 22:44:22 [DEBUG] starting service creation monitor
2017/08/09 22:44:22 [DEBUG] starting service creation monitor
2017/08/09 22:44:22 [DEBUG] starting service removal monitor
2017/08/09 22:44:22 [DEBUG] starting service removal monitor
2017/08/09 22:44:38 [DEBUG] daemon - verifying provider
2017/08/09 22:44:38 [DEBUG] starting verification service with args: [--provider-base-url http://localhost:44041 --pact-urls /home/haavardw/go/src/github.com/pact-foundation/pact-go/examples/mux/provider/../../pacts/billy-bobby.json --provider-states-setup-url http://localhost:44041/setup]
2017/08/09 22:44:38 [DEBUG] starting service
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/username/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/username/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/80/8lv857_55gv0xtvl97bwvn4c0000gp/T/go-build315953557=/tmp/go-build -gno-record-gcc-switches -fno-common"
When calling pact.VerifyProvider
and passing in a types.VerifyRequest
with BrokerURL
specified, I expect that if the broker contains pacts from more than one consumer for this provider, each pact will be verified.
When running the test, I see the following output:
pact.go:264: Error: error verifying provider: exit status 1
STDERR:
Error reading file from https://<broker-url>/pacts/provider/provider-name/consumer/consumer1-name/version/1.12.0 https://<broker-url>/pacts/provider/provider-name/consumer/consumer2-name/version/1.19.0
bad URI(is not URI?): https://<broker-url>/pacts/provider/provider-name/consumer/consumer1-name/version/1.12.0 https://<broker-url>/pacts/provider/provider-name/consumer/consumer2-name/version/1.19.0 /Users/username/go/src/github.com/org/repo/pact/lib/ruby/lib/ruby/2.2.0/uri/rfc3986_parser.rb:66:in `split'
/Users/username/go/src/github.com/org/repo/pact/lib/ruby/lib/ruby/2.2.0/uri/rfc3986_parser.rb:72:in `parse'
/Users/username/go/src/github.com/org/repo/pact/lib/ruby/lib/ruby/2.2.0/uri/common.rb:226:in `parse'
/Users/username/go/src/github.com/org/repo/pact/lib/ruby/lib/ruby/2.2.0/uri/common.rb:713:in `URI'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-support-1.2.4/lib/pact/consumer_contract/pact_file.rb:39:in `render_pact'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-support-1.2.4/lib/pact/consumer_contract/pact_file.rb:22:in `read'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/provider/pact_source.rb:14:in `pact_json'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/provider/pact_spec_runner.rb:129:in `collect'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/provider/pact_spec_runner.rb:129:in `pact_jsons'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/provider/pact_spec_runner.rb:92:in `configure_rspec'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/provider/pact_spec_runner.rb:33:in `run'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/cli/run_pact_verification.rb:61:in `run_with_pact_uri'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/cli/run_pact_verification.rb:49:in `run_specs'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/cli/run_pact_verification.rb:22:in `call'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/cli/run_pact_verification.rb:14:in `call'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.11.0/lib/pact/provider_verifier/app.rb:107:in `verify_pact'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.11.0/lib/pact/provider_verifier/app.rb:28:in `block in call'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.11.0/lib/pact/provider_verifier/app.rb:27:in `collect'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.11.0/lib/pact/provider_verifier/app.rb:27:in `call'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.11.0/lib/pact/provider_verifier/app.rb:21:in `call'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.11.0/lib/pact/provider_verifier/cli/verify.rb:26:in `verify'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/thor-0.20.0/lib/thor/base.rb:466:in `start'
/Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.11.0/lib/pact/provider_verifier/cli/custom_thor.rb:17:in `start'
/Users/username/go/src/github.com/org/repo/pact/lib/app/pact-provider-verifier.rb:2:in `<main>'
/Users/username/go/src/github.com/org/repo/pact/lib/ruby/lib/ruby/2.2.0/uri/rfc3986_parser.rb:66:in `split': bad URI(is not URI?): https://<broker-url>/pacts/provider/provider-name/consumer/consumer1-name/version/1.12.0 https://<broker-url>/pacts/provider/provider-name/consumer/consumer2-name/version/1.19.0 (URI::InvalidURIError)
from /Users/username/go/src/github.com/org/repo/pact/lib/ruby/lib/ruby/2.2.0/uri/rfc3986_parser.rb:72:in `parse'
from /Users/username/go/src/github.com/org/repo/pact/lib/ruby/lib/ruby/2.2.0/uri/common.rb:226:in `parse'
from /Users/username/go/src/github.com/org/repo/pact/lib/ruby/lib/ruby/2.2.0/uri/common.rb:713:in `URI'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-support-1.2.4/lib/pact/consumer_contract/pact_file.rb:39:in `render_pact'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-support-1.2.4/lib/pact/consumer_contract/pact_file.rb:22:in `read'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/provider/pact_source.rb:14:in `pact_json'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/provider/pact_spec_runner.rb:129:in `collect'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/provider/pact_spec_runner.rb:129:in `pact_jsons'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/provider/pact_spec_runner.rb:92:in `configure_rspec'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/provider/pact_spec_runner.rb:33:in `run'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/cli/run_pact_verification.rb:61:in `run_with_pact_uri'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/cli/run_pact_verification.rb:49:in `run_specs'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/cli/run_pact_verification.rb:22:in `call'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-1.20.0/lib/pact/cli/run_pact_verification.rb:14:in `call'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.11.0/lib/pact/provider_verifier/app.rb:107:in `verify_pact'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.11.0/lib/pact/provider_verifier/app.rb:28:in `block in call'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.11.0/lib/pact/provider_verifier/app.rb:27:in `collect'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.11.0/lib/pact/provider_verifier/app.rb:27:in `call'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.11.0/lib/pact/provider_verifier/app.rb:21:in `call'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.11.0/lib/pact/provider_verifier/cli/verify.rb:26:in `verify'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/thor-0.20.0/lib/thor/base.rb:466:in `start'
from /Users/username/go/src/github.com/org/repo/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.11.0/lib/pact/provider_verifier/cli/custom_thor.rb:17:in `start'
from /Users/username/go/src/github.com/org/repo/pact/lib/app/pact-provider-verifier.rb:2:in `<main>'
pact := &dsl.Pact{
Port: 6666,
Provider: "provider-name",
}
mockPort := ":6667"
providerStatesSetupPath := "/setup"
go startServer(t, mockPort)
pact.VerifyProvider(t, types.VerifyRequest{
ProviderBaseURL: "http://localhost" + mockPort,
ProviderStatesSetupURL: "http://localhost" + mockPort + providerStatesSetupPath,
BrokerURL: os.Getenv("PACT_BROKER_BASE_URL"),
BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"),
BrokerPassword: os.Getenv("PACT_BROKER_PSWD"),
PublishVerificationResults: publishResults,
ProviderVersion: providerVersion,
})
$ pact-go version
Pact Go CLI v0.0.11
1.9.2
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mohanrajr/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/d0/742yxrrx0glg93s4z_rwyzkxm0whbv/T/go-build176059632=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
pact.Server.Port
should return the port once dsl.Pact{}
is created
Panics instead
2018/01/23 12:11:04 [DEBUG] teardown
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x13fe54c]
goroutine 4 [running]:
testing.tRunner.func1(0xc4201880f0)
/usr/local/Cellar/go/1.9.2/libexec/src/testing/testing.go:711 +0x2d2
panic(0x14756e0, 0x177e580)
/usr/local/Cellar/go/1.9.2/libexec/src/runtime/panic.go:491 +0x283
// Create Pact connecting to local Daemon
pact := &dsl.Pact{
Host: pactDaemonHost,
Port: pactDaemonPort,
Consumer: "Consumer",
Provider: "Provider",
}
defer pact.Teardown()
// accessing pact server port results in a panic before setting up an interaction
// sleeping doesn't help either
//time.Sleep(10 * time.Second)
fmt.Println("Pact port before:", pact.Server.Port)
// Set up expected interactions
pact.
AddInteraction()
// accessing pact server port works as expected after setting up the interaction
fmt.Println("Pact port after:", pact.Server.Port)
NA
See the below example, most of the output is noise:
2) Verifying a pact between API and Metrics A request to create a metric with POST /metrics returns a response which has a matching body
Failure/Error: expect(response_body).to match_term expected_response_body, diff_options
Actual: 404 page not found
@@ -1,7 +1,2 @@
-{
- "sent": {
- "json_class": "Pact::SomethingLike",
- "contents": true
- }
-}
+404 page not found
Key: - means "expected, but was not found".
+ means "actual, should not be found".
Values where the expected matches the actual are not shown.
# ./bin/pact-provider-verifier/lib/vendor/ruby/2.1.0/gems/rspec-expectations-2.99.2/lib/rspec/expectations/fail_with.rb:32:in `fail_with'
# ./bin/pact-provider-verifier/lib/vendor/ruby/2.1.0/gems/rspec-expectations-2.99.2/lib/rspec/expectations/handler.rb:40:in `handle_matcher'
# ./bin/pact-provider-verifier/lib/vendor/ruby/2.1.0/gems/rspec-expectations-2.99.2/lib/rspec/expectations/expectation_target.rb:59:in `to'
# ./bin/pact-provider-verifier/lib/vendor/ruby/2.1.0/gems/pact-1.9.1/lib/pact/provider/rspec.rb:138:in `block (2 levels) in describe_response'
# ./bin/pact-provider-verifier/lib/vendor/ruby/2.1.0/gems/rspec-core-2.99.2/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_exec'
# ./bin/pact-provider-verifier/lib/vendor/ruby/2.1.0/gems/rspec-core-2.99.2/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_eval_with_args'
# ./bin/pact-provider-verifier/lib/vendor/ruby/2.1.0/gems/rspec-core-2.99.2/lib/rspec/core/example.rb:116:in `block in run'
One suggestion would be to automatically detect this cruft (anything starting with # ./bin
) and discard the output, possibly configured as a flag or via DEBUG
logging.
This should greatly increase readability and user experience.
Wercker is unreliable and artifacts don't cache between steps, making it unsuitable for our needs.
This probably belongs in a child repo, I'm just not sure which one, so raising here!
I've removed the ruby specific output from the pact verify command (yay!)
What I would like to add is words to the effect of "to run just one interaction, please rerun the pact verify command with PACT_DESCRIPTION="..." and PACT_PROVIDER_STATE="..." environment variables set.
Can you please update to the ruby standalone version 1.4.0 and verify that the above environment variables are passed through? You should see the text Filtering interactions by...
Minor
Submitting a PR to file two errors both of:
missing ',' before newline in composite literal
Could be fixed by either adding a ,
like I am doing or getting rid of the new line.
If the endpoint referenced by /setup
or /states
is invalid, as expected by the verifier, Pact should fail fast with a clear warning:
if err := pact.VerifyProvider(types.VerifyRequest{
ProviderBaseURL: fmt.Sprintf("http://localhost:%d", port),
PactURLs: pactFiles,
ProviderStatesURL: fmt.Sprintf("http://localhost:%d/states", port),
ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", port),
}); err != nil {
t.Errorf("verification failed: %v", err)
}
At the moment, an obscure error message from the verifier is recorded:
```/Users/mfellows/Downloads/darwin-amd64/pact-provider-verifier/lib/app/lib/pact/provider_verifier/pact_helper.rb:33:in<top (required)>': undefined method
keys' for nil:NilClass (NoMethodError)
from /Users/mfellows/Downloads/darwin-amd64/pact-provider-verifier/lib/vendor/ruby/2.1.0/gems/pact-1.9.1/lib/pact/cli/run_pact_verification.rb:43:in`load'
from /Users/mfellows/Downloads/darwin-amd64/pact-provider-verifier/lib/vendor/ruby/2.1.0/gems/pact-1.9.1/lib/pact/cli/run_pact_verification.rb:43:in `load_pact_helper'
from /Users/mfellows/Downloads/darwin-amd64/pact-provider-verifier/lib/vendor/ruby/2.1.0/gems/pact-1.9.1/lib/pact/cli/run_pact_verification.rb:21:in`call'
from /Users/mfellows/Downloads/darwin-amd64/pact-provider-verifier/lib/vendor/ruby/2.1.0/gems/pact-1.9.1/lib/pact/cli/run_pact_verification.rb:14:in `call'
from /Users/mfellows/Downloads/darwin-amd64/pact-provider-verifier/lib/app/lib/pact/provider_verifier/app.rb:65:in`block in verify_pacts'
from /Users/mfellows/Downloads/darwin-amd64/pact-provider-verifier/lib/app/lib/pact/provider_verifier/app.rb:54:in `collect'
from /Users/mfellows/Downloads/darwin-amd64/pact-provider-verifier/lib/app/lib/pact/provider_verifier/app.rb:54:in`verify_pacts'
from /Users/mfellows/Downloads/darwin-amd64/pact-provider-verifier/lib/app/lib/pact/provider_verifier/cli.rb:18:in `verify'
from /Users/mfellows/Downloads/darwin-amd64/pact-provider-verifier/lib/vendor/ruby/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:27:in`run'
from /Users/mfellows/Downloads/darwin-amd64/pact-provider-verifier/lib/vendor/ruby/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from /Users/mfellows/Downloads/darwin-amd64/pact-provider-verifier/lib/vendor/ruby/2.1.0/gems/thor-0.19.1/lib/thor.rb:359:in`dispatch'
from /Users/mfellows/Downloads/darwin-amd64/pact-provider-verifier/lib/vendor/ruby/2.1.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
from /Users/mfellows/Downloads/darwin-amd64/pact-provider-verifier/lib/app/pact-provider-verifier.rb:3:in`
Support the ability to publish verification status to the broker. See https://github.com/bethesque/pact_broker/blob/v2.0.0.beta.2/lib/pact_broker/doc/views/publish-verification.markdown
Using the stub server feature from pact-standalone
, allow users to create stub-servers from provided pact files.
This is often useful to run in the background with Makefile
s or as part of "integrated" / "black-box" style tests.
Getting error when trying to match logically accurate JSON probably due to formatting issues with and without the formatJSON function used in the examples. If it was explicit string matching then I would expect this behavior but not for flexible matching.
1) Verifying a pact between service-one and service-two Given User traffic exists for the current month A request for all traffic for the current month with GET /v1/traffic/usage/json returns a response which has a matching body
Failure/Error: expect(response_body).to match_term expected_response_body, diff_options
Actual: [{"org":"a6df0d8e-916b-4998-ac6e-149b299e2c9f","usage":12345}]
@@ -1,7 +1,2 @@
-[
- {
- "org": "a6df0d8e-916b-4998-ac6e-149b299e2c9f",
- "usage": 12345
- },
-]
+[{"org":"a6df0d8e-916b-4998-ac6e-149b299e2c9f","usage":12345}]
Key: - means "expected, but was not found".
+ means "actual, should not be found".
Values where the expected matches the actual are not shown.
# /usr/local/bin/pact-provider-verifier/lib/app/pact-provider-verifier.rb:3:in `<main>'
Finished in 0.0183 seconds
2 examples, 1 failure
This is the printed output of my expected with pact matching terminology in it:
{
"json_class": "Pact::ArrayLike",
"contents": {"org":
{
"json_class": "Pact::Term",
"data": {
"generate": "a6df0d8e-916b-4998-ac6e-149b299e2c9f",
"matcher": {
"json_class": "Regexp",
"o": 0,
"s": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
}
}
},"usage":
{
"json_class": "Pact::SomethingLike",
"contents": 12345
}},
"min": 1
}
The Mock Server is always started even if no consumer tests are being run.
From looking at the code it seems that any error the passed in function returns is ignored.
https://github.com/pact-foundation/pact-go/blob/master/dsl/pact.go#L182
Seems to match what I'm seeing in my tests as well; my client is erroring but my tests all pass.
if err := pact.Verify(c.testFunc); err != nil {
t.Fatalf(err.Error())
}
I am trying to test a complex interaction :
How can I do this with Pact?
$ pact-go version
Pact Go CLI v0.0.11
go1.10 darwin/amd64
go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mohanrajr/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mohanrajr/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/d0/742yxrrx0glg93s4z_rwyzkxm0whbv/T/go-build258382301=/tmp/go-build -gno-record-gcc-switches -fno-common"
Getting a 500 Server error saying interaction not found - even though the interaction is defined.
After many many hours of debugging found the issue was due to missing header "Content-Type": "application/json"
in the request sent to the mock server. I think this was mentioned in the docs or sample code - but the lack of a clear error message pointing to the missing header is confounding.
What needs to be done:
$ pact-go version
Pact Go CLI v0.0.11
1.9.2
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mohanrajr/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/d0/742yxrrx0glg93s4z_rwyzkxm0whbv/T/go-build176059632=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
When required header ("Content-Type", "application/json"
) is not present in request sent to the mock server, the error message points to the missing header.
Test fails with a confounding error message instead
Request to authenticate unsuccessful. Status: 500 Internal Server Error Body: {"message":"No interaction found for GET /api/v2.6/grid","interaction_diffs":[]}
This had me focus on the "No interaction found for GET /api/v2.6/grid" part of the error message and left me scratching my head as I had an interaction defined for "GET /api/v2.6/grid"
Also noticed later that the application/json
header can be skipped when setting up a interaction - which might be further confusing when debugging the error.
"Content-Type", "application/json"
when sending the request to the mock serverpact.log
I, [2018-01-22T14:38:33.110140 #50606] INFO -- : Registered expected interaction GET /api/v2.6/grid
D, [2018-01-22T14:38:33.110399 #50606] DEBUG -- : {
"description": "A request to authenticate",
"request": {
"method": "GET",
"path": "/api/v2.6/grid",
"headers": {
"Authorization": "Basic ZHJmX3Rlc3Q6W3M7NzxfQ1MlWTJ5SF0=",
"Content-Type": "application/json"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
}
}
}
I, [2018-01-22T14:38:33.113042 #50606] INFO -- : Received request GET /api/v2.6/grid
D, [2018-01-22T14:38:33.113131 #50606] DEBUG -- : {
"path": "/api/v2.6/grid",
"query": "",
"method": "get",
"headers": {
"Content-Type": "application/json",
"Host": "localhost:62140",
"User-Agent": "Go-http-client/1.1",
"Authorization": "Basic xxx=",
"Accept-Encoding": "gzip",
"Version": "HTTP/1.1"
}
}
I, [2018-01-22T14:38:33.113294 #50606] INFO -- : Found matching response for GET /api/v2.6/grid
D, [2018-01-22T14:38:33.113408 #50606] DEBUG -- : {
"status": 200,
"headers": {
"Content-Type": "application/json"
}
}
I, [2018-01-22T14:38:33.115668 #50606] INFO -- : Verifying - interactions matched
I, [2018-01-22T14:38:33.118071 #50606] INFO -- : Cleared interactions
I, [2018-01-22T14:38:33.123374 #50627] INFO -- : Received request GET /api/v2.6/grid
D, [2018-01-22T14:38:33.123495 #50627] DEBUG -- : {
"path": "/api/v2.6/grid",
"query": "",
"method": "get",
"headers": {
"Host": "localhost:62143",
"User-Agent": "Go-http-client/1.1",
"Authorization": "Basic xxx=",
"Accept-Encoding": "gzip",
"Version": "HTTP/1.1"
}
}
E, [2018-01-22T14:38:33.123545 #50627] ERROR -- : No matching interaction found for GET /api/v2.6/grid
E, [2018-01-22T14:38:33.123567 #50627] ERROR -- : Interaction diffs for that route:
E, [2018-01-22T14:38:33.123603 #50627] ERROR -- :
Hey there,
I've recently started getting the following error when my pact tests. I can confirm this has been recently introduced, replacing my older version of the package (about 3 weeks old) with the most recent introduces the problem.
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x139994f]
goroutine 35 [running]:
testing.tRunner.func1(0xc4201f4680)
/usr/local/go/src/testing/testing.go:622 +0x29d
panic(0x1408ea0, 0x169f6f0)
/usr/local/go/src/runtime/panic.go:489 +0x2cf
github.com/pact-foundation/pact-go/dsl.(*PactClient).VerifyProvider(0x0, 0xc42000c14b, 0x15, 0xc4201a5030, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, ...)
<hidden>/go/src/github.com/pact-foundation/pact-go/dsl/client.go:118 +0xef
github.com/pact-foundation/pact-go/dsl.(*Pact).VerifyProvider(0xc42024c000, 0xc42000c14b, 0x15, 0xc4201a5030, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, ...)
<hidden>/go/src/github.com/pact-foundation/pact-go/dsl/pact.go:219 +0xc2
<hidden>/deploy_test.TestPact(0xc4201f4680)
<hidden>/pact_verify_test.go:37 +0x442
testing.tRunner(0xc4201f4680, 0x149f800)
/usr/local/go/src/testing/testing.go:657 +0x96
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:697 +0x2ca
Is there existing or planned support for specifying cookies in interactions ?
Having some issues writing pact tests around a service which relies on cookie for auth - can you please help me.
$ pact-go version
Pact Go CLI v0.0.11
go1.10 darwin/amd64
go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mohanrajr/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mohanrajr/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/d0/742yxrrx0glg93s4z_rwyzkxm0whbv/T/go-build258382301=/tmp/go-build -gno-record-gcc-switches -fno-common"
VerifyProvider()
test to fail - since trying to /logout without a cookie or auth header results in a 401 instead of the expected 200 status
E, [2018-03-13T19:33:34.040449 #50904] ERROR -- : No matching interaction found for POST /logout
E, [2018-03-13T19:33:34.040486 #50904] ERROR -- : Interaction diffs for that route:
E, [2018-03-13T19:33:34.040957 #50904] ERROR -- : Diff with interaction: "A request to logout"
Diff
--------------------------------------
Key: - is expected
+ is actual
Matching keys and values are not shown
{
"headers": {
- "Authorization": "Basic XXX="
}
}
Description of differences
--------------------------------------
* Could not find key "Authorization" (keys present are: Content-Type, Host, User-Agent, Accept-Encoding, Version) at $.headers
I, [2018-03-13T19:33:34.044004 #50904] INFO -- : Writing pact for WAPIIntegration to
I tried this example. However, I've got an error when I try go test -v .
https://github.com/pact-foundation/pact-go/tree/master/examples/go-kit
At first, I've got this error. (before this, I go get for go-kit)
$ go test -v .
endpoints.go:8:2: cannot find package "golang.org/x/net/context" in any of:
/usr/local/Cellar/go/1.8/libexec/src/golang.org/x/net/context (from $GOROOT)
/Users/ushio/go/src/golang.org/x/net/context (from $GOPATH)
/Users/ushio/go/src/github.com/go-kit/kit/transport/http/client.go:12:2: cannot find package "golang.org/x/net/context/ctxhttp" in any of:
/usr/local/Cellar/go/1.8/libexec/src/golang.org/x/net/context/ctxhttp (from $GOROOT)
/Users/ushio/go/src/golang.org/x/net/context/ctxhttp (from $GOPATH)
Then I try go get -u golang.org/x/net/context
then I've got this.
How can I solve this problem?
# _/Users/ushio/Codes/pact/pact-go/examples/go-kit/provider
./endpoints.go:25: cannot use func literal (type func("golang.org/x/net/context".Context, interface {}) (interface {}, error)) as type endpoint.Endpoint in return argument
./transport.go:29: cannot use encodeError (type func("golang.org/x/net/context".Context, error, "net/http".ResponseWriter)) as type "github.com/go-kit/kit/transport/http".ErrorEncoder in argument to "github.com/go-kit/kit/transport/http".ServerErrorEncoder
./transport.go:39: too many arguments in call to "github.com/go-kit/kit/transport/http".NewServer
have ("golang.org/x/net/context".Context, endpoint.Endpoint, func("golang.org/x/net/context".Context, *"net/http".Request) (interface {}, error), func("golang.org/x/net/context".Context, "net/http".ResponseWriter, interface {}) error, []"github.com/go-kit/kit/transport/http".ServerOption...)
want (endpoint.Endpoint, "github.com/go-kit/kit/transport/http".DecodeRequestFunc, "github.com/go-kit/kit/transport/http".EncodeResponseFunc, ..."github.com/go-kit/kit/transport/http".ServerOption)
./transport.go:66: undefined: "github.com/go-kit/kit/transport/http".Error
./transport.go:74: undefined: "github.com/go-kit/kit/transport/http".DomainDecode
./transport.go:76: undefined: "github.com/go-kit/kit/transport/http".DomainDo
./user_service_test.go:90: undefined: "github.com/go-kit/kit/log".NewContext
./user_service_test.go:91: undefined: "github.com/go-kit/kit/log".NewContext
When testing an API with provider states, the Mock Service outputs in the middle of the BDD-style output, making it hard to read:
Verifying a pact between billy and bobby
Given Some state
Some name for the test
with GET /foobar
returns a response which
Setting up provider state 'Some state' for consumer 'billy' using provider state server at http://localhost:64349/setup
has status code 200
includes headers
"Content-Type" with value "application/json"
Given Some state2
Some name for the test
with GET /bazbat
returns a response which
Setting up provider state 'Some state2' for consumer 'billy' using provider state server at http://localhost:64349/setup
has status code 200
has a matching body
Finished in 0.65175 seconds
4 examples, 0 failures
Add ability to specify pact write mode to allow simpler splitting of tests across files.
See pact-foundation/pact-js#48 for example.
Running on Mac OS the Pact daemon with no arguments we get this output:
2017/02/09 15:33:14 [ERROR]
2017/02/09 15:33:14 [ERROR] Writing pact for <SERVICE> to /Users/<OMITTED>/go/src/<FILE>.json
I've replaced some sensitive info with , and .
The json file gets written properly so functionally it's fine. The [ERROR]
is probably just the wrong log level.
Hey quick question I can't grok from the docs. We have 4 clients each pulling from 4 providers. Lets call the providers A,B,C and D. I push all the pacts to my broker. When looking at VerifyRequest
I can't really figure out how to specify I want all the the latests pacts for tag foo
where the provider is B
.
It seems the verification process does not like local Windows paths, dying after matching Ruby's URI:Regex
and being treated as a remote file.
This has the implication that for now, pact verification must happen over a remote connection (e.g. via a Pact Broker).
Stack trace forthcoming, however it appears to be buried in part of the pact_support
gem.
I am trying to use the PublishPacts functions from my code. The README shows this example but I get errors when using this code and I am unable to find this code in the repo. I could be doing something noob (and most likely am :P ) so this issue is more of a request for guidance that an actual issue.
pact.PublishPacts(types.PublishRequest{
PactBroker: "http://pactbroker:8000",
PactURLs: []string{"./pacts/my_consumer-my_provider.json"},
ConsumerVersion: "1.0.0",
Tags: []string{"latest", "dev"},
})
The generated pact files using pact-go differs from the ones generated with pact for java. Pact Go outputs 'provider_state' and for the java pact it outputs 'providerState'. According to the v2 of the pact specification it should be 'providerState'. This is due to the implementation coping the Ruby one.
Need to change 'provider_state' to 'providerState' at https://github.com/pact-foundation/pact-go/blob/master/dsl/interaction.go#L20
Run the E2E tests TestPact_Integration
during Wercker builds.
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.