https://pact.io logo
Join Slack
Powered by
# pact-go
  • g

    Guillaume Camus

    06/29/2022, 1:29 PM
    Hi guys, I have errors when I perform tests on the content type. And I don’t understand why! I have this message:
    Copy code
    2.1) includes header 'Content-Type' with value 'application/json; charset=utf-8'
               Expected header 'Content-Type' to have value 'application/json; charset=utf-8' but was 'application/json; charset=utf-8'
    But for me the 2 strings are equal. How can I fix this?
    m
    • 2
    • 3
  • r

    Ringo

    06/30/2022, 10:35 AM
    I have this near the end of a test I’m trying to write:
    Copy code
    err = mockProvider.ExecuteTest(t, doTestCreateGithubRepo)
    With this as definition:
    Copy code
    var doTestCreateGithubRepo = func() func(config MockServerConfig) error {
    	return executeTestCreateGithubRepo("foo")
    }()
    
    var executeTestCreateGithubRepo = func(repo string) func(config MockServerConfig) error {
       ...
    }
    I would like to have access to
    t *testing.T
    within
    executeTestCreateGithubRepo
    for the test logging functions. How can I do that?
  • m

    Matt (pactflow.io / pact-js / pact-go)

    06/30/2022, 11:11 AM
    I don’t think you need the
    doTestCreateGithubRepo
    function at all. I think you can just do something like this:
    Copy code
    err = mockProvider.ExecuteTest(t, executeTestCreateGithubRepo("foo", t))
    and then
    Copy code
    var executeTestCreateGithubRepo = func(repo string, t *testing.T) func(config MockServerConfig) error {
       ...
    }
    👍 1
  • r

    Ringo

    06/30/2022, 1:20 PM
    How should I write that one property in a
    Map
    is another composite object (not array)?
    Copy code
    WithJSONBody(Map{
       "id":        Integer(1296269),
       "node_id":   S("MDEwOlJlcG9zaXRvcnkxMjk2MjY5"),
       "name":      S("foo"),
       "full_name": S("theorg/foo"),
       "owner": Map{
    	   "login": S("theorg"),
       },
    })
    The above gives me an error on the line where I specify another
    Map
    for
    owner
    .
    m
    • 2
    • 1
  • r

    Ringo

    06/30/2022, 1:27 PM
    Copy code
    cannot use (Map literal) (value of type matchers.MapMatcher) as matchers.Matcher value in map literal: matchers.MapMatcher does not implement matchers.Matcher (missing method GetValue)compilerInvalidIfaceAssign
  • r

    Ravindra Dhaka

    07/06/2022, 7:14 AM
    @Matt (pactflow.io / pact-js / pact-go) when i was runing in local machine its working fine but in gitlab ci/cd getting this error
    Copy code
    make consumer
    #/builds/panamera/fcg/service/dapi/pact/bin run  --no-config --deadline=10m --enable=misspell --enable=nakedret
    --- 🔨Running Consumer Pact tests 
    go test -count=1 ./consumer/client -run 'TestClientPact'
    go: finding <http://github.com/pact-foundation/pact-go|github.com/pact-foundation/pact-go> v1.7.1-0.20220627045253-94d333263e43
    go: finding <http://cloud.google.com/go|cloud.google.com/go> v0.46.3
    go: finding <http://github.com/hashicorp/logutils|github.com/hashicorp/logutils> v1.0.0
    go: finding <http://github.com/hashicorp/go-version|github.com/hashicorp/go-version> v1.5.0
    go: finding <http://google.golang.org/api|google.golang.org/api> v0.13.0
    go: finding <http://github.com/stretchr/testify|github.com/stretchr/testify> v1.7.4
    go: finding <http://github.com/gorilla/websocket|github.com/gorilla/websocket> v1.4.2
    go: finding <http://golang.org/x/net|golang.org/x/net> v0.0.0-20210226172049-e18ecbb05110
    go: finding <http://github.com/stretchr/objx|github.com/stretchr/objx> v0.4.0
    go: finding <http://golang.org/x/crypto|golang.org/x/crypto> v0.0.0-20210921155107-089bfa567519
    go: finding <http://golang.org/x/text|golang.org/x/text> v0.3.3
    go: finding <http://github.com/gin-gonic/gin|github.com/gin-gonic/gin> v1.7.7
    go: finding <http://gopkg.in/yaml.v3|gopkg.in/yaml.v3> v3.0.1
    go: finding <http://github.com/google/uuid|github.com/google/uuid> v1.3.0
    go: finding <http://github.com/klauspost/compress|github.com/klauspost/compress> v1.14.2
    2022/07/06 05:25:48 [ERROR] service: /builds/panamera/fcg/service/dapi/pact/lib/ruby/bin/ruby: line 6: /builds/panamera/fcg/service/dapi/pact/lib/ruby/bin.real/ruby: No such file or directory
    2022/07/06 05:25:58 [ERROR] Expected server to start < 10s. Timed out waiting for Mock Server to start on port 39773 - are you sure it's running?
    2022/07/06 05:25:58 [ERROR] client: failed to wait for Mock Server: Expected server to start < 10s. Timed out waiting for Mock Server to start on port 39773 - are you sure it's running?
    2022/07/06 05:25:58 Error on Verify: Post <http://localhost:39773/interactions>: dial tcp 127.0.0.1:39773: connect: connection refused
    FAIL	<http://frontiercargroup.org/dealer/consumer/client|frontiercargroup.org/dealer/consumer/client>	10.026s
    FAIL
    make: *** [Makefile:221: consumer] Error 1
    m
    • 2
    • 9
  • r

    Ravindra Dhaka

    07/06/2022, 7:14 AM
    MakeFile
    Copy code
    PACT := $(PWD)/pact/bin
    $(PACT):
    	curl -sfL <https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/master/install.sh> | sh -s -- -b $(GOPATH)/bin
    
    .PHONY: pact
    pact: $(PACT)
    	 #$(PACT) run  --no-config --deadline=10m --enable=misspell --enable=nakedret
    
    .PHONY: consumer
    consumer: pact
    	@echo "--- 🔨Running Consumer Pact tests "
    	go test -count=1 ./consumer/client -run 'TestClientPact'
  • r

    Ravindra Dhaka

    07/06/2022, 7:15 AM
    DockerFile -> i used
    Copy code
    RUN make $GOPATH/bin/pact
  • r

    Ravindra Dhaka

    07/10/2022, 5:13 PM
    getting below error while running make consumer
    Copy code
    /builds/panamera/fcg/service/dapi/pact/lib/ruby/bin/ruby: line 6: /builds/panamera/fcg/service/dapi/pact/lib/ruby/bin.real/ruby: No such file or directory
    2022/07/06 05:25:58 [ERROR] Expected server to start < 10s. Timed out waiting for Mock Server to start on port 39773 - are you sure it's running?
    2022/07/06 05:25:58 [ERROR] client: failed to wait for Mock Server: Expected server to start < 10s. Timed out waiting for Mock Server to start on port 39773 - are you sure it's running?
    2022/07/06 05:25:58 Error on Verify: Post <http://localhost:39773/interactions>: dial tcp 127.0.0.1:39
  • r

    Ravindra Dhaka

    07/10/2022, 5:14 PM
    @Octavian Herescu
    • 1
    • 2
  • e

    Erik Kvale

    07/11/2022, 3:31 PM
    Hello pact-go team, this may have been answered somewhere already and my channel and repo search terms may be off-point, but is there a timeline for the v.2.xx.xx release out of beta? I am doing some proof of concept work for my company, work which is moving rapidly. Stability is obviously a priority as we get more serious with it, so v1.xx.xx seems correct for now, but just getting a sense of a timeline for a stable release of v2.xx.xx, at your convenience. Cheers!
    m
    • 2
    • 3
  • s

    Slackbot

    07/12/2022, 8:24 AM
    This message was deleted.
    m
    r
    • 3
    • 8
  • n

    Nuno Frias

    07/12/2022, 4:24 PM
    Hi all, In
    Pact-jvm
    you have the option to define different matching rules for an attribute using the OR condition. I have recently gone through the rust codebase of the
    libpact_ffi
    library which is used by pact-go and I didn't see any support for
    OR
    matching rules, at least for Pact V3 and V4. Is there any plan to introduce this feature? This is kind of useful as i have to deal with some cases when an attribute may be null, but if it isn't it must obey a certain regex.
    m
    • 2
    • 2
  • j

    John Ed Alvinez

    07/20/2022, 11:51 AM
    hi pact-go team, apologies for the long question. thanks in advance for your help! 🙏 i've upgraded my
    pact-go
    to
    v2.0.0-beta.14
    and updated my consumer test to use Pact V4 such as replacing
    NewV3Pact()
    with
    NewV4Pact()
    . i understand that Pact V4 adds a `key` field to an interaction and its value seems to be some hash when i looked at its value in the pact generated when i ran my test. i'm guessing the hash is calculated using the
    description
    ,
    provider_states
    ,
    request
    ,
    response
    and
    pending
    fields in https://github.com/pact-foundation/pact-reference/blob/9d30a4411dfab9f0993070ef34d2ea8bf8d28a6d/rust/pact_models/src/v4/synch_http.rs#L397 i ran my consumer test several times without changing the interactions. when i inspected the value of the
    key
    field in the pact file generated, i was surprised to see that its value changes between runs. should its value stay the same instead since the pact didn't change? the pact broker thinks my consumer published a new pact, but it shouldn't be the case since i just generated again the same pact and published it without changing anything. i've attached a snippet of my simplified setup of the mock provider with interactions in this thread for reference.
    m
    • 2
    • 9
  • t

    Tarun Gulati

    07/21/2022, 6:49 PM
    Hey 👋 We are trying to use pact for creating contracts for kinesis events, the consumer listens for proto’s that are sent through. We are creating matchers using similar code as below:
    Copy code
    WithContent(map[string]interface{}{
    			"moneyToMove":           term(),
    }).WithType(&myproto.MyProtoName)
    The issue we are running into is that the unmarshaller is not able to unmarshal to proto types. Is there some methods that can be overriden to achieve this? The error that we end up getting is:
    Copy code
    VerifyMessageConsumer failed: unable to narrow type to : json: cannot unmarshal string into Go struct field myproto.created_at of type timestamppb.Timestamp
    m
    s
    • 3
    • 9
  • m

    Mark Wilson

    07/26/2022, 2:20 PM
    Hey does anyone know how to set the port for the mock server during the pact setup in golang?
    m
    • 2
    • 9
  • w

    win

    07/26/2022, 3:23 PM
    i am having issues intsalling pact-go on my m1 mac
    m
    • 2
    • 3
  • h

    Hazem Borham

    07/28/2022, 5:40 PM
    Question about 2.x.x. I'm trying out the latest beta and was wondering how to configure the
    PactLogDir
    for a provider verification. In the latest 1.7, the field is on
    VerifyRequest
    Is this still configurable?
    m
    • 2
    • 1
  • r

    Robert Henzel

    07/28/2022, 7:53 PM
    Hey I'm using pact v2.x.x to write a contract test between two of my grpc services. Andfor consumer get such error:
    Copy code
    === RUN   TestGrpcInteraction
    2022/07/28 21:46:13 [DEBUG] pact synchronous message validate config
    2022/07/28 21:46:13 [DEBUG] initialising rust mock server interface
    2022/07/28 21:46:13 [DEBUG] log_to_stdout res 0
    proto: /home/robert/go/src/giltab.elona.com/elona/dev/rosi/module/card/pact_tests/consumer_tests/../../../secure/pb/service_modulesecure.proto 
    2022-07-28T19:46:13.789357Z ERROR ThreadId(01) pact_ffi::mock_server::handles: Interaction 0x10001 is not a message interaction, it is V4 Synchronous/Messages    
    2022-07-28T19:46:14.410508Z ERROR ThreadId(01) pact_ffi::plugins: Failed to call out to plugin - Request to configure interaction failed: Failed to process protobuf: Failed to invoke protoc binary: exit code exit status: 1
    2022-07-28T19:46:14.411990Z ERROR ThreadId(01) pactffi_create_mock_server_for_transport{pact=PactHandle { pact_ref: 1 } addr=0x2248e10 port=0 transport=0x2248df0 transport_config=0x2248dd0}: pact_ffi::mock_server: Failed to start mock server - Mock server failed to start: Failed to start gRPC mock server: Pact file does not contain any Protobuf descriptors
    2022/07/28 21:46:14 unable to start plugin transport: unable to start the mock server
    FAIL    command-line-arguments  0.628s
    FAIL
    is it because the .proto file is not reachable when I do
    Copy code
    cat /home/robert/go/src/giltab.elona.com/elona/dev/rosi/module/card/pact_tests/consumer_tests/../../../secure/pb/service_modulesecure.proto
    it prints the protofile.
  • m

    Matt (pactflow.io / pact-js / pact-go)

    07/28/2022, 10:58 PM
    Failed to invoke protoc binary: exit code exit status: 1
    I’m not sure if this is the cause, but it seems to not be able to run the
    protoc
    binary.
  • m

    Matt (pactflow.io / pact-js / pact-go)

    07/28/2022, 10:58 PM
    There should also be logginsg at the plugin level that may indicate what is going on.
  • m

    Matt (pactflow.io / pact-js / pact-go)

    07/28/2022, 10:59 PM
    In your ~/.pact/plugins directory there should be the installed protobuf plugin. Please double check the permissions there and ensure the binary can run.
  • m

    Matt (pactflow.io / pact-js / pact-go)

    07/28/2022, 10:59 PM
    The framework attempts to automatically install protoc if it doesn’t exist, this may have failed also
  • r

    Robert Henzel

    07/29/2022, 6:37 AM
    Funny thing happend. When I regenerated the proto file with name
    servicemodulesecure.proto
    instead of
    service_modulesecure.proto
    I could reach it and the
    protoc
    binary was invoked. At first I thought that it cannot parse
    _
    from path but after I changed it back to
    service_modulesecure.proto
    it alswo worked. 😕 Edit: I think the permissions are all right because I was able to run the tests from
    pact-go/examples/grpc
    directory without problems.
    🤷‍♂️ 1
  • r

    Robert Henzel

    07/29/2022, 12:13 PM
    What if a providers grpc handler calls another grpc method (provider is a consumer here e.g crypt service). How can I test provider in that case. Right now I have it mocked but it does not work.
    m
    • 2
    • 1
  • r

    Robert Henzel

    07/29/2022, 12:14 PM
    Copy code
    1) Verifying a pact between module-card and module-secure - Secure Module - GetSecureDetails - Verification failed with an error - Failed to verify the request: transport error
    
    
    There were 1 pact failures
    
    === RUN   TestGrpcProvider/Provider_pact_verification
        plugin_verifier.go:56: the verifier failed to successfully verify the pacts, this indicates an issue with the provider API
    === CONT  TestGrpcProvider
        get_card_secure_details_test.go:129: 
                    Error Trace:    get_card_secure_details_test.go:129
                    Error:          Received unexpected error:
                                    the verifier failed to successfully verify the pacts, this indicates an issue with the provider API
                    Test:           TestGrpcProvider
        controller.go:269: missing call(s) to *mock_pb.MockHsmModuleServiceClient.DecryptPin(is anything, is equal to pinBlock:"567891234567"  pan:"1234567891234567"  keyGroup:"visa" (*modulehsm.DecryptPinRequest)) /home/robert/go/src/gitlab.elona.com/elona/dev/rosi/module/secure/pact_tests/provider_tests/get_card_secure_details_test.go:81
        controller.go:269: aborting test due to missing call(s)
    --- FAIL: TestGrpcProvider (10.51s)
        --- FAIL: TestGrpcProvider/Provider_pact_verification (0.00s)
    FAIL
  • g

    Guillaume Camus

    07/29/2022, 1:43 PM
    hi, when i try to install pact with
    pact-go -l DEBUG install
    , I have some errors
    Copy code
    2022/07/29 13:40:25 [INFO] package libpact_ffi not found
    2022/07/29 13:40:25 [INFO] downloading library from <https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v0.3.2/libpact_ffi-linux-x86_64.so.gz> to /usr/local/lib/libpact_ffi.so
    2022/07/29 13:40:27 [ERROR] Your Pact library installation is out of date and we were unable to download a newer one for you: open /usr/local/lib/libpact_ffi.so: permission denied
    make: *** [Makefile:13: install] Error 1
    How I could fix this ?
  • r

    Robert Henzel

    07/29/2022, 2:32 PM
    you have to change the permissions of /usr/local/lib/libpact_ffi.so file
  • r

    Robert Henzel

    07/29/2022, 2:33 PM
    I 'have changed owner of this file with chown
  • r

    Robert Henzel

    08/03/2022, 5:47 PM
    How to run pact-go@v2.x.x in container? The grpc plugin needs bunch of files.
1234Latest