equalcmp

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2021 License: MIT Imports: 3 Imported by: 0

README

equal-cmp

A module that implements gomega's Equal with go-cmp.

The EqualCmp provided by this module makes it easier to understand the difference between the actual value and the expected value when they do not match than the Equal provided by gomega.

Example

Given the following test code using ginkgo and gomega.

package example_test

import (
	. "github.com/kamikazezirou/equal-cmp"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

type Object struct {
	ID   int
	Name string
}

var _ = Describe("Example", func() {
	It("Example", func() {
		actual := Object{ID: 1, Name: "actual"}
		expected := Object{ID: 1, Name: "expected"}
		Expect(actual).Should(EqualCmp(expected))
	})
})

The error message is as follows.

• Failure [0.000 seconds]
Example
...
  Example [It]
  ...

  Mismatch(-actual +expected):
    equalcmp_test.Object{
    	ID:   1,
  - 	Name: "actual",
  + 	Name: "expected",
    }

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualCmp

func EqualCmp(expected interface{}, options ...cmp.Option) types.GomegaMatcher

EqualCmp uses go-cmp to compare actual with expected. Equal is strict about types when performing comparisons. It is an error for both actual and expected to be nil. Use BeNil() instead.

Types

This section is empty.

Jump to

Keyboard shortcuts

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