test

package
v0.0.0-...-ebf3c7b Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package test contains utility methods for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CmpMatcher

func CmpMatcher(x interface{}, opts ...cmp.Option) gomock.Matcher

CmpMatcher returns a new matcher backed by go-cmp/cmp.Equal.

Types

type Reporter

type Reporter struct {
	T *testing.T
}

Reporter wraps a *testing.T, and provides a more useful failure mode when interacting with gomock.Controller.

For example, consider:

func TestMyThing(t *testing.T) {
  mockCtrl := gomock.NewController(t)
  defer mockCtrl.Finish()
  mockObj := something.NewMockMyInterface(mockCtrl)
  go func() {
    mockObj.SomeMethod(4, "blah")
  }
}

It hangs without any indication that it's missing an EXPECT() on `mockObj`. Providing the Reporter to the gomock.Controller ctor avoids this, and terminates with useful feedback. i.e.

func TestMyThing(t *testing.T) {
  mockCtrl := gomock.NewController(test.Reporter{t})
  defer mockCtrl.Finish()
  mockObj := something.NewMockMyInterface(mockCtrl)
  go func() {
    mockObj.SomeMethod(4, "blah") // crashes the test now
  }
}

func (Reporter) Errorf

func (r Reporter) Errorf(format string, args ...interface{})

Errorf is equivalent testing.T.Errorf.

func (Reporter) Fatalf

func (r Reporter) Fatalf(format string, args ...interface{})

Fatalf crashes the program with a panic to allow users to diagnose missing expects.

Jump to

Keyboard shortcuts

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