Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add ExpectEqualProtoMessages for cleaner, easier to debug proto assertions #148

@mitchdraft

Description

@mitchdraft

from solo-io/build

// ExpectEqualProtoMessages provides richer error messages than struct comparison by leveraging the String() method that all
// proto Messages provide. On error, Gomega's string comparison utility prints a few characters of the text immediately
// surrounding the first discrepancy.
// Example of the output:
//   Expected
//       <string>: "...-1010" vers..."
//   to equal               |
//       <string>: "...-10101" ver..."
func ExpectEqualProtoMessages(a, b proto.Message) {
	if proto.Equal(a, b) {
		return
	}
	// One shortcoming is that you only get +/- 5 chars of context
	// per: https://github.com/onsi/gomega/blob/master/format/format.go#L146
	// TODO(mitchdraft) gomega pr to modify charactersAroundMismatchToInclude (if not merged will make a util)
	Expect(a.String()).To(Equal(b.String()))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions