grpcmatchers

package module
v0.0.0-...-338de40 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 7 Imported by: 0

README

gomega-grpc

When comparing protobuf objects in Gomega could be a bit complicated as unmarshaled structs cannot be directly compared by the tranditional gomega Equal. This library provides a set of matchers to compare protobuf objects.

Usage

ProtoEqual
import (
    . "github.com/onsi/gomega"
    . "github.com/onsi/gomega-grpc"
)

var _ = Describe("MyTest", func() {
    It("should compare protobuf objects", func() {
        Expect(Message{
			Message: "message 1",
        }).To ProtoEqual(Message{
            Message: "message 2",
        })
    })
})

The above will produce:

  Expected
    <string>: {
      "message": "message 2"
    }
  to equal
    <string>: {
      "message": "message 1"
    }

  Diff:
   {
  -  "message": "message 1"
  +  "message": "message 2"
   }

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func HaveErrorInfoDomain

func HaveErrorInfoDomain(matcher types.GomegaMatcher) *matchersimpl.GRPCStatusMatcher

HaveErrorInfoDomain will match the *errdetails.ErrorInfo Reason property against the given matcher.

Example
st, err := status.New(codes.Internal, "message").WithDetails(&errdetails.ErrorInfo{
	Domain: "some domain",
})
Expect(err).ToNot(HaveOccurred())

Expect(st).To(HaveErrorInfoDomain(Equal("some domain")))
Output:

func HaveErrorInfoMetadata

func HaveErrorInfoMetadata(matcher types.GomegaMatcher) *matchersimpl.GRPCStatusMatcher

HaveErrorInfoMetadata will match the *errdetails.ErrorInfo Reason property against the given matcher.

Example
st, err := status.New(codes.Internal, "message").WithDetails(&errdetails.ErrorInfo{
	Metadata: map[string]string{
		"key1": "value1",
	},
})
Expect(err).ToNot(HaveOccurred())

Expect(st).To(HaveErrorInfoMetadata(HaveKey("key1")))
Output:

func HaveErrorInfoReason

func HaveErrorInfoReason(matcher types.GomegaMatcher) *matchersimpl.GRPCStatusMatcher

HaveErrorInfoReason will match the *errdetails.ErrorInfo Reason property against the given matcher.

Example
st, err := status.New(codes.Internal, "message").WithDetails(&errdetails.ErrorInfo{
	Reason: "some reason",
})
Expect(err).ToNot(HaveOccurred())

Expect(st).To(HaveErrorInfoReason(Equal("some reason")))
Output:

func HaveFieldViolation

func HaveFieldViolation(fieldAndDescription ...string) *matchersimpl.GRPCStatusMatcher

HaveFieldValidation matches a given field and description (if informed) for a given errdetails.BadRequest or errdetails.BadRequest_FieldViolation[] or errdetails.BadRequest_FieldViolation.

func HaveStatusCode

func HaveStatusCode(matcher types.GomegaMatcher) *matchersimpl.GRPCStatusMatcher

HaveStatusCode will match the *status.Status Code property against the given matcher.

Example
err := status.New(codes.Internal, "message").Err()

Expect(err).To(HaveStatusCode(Equal(codes.Internal)))
Output:

func HaveStatusMessage

func HaveStatusMessage(matcher types.GomegaMatcher) *matchersimpl.GRPCStatusMatcher

HaveStatusMessage will match the *status.Status Message property against the given matcher.

Example
err := status.New(codes.Internal, "this is a message").Err()

Expect(err).To(HaveStatusMessage(Equal("this is a message")))
Expect(err).To(HaveStatusMessage(ContainSubstring("message")))
Output:

func ProtoEqual

func ProtoEqual(m proto.Message) types.GomegaMatcher

ProtoEqual is the matcher for comparing proto.Message values. This matcher is powered by the proto.Equal function, provided by the default GRPC implementation.

Example
errInfo := &errdetails.ErrorInfo{
	Reason: "some reason",
}

Expect(errInfo).To(ProtoEqual(&errdetails.ErrorInfo{
	Reason: "some reason",
}))
Output:

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL