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

    Shakil Riyad

    11/25/2024, 9:57 PM
    @Shakil Riyad has left the channel
  • m

    Marcus Couto

    11/25/2024, 10:53 PM
    Hi folks, I am hitting a wall when trying to run my tests from my docker container, and I found out about this issue in GH. My company use Alpine, and according to this command from @Matt (pactflow.io / pact-js / pact-go) , it looks like it is not supported. Is that it, or is there any new information about this? Thank you.
    y
    m
    • 3
    • 9
  • d

    Dilip Punna

    11/29/2024, 9:26 AM
    Hi 👋 looking for some help with Pact, latest Go Pact lib looks broken due to missing dynamic libs. Anybody found any workarounds how to add this missing lib for Alpine arm64 image?
    y
    • 2
    • 1
  • m

    Marcus Couto

    11/29/2024, 3:31 PM
    Hey folks, I am wrapping my mind around what the workflow for WIP and Pending Pacts should look like. What is bugging me is that when writing the
    provider
    validation, I can only see if there is any pact failing if I run the tests in debug mode. Is that the expected behaviour, or am I missing something? For example, the first screenshot is what I get when I just “run tests” in VS Code, and the second is when I “debug test”. This means that a dev from the provider side would only notice something is wrong if they run the tests in debug mode.
    y
    • 2
    • 4
  • l

    Luis NuĂąo

    11/29/2024, 5:40 PM
    Helo! 👋🏻 I'm currently working on a Bi-Directional contract testing project. So far I had only worked with OpenAPI 3.0 yaml files, but in this case we have a Swagger 2.0 spec file and we have an endpoint that can respond with any of the next 4 different Content Types:
    Copy code
    produces:
        - application/json
        - image/jpeg
        - image/png
        - application/octet-stream
    On the consumer side we are writing a test that expects a `"Content-Type": "application/json"`:
    Copy code
    WillRespondWith(200, func(b *consumer.V2ResponseBuilder) {
       b.Header("Content-Type", Regex("application/json", "application/json;?.*"))
    }).
    But when we publish the contract to PactFlow we get the next error:
    Copy code
    Validator Error
    schema is invalid: data/type must be equal to one of the allowed values, data/type must be array, data/type must match a schema in anyOf
    Since this swagger 2.0
    anyOf
    is not supported, so is there any way we can fix this issue?
    y
    • 2
    • 14
  • y

    Yunzhao Xu

    12/02/2024, 11:58 PM
    Hello everyone! I'm new to contract testing. I've already set up a simple contract testing framework, but I have some questions in practice. I have a test related to time. For example, a certain API will return different values during specific time periods. For instance, it will return
    {a: "aaa"}
    on December 5th,
    {b: "bbb"}
    on the 8th, and
    {a: "ccc"}
    on the 9th. I'd like to know: • Do I need to include the above logics in the contract testing? Should all functional changes be included or only when the structure changes from
    a
    to
    b
    ? • How should such conditional changes that return different results be handled in contract testing? Do I need to mock the server side? If mock is needed, should it be done at a relatively earlier position, like directly mocking in the Controller, or at a relatively later position, such as inserting several test data into the database in the dev environment? And how should the situation related to time be dealt with? • Where can I learn the knowledge about this kind of writing practice? thanks
    m
    • 2
    • 2
  • j

    Jacob Buckley

    12/05/2024, 12:25 AM
    time.Time
    appears to not be mocked correctly with
    BodyMatch
    I can minimally reproduce this issue with the following:
    Copy code
    func TestPact(t *testing.T) {
    	mockProvider, err := consumer.NewV4Pact(
    		consumer.MockHTTPProviderConfig{
    			Consumer: "consumer",
    			Provider: "provider",
    		},
    	)
    	require.NoError(t, err)
    
    	type TimeStruct struct {
    		Time time.Time `json:"time"`
    	}
    	err = mockProvider.AddInteraction().
    		Given("anything").
    		UponReceiving("A request for the current time").
    		WithRequest(http.MethodGet, "/time", func(builder *consumer.V4RequestBuilder) {}).
    		WillRespondWith(
    			http.StatusOK,
    			func(builder *consumer.V4ResponseBuilder) {
    				builder.BodyMatch(
    					TimeStruct{},
    				)
    			},
    		).
    		ExecuteTest(
    			t, func(config consumer.MockServerConfig) error {
    				resp, err := http.Get(fmt.Sprintf("<http://%s:%d/time>", config.Host, config.Port))
    				require.NoError(t, err)
    				b, err := io.ReadAll(resp.Body)
    				require.NoError(t, err)
    
    				var timeStruct TimeStruct
    				err = json.Unmarshal(b, &timeStruct)
    				assert.NoError(t, err, string(b))
    				return err
    			},
    		)
    	assert.NoError(t, err)
    }
    which has the following output
    Copy code
    === RUN   TestPact
    2024-12-05T00:22:22.417160Z  INFO tokio-runtime-worker pact_mock_server::hyper_server: Received request GET /time
    2024-12-05T00:22:22.417281Z  INFO tokio-runtime-worker pact_mock_server::hyper_server: Request matched, sending response
        pact_test.go:59: 
            	Error Trace:	/Users/buckley/dev/[redacted]/pkg/api/pact/pact_test.go:59
            	            				/Users/buckley/go/pkg/mod/github.com/pact-foundation/pact-go/v2@v2.0.8/consumer/http.go:152
            	            				/Users/buckley/go/pkg/mod/github.com/pact-foundation/pact-go/v2@v2.0.8/consumer/http_v4.go:319
            	            				/Users/buckley/dev/[redacted]/pkg/api/pact/pact_test.go:50
            	Error:      	Received unexpected error:
            	            	Time.UnmarshalJSON: input is not a JSON string
            	Test:       	TestPact
            	Messages:   	{"time":{"":{"":{"":true}}}}
    2024/12/04 17:22:22 [ERROR] failed to log to stdout: can't set logger (applying the logger failed, perhaps because one is applied already).
        pact_test.go:63: 
            	Error Trace:	/Users/buckley/dev/[redacted]/pkg/api/pact/pact_test.go:63
            	Error:      	Received unexpected error:
            	            	Time.UnmarshalJSON: input is not a JSON string
            	Test:       	TestPact
    --- FAIL: TestPact (0.01s)
    
    FAIL
    You will note that the json returned is
    {"time":{"":{"":{"":true}}}}
    instead of something like
    {"time":"2024-12-04T17:24:03.987Z"}
    m
    • 2
    • 7
  • y

    Yunzhao Xu

    12/05/2024, 12:44 AM
    Hello, I I have two Golang microservices, Service A and Service B. They communicate with each other through gRPC. Service B is the service provider and Service A is the consumer. However, Service A communicates by referring to the pb package of Service B and doesn't copy the Protobuf file defined by Service B to its own directory. I think this way is great as it reduces the errors caused by different versions of Protobuf files between the two. I noticed that in the example, the path of the Protobuf file needs to be passed into
    pact:proto
    . Can this be ignored or bypassed in some other way?
    Copy code
    path := fmt.Sprintf("%s/routeguide/route_guide.proto", strings.ReplaceAll(dir, "\\", "/"))
    
    	grpcInteraction := `{
    		"pact:proto": "` + path + `",
    		"pact:proto-service": "RouteGuide/GetFeature",
    		"pact:content-type": "application/protobuf",
    		"request": {
    			"latitude": "matching(number, 180)",
    			"longitude": "matching(number, 200)"
    		},
    		"response": {
    			"name": "notEmpty('Big Tree')",
    			"location": {
    				"latitude": "matching(number, 180)",
    				"longitude": "matching(number, 200)"
    			}
    		}
    	}`
    m
    • 2
    • 9
  • y

    Yunzhao Xu

    12/05/2024, 7:08 AM
    I have write two grpc pact test follow https://github.com/pact-foundation/pact-go/blob/master/examples/grpc/grpc_consumer_test.go but when I run test in command , I always get
    Copy code
    ERROR ThreadId(19) pact_mock_server::server_manager: Failed to shutdown plugin mock server with ID 624657c5-7383-47d9-8ef2-3b757700e648 - transport error
    Is there any idea?
  • y

    Yunzhao Xu

    12/08/2024, 1:00 PM
    Hello everyone! I have a Kafka message communication that needs to be verified. I'm implementing this function according to [https://docs.pact.io/implementation_guides/go/docs/messages](https://docs.pact.io/implementation_guides/go/docs/messages). However, for the provider part of the sample code, types such as
    MessageVerifier
    and
    ProviderStateV3Response
    cannot be found. Is there a problem with the document or my usage? Where should I look for a suitable example?
    m
    • 2
    • 3
  • p

    Pietro Di Bello

    12/17/2024, 11:22 AM
    @Pietro Di Bello has left the channel
  • k

    Kevser

    01/06/2025, 3:39 PM
    Hello everyone, I'm encountering an issue with our Pact consumer tests using pact-go v2.0.1 and go 1.21.13. When sending the request, we're using Body(contentType, content), where contentType is generated by the FormDataContentType() method from multipart.Writer. Here’s how the interaction is defined:
    Copy code
    WithRequest(http.MethodPost, url, func(b *consumer.V4RequestBuilder) {
    	b.Body(contentType, content)
    }).
    Error:
    Copy code
    Mismatch with header 'Content-Type': Expected header 'Content-Type' to have value 'multipart/form-data;boundary=a76648f32eda23feef43a81954d35cbd782294c16f488baef7acbda53e32' but was 'multipart/form-data; boundary=325ce599ed0e830d149d04fa6be3c58835aa1bb7f8d31cb22d2514534999'
    is there a way to use the Body method without specifying a contentType to avoid boundary mismatches? Thanks.
    m
    r
    j
    • 4
    • 51
  • k

    Kevser

    01/15/2025, 2:50 PM
    Hello everyone again 🙂 I'm trying to send a file and include taskId as form data in the same request. The file is being sent successfully, but the taskId is missing from the contract. How can I properly include both the file and taskId in the request body? Thanks.
    Copy code
    err = mockProvider.
    		AddInteraction().
    		Given("a valid send log").
    		WithRequestPathMatcher(http.MethodPost, matchers.S(url), func(b *consumer.V4RequestBuilder) {
    			b.
    				Header("Content-Type", matchers.Like(contentType)).
    				MultipartBody(contentType, PactTaskID, "taskId").
    				MultipartBody("application/zip", zipFile, "file")
    		}).
    m
    • 2
    • 6
  • g

    GitHub

    01/21/2025, 11:03 AM
    Release - v2.0.9 New release published by YOU54F What's Changed • build(deps): bump google.golang.org/protobuf from 1.34.2 to 1.35.1 by @dependabot in #459 • build(deps): bump google.golang.org/grpc from 1.66.0 to 1.67.1 by @dependabot in #460 • fix: ensure sync messages write metadata to both req & res by @YOU54F in #461 • build(deps): bump google.golang.org/protobuf from 1.35.1 to 1.35.2 by @dependabot in #463 • chore(ci): upgrade macos-12 to macos-13 by @JP-Ellis in #468 • docs: pact-go supported platforms by @YOU54F in #466 • chore(ci): prevent duplicate ci triggers by @JP-Ellis in #476 • chore: Configure Renovate by @renovate in #467 • fix(deps): update module github.com/spf13/afero to v1.12.0 by @renovate in #483 • fix(deps): update module github.com/linkedin/goavro/v2 to v2.13.1 by @renovate in #482 • fix(deps): update module google.golang.org/protobuf to v1.36.3 by @renovate in #486 • fix(deps): update module github.com/stretchr/testify to v1.10.0 by @renovate in #487 • Improving Provider VerifyRequest - ProviderBaseURL documentation. by @marcusvnac in #464 • fix(deps): update module gopkg.in/yaml.v2 to v3 by @renovate in #489 • Deps/go mod tidy by @YOU54F in #492 New Contributors • @JP-Ellis made their first contribution in #468 • @renovate made their first contribution in #467 • @marcusvnac made their first contribution in #464 Full Changelog: v2.0.8...v2.0.9 pact-foundation/pact-go
    y
    • 2
    • 2
  • g

    GitHub

    01/21/2025, 11:54 AM
    Release - v2.0.10 New release published by YOU54F What's Changed • fix: update pact-ffi to v0.4.26 by @YOU54F in #493 Full Changelog: v2.0.9...v2.0.10 pact-foundation/pact-go
  • g

    GitHub

    01/21/2025, 12:06 PM
    Release - v2.0.10 New release published by YOU54F What's Changed • fix: update pact-ffi to v0.4.26 by @YOU54F in #493 Full Changelog: v2.0.9...v2.0.10 pact-foundation/pact-go
  • g

    GitHub

    01/21/2025, 4:00 PM
    Release - v2.1.0 New release published by YOU54F What's Changed • fix(deps): update module google.golang.org/grpc to v1.69.4 by @renovate in #488 Breaking Change • chore(deps)!: require minimum go version 1.22 by @YOU54F in #490 Full Changelog: v2.0.10...v2.1.0 pact-foundation/pact-go
  • r

    Rishav Singh

    01/22/2025, 10:07 AM
    hey team!, we are trying to write contracts tests using pact-go and we are getting this failure in our pipeline
    Copy code
    /usr/bin/ld: cannot find -lpact_ffi: No such file or directory
    collect2: error: ld returned 1 exit status
    can you please help to fix this ?
    m
    s
    • 3
    • 22
  • t

    Tom Lopez

    01/22/2025, 4:04 PM
    @Tom Lopez has left the channel
  • g

    GitHub

    01/23/2025, 3:07 PM
    Release - v2.2.0 New release published by YOU54F What's Changed • feat: support linux musl by @YOU54F in #454 Full Changelog: v2.1.0...v2.2.0 pact-foundation/pact-go
  • s

    Sudhir Meena

    01/28/2025, 11:19 AM
    Hey Team, I have an another question. I am writing contract testing following this example contract test file :- https://github.com/pact-foundation/pact-go/blob/master/examples/basic_test.go But when I am adding one another test case in the same code, Interactions are not getting merged in same pact file. I guess interactions should be merged as it is an array of interactions in pact output.
  • m

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

    01/28/2025, 11:40 AM
    Do they have unique interaction descriptions?
  • s

    Sudhir Meena

    01/28/2025, 12:28 PM
    Yes
  • m

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

    01/28/2025, 12:33 PM
    Set logs to debug and have a see if anything jumps out about writing interactions
  • m

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

    01/28/2025, 12:34 PM
    Feel free to share code examples also
    s
    • 2
    • 1
  • d

    Dominic Plourde

    01/30/2025, 7:48 PM
    Hello, I already posted my question in #C9VPNUJR2, but I feel it may be related to pact-go, we get a strange error when using certain selector:
    Copy code
    pact_verifier: Failed to load pact - Failed to load pact from '<https://pact-broker.spatium-iot.com>': Error with the content of a HAL resource - Expected either a "*" or path identifier in path expression "$.query.$" at index 8
    when we use one of those selector: • DeployedOrReleased • Environment • Deployed We tried a lot of possibilities, but only “Latest: true” works. since we have multiple environments, we also want DeployedOrReleased, which was working until recently
    m
    • 2
    • 13
  • r

    Romain LĂŠtendart

    01/31/2025, 4:56 PM
    @Romain LĂŠtendart has left the channel
  • f

    Fabian Noll

    02/03/2025, 6:00 AM
    Hello together, i am doing some Pact Messaging Tests and just saw in the pactBroker that it says the pacts are verified by pact-rust. Is this normal or a overlook of the implementation?
    Copy code
    {
      "providerName": "MQTTProducer",
      "providerApplicationVersion": "1.0.0",
      "success": true,
      "verificationDate": "2025-02-03T05:54:37+00:00",
      "testResults": [
        {
          "interactionId": "4502629169ea07b9fd7c9fd70c772553a1b4407d",
          "success": true
        }
      ],
      "verifiedBy": {
        "implementation": "Pact-Rust",
        "version": "1.2.5"
      },
      "_links": {
        "self": {
          "title": "Verification result",
          "name": "Verification result 201 for Pact between MQTTConsumer (1.0.1) and MQTTProducer",
          "href": "<http://localhost:9292/pacts/provider/MQTTProducer/consumer/MQTTConsumer/pact-version/cd421621766dde56e9e01a0c8a8b47c4b5f63b40/verification-results/201>"
        },
        "pb:pact-version": {
          "title": "Pact",
          "name": "Pact between MQTTConsumer (1.0.1) and MQTTProducer",
          "href": "<http://localhost:9292/pacts/provider/MQTTProducer/consumer/MQTTConsumer/pact-version/cd421621766dde56e9e01a0c8a8b47c4b5f63b40/metadata/Y3ZuPTEuMC4x>"
        },
        "pb:triggered-webhooks": {
          "title": "Webhooks triggered by the publication of this verification result",
          "href": "<http://localhost:9292/pacts/provider/MQTTProducer/consumer/MQTTConsumer/pact-version/cd421621766dde56e9e01a0c8a8b47c4b5f63b40/verification-results/201/triggered-webhooks>"
        }
      }
    }
    m
    • 2
    • 4
  • d

    Devin Woods

    02/05/2025, 8:58 PM
    When trying to run provider pact tests, getting this error:
    Copy code
    Undefined symbols for architecture arm64:
      "_pactffi_with_metadata", referenced from:
          __cgo_b3f3fec7e6e1_Cfunc_pactffi_with_metadata in 000003.o
    ld: symbol(s) not found for architecture arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    Anyone ever see this before?
    m
    e
    • 3
    • 9
  • s

    Spencer

    02/11/2025, 3:34 PM
    @Spencer has left the channel
1234Latest