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

Metadata information not getting recorded for protobuf-message #331

Open
sathishathpe opened this issue Aug 28, 2023 · 1 comment
Open
Labels
bug Indicates an unexpected problem or unintended behavior triage This issue is yet to be triaged by a maintainer

Comments

@sathishathpe
Copy link

sathishathpe commented Aug 28, 2023

Software versions

  • OS: e.g. Mac OSX 10.11.5
  • Consumer Pact library: Pact go v2.0.1
  • Golang Version: go1.20.5
  • Golang environment: Provide output of GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/dev/.cache/go-build" GOENV="/home/dev/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/dev/go/pkg/mod" GONOPROXY="github.hpe.com" GONOSUMDB="github.hpe.com" GOOS="linux" GOPATH="/home/dev/go" GOPRIVATE="github.hpe.com" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.20.5" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/dev/ws/pact-go/go.mod" GOWORK="" CGO_CFLAGS="-O2 -g" CGO_CPPFLAGS="" CGO_CXXFLAGS="-O2 -g" CGO_FFLAGS="-O2 -g" CGO_LDFLAGS="-O2 -g" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1831304596=/tmp/go-build -gno-record-gcc-switches"

Expected behaviour

Adding WithMetadata() to record headers in the example documented here, does not add metadata details to the contract.

Actual behaviour

Would like to see headers added to the contract

Steps to reproduce

Run the below test

//go:build consumer
// +build consumer

package protobuf

import (
	"fmt"
	"os"
	"path/filepath"
	"testing"

	message "github.com/pact-foundation/pact-go/v2/message/v4"
	"github.com/stretchr/testify/assert"
)

var dir, _ = os.Getwd()

func TestPluginMessageConsumer(t *testing.T) {
	p, _ := message.NewAsynchronousPact(message.Config{
		Consumer: "protobufmessageconsumer",
		Provider: "protobufmessageprovider",
		PactDir:  filepath.ToSlash(fmt.Sprintf("%s/../pacts", dir)),
	})

	kafkaHeaders := map[string]string{
		"specversion": "1.0",
		"type":        "eventName",
		"source":      "sourceName",
	}

	dir, _ := os.Getwd()
	path := fmt.Sprintf("%s/../grpc/routeguide/route_guide.proto", dir)

	protoMessage := `{
		"pact:proto": "` + path + `",
		"pact:message-type": "Feature",
		"pact:content-type": "application/protobuf",

		"name": "notEmpty('Big Tree')",
		"location": {
			"latitude": "matching(number, 180)",
			"longitude": "matching(number, 200)"
		}
	}`

	err := p.AddAsynchronousMessage().
		Given("the world exists").
		ExpectsToReceive("feature message").
		WithMetadata(kafkaHeaders).
		UsingPlugin(message.PluginConfig{
			Plugin:  "protobuf",
			Version: "0.3.4",
		}).
		WithContents(protoMessage, "application/protobuf").
		ExecuteTest(t, func(m message.AsynchronousMessage) error {
			return nil
		})

	assert.NoError(t, err)
}

Relevent log files

Please ensure you set logging to DEBUG and attach any relevant log files here (or link from a gist).

@mefellows mefellows added triage This issue is yet to be triaged by a maintainer enhancement Indicates new feature requests bug Indicates an unexpected problem or unintended behavior and removed enhancement Indicates new feature requests labels Aug 28, 2023
@opicaud
Copy link

opicaud commented Dec 30, 2023

Hello,
I have same issue, but apparently, AsynchronousMessage is not supported for a grpc service in golang (grpc/grpc-go#246)
On my side only SynchronousMessage is ignoring Metadata as it seems that MessageV4 does not support Metadata for now:

type MessageContents struct {
	// Message Body
	Contents []byte

	// Body is the attempt to reify the message body back into a specified type
	// Not populated for synchronous  messages
	Body interface{} `json:"contents"`

	// Message metadata. Currently not populated for synchronous messages
	// Metadata Metadata `json:"metadata"`
}

Am I right ? In that case, this feature would unlock many great NFRs to test :) like mentioned below from https://grpc.io/docs/guides/metadata/#overview

gRPC metadata is useful for a variety of purposes, such as:

* Authentication: gRPC metadata can be used to send authentication credentials to the server.  
This can be used to implement different authentication schemes, such as OAuth2 or JWT using the standard HTTP Authorization header.
* Tracing: gRPC metadata can be used to send tracing information to the server. 
This can be used to track the progress of a request through a distributed system.
* Custom headers: gRPC metadata can be used to send custom headers to the server or from the server to the client. 
This can be used to implement application-specific features, such as load balancing, rate limiting or providing detailed error messages from the server to the client.
* Internal usages: gRPC uses HTTP/2 headers and trailers, which will be integrated with the metadata specified by your application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior triage This issue is yet to be triaged by a maintainer
Projects
Status: New Issue
Development

No branches or pull requests

3 participants