Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentType being set as application/json for protobuf messages #265

Closed
sandy999 opened this issue Jan 27, 2023 · 3 comments
Closed

ContentType being set as application/json for protobuf messages #265

sandy999 opened this issue Jan 27, 2023 · 3 comments

Comments

@sandy999
Copy link

Software versions

  • OS: macOS13.2
  • Consumer Pact library: Pact Go CLI v2.0.0-beta.17
  • Provider Pact library: pact-go/v2 v2.0.0-beta.17.0.20221222235702-6e805a539d1b
  • Golang Version: go1.18.3 darwin/arm64
  • Golang environment: Provide output of go env

Expected behaviour

The content type header should be set to the one provided via Metadata

Actual behaviour

I am trying to setup a producer/consumer pact test for a protobuf based messaging contract. I have the consumer test setup using the protobuf plugin 0.2.4

When setting up the producer test using the VerifyProvider I am getting below error:

1) Verifying a pact between Consumer and Provider Given event processing for transaction - an event for transaction processing
    1.1) has a matching body
           expected 'application/protobuf;message=Event' body but was 'application/json;charset=utf-8'

I have the contentType correct context type defined in the Metadata when setting up the message Handles

    return event, pactmessage.Metadata{
        "contentType": "application/protobuf;message=Event",
    }, nil

Steps to reproduce

Here is the sanitized test I have for the producer

func TestEventPact(t *testing.T) {
	var dir, _ = os.Getwd()
	var pactDir = fmt.Sprintf("%s/pacts", dir)

	err := pactlog.SetLogLevel("DEBUG")
	assert.NoError(t, err)

	pactversion.CheckVersion()

	verifier := pactprovider.NewVerifier()
	
	functionMappings := pactmessage.Handlers{
		"a event for transaction processing": func([]models.ProviderState) (pactmessage.Body, pactmessage.Metadata, error) {
			return &proto.Event{}, pactmessage.Metadata{
				"contentType": "application/protobuf;message=Event",
			}, nil
		},
	}

	stateMappings := models.StateHandlers{
		"processing transaction": func(setup bool, s models.ProviderState) (models.ProviderStateResponse, error) {
			return nil, nil
		},
	}
	
	err = verifier.VerifyProvider(t, pactprovider.VerifyRequest{
		PactFiles: []string{
			filepath.ToSlash(fmt.Sprintf("%s/pact.json", pactDir)),
		},
		StateHandlers:   stateMappings,
		Provider:        "V4MessageProvider",
		MessageHandlers: functionMappings,
	})

	assert.NoError(t, err)
}

Relevent log files

NA

@mefellows
Copy link
Member

Thanks, this is definitely an enhancement required. Somewhere in the messaging part of the framework, the content-type is hard coded but we need to accept the content-type from the user.

@github-actions
Copy link

👋 Hi! The 'smartbear-supported' label has just been added to this issue, which will create an internal tracking ticket in PactFlow's Jira (PACT-1174). We will use this to prioritise and assign a team member to this task. All activity will be public on this ticket. For now, sit tight and we'll update this ticket once we have more information on the next steps.

See our documentation for more information.

@mefellows
Copy link
Member

Fixed in v2.0.0-beta.23. Example also added so you can see it in action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants