models

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2019 License: BSD-3-Clause Imports: 1 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeUser

type FakeUser struct {
	StringHook func() string
	IDHook     func() string

	StringCalls []*UserStringInvocation
	IDCalls     []*UserIDInvocation
}

FakeUser is a mock implementation of User for testing. Use it in your tests as in this example:

package example

func TestWithUser(t *testing.T) {
	f := &models.FakeUser{
		StringHook: func() (ident5 string) {
			// ensure parameters meet expections, signal errors using t, etc
			return
		},
	}

	// test code goes here ...

	// assert state of FakeString ...
	f.AssertStringCalledOnce(t)
}

Create anonymous function implementations for only those interface methods that should be called in the code under test. This will force a panic if any unexpected calls are made to FakeString.

func NewFakeUserDefaultError

func NewFakeUserDefaultError(t UserTestingT) *FakeUser

NewFakeUserDefaultError returns an instance of FakeUser with all hooks configured to call t.Error

func NewFakeUserDefaultFatal

func NewFakeUserDefaultFatal(t UserTestingT) *FakeUser

NewFakeUserDefaultFatal returns an instance of FakeUser with all hooks configured to call t.Fatal

func NewFakeUserDefaultPanic

func NewFakeUserDefaultPanic() *FakeUser

NewFakeUserDefaultPanic returns an instance of FakeUser with all hooks configured to panic

func (*FakeUser) AssertIDCalled

func (f *FakeUser) AssertIDCalled(t UserTestingT)

AssertIDCalled calls t.Error if FakeUser.ID was not called

func (*FakeUser) AssertIDCalledN

func (f *FakeUser) AssertIDCalledN(t UserTestingT, n int)

AssertIDCalledN calls t.Error if FakeUser.ID was called less than n times

func (*FakeUser) AssertIDCalledOnce

func (f *FakeUser) AssertIDCalledOnce(t UserTestingT)

AssertIDCalledOnce calls t.Error if FakeUser.ID was not called exactly once

func (*FakeUser) AssertIDNotCalled

func (f *FakeUser) AssertIDNotCalled(t UserTestingT)

AssertIDNotCalled calls t.Error if FakeUser.ID was called

func (*FakeUser) AssertStringCalled

func (f *FakeUser) AssertStringCalled(t UserTestingT)

AssertStringCalled calls t.Error if FakeUser.String was not called

func (*FakeUser) AssertStringCalledN

func (f *FakeUser) AssertStringCalledN(t UserTestingT, n int)

AssertStringCalledN calls t.Error if FakeUser.String was called less than n times

func (*FakeUser) AssertStringCalledOnce

func (f *FakeUser) AssertStringCalledOnce(t UserTestingT)

AssertStringCalledOnce calls t.Error if FakeUser.String was not called exactly once

func (*FakeUser) AssertStringNotCalled

func (f *FakeUser) AssertStringNotCalled(t UserTestingT)

AssertStringNotCalled calls t.Error if FakeUser.String was called

func (*FakeUser) ID

func (_f3 *FakeUser) ID() (ident1 string)

func (*FakeUser) IDCalled

func (f *FakeUser) IDCalled() bool

IDCalled returns true if FakeUser.ID was called

func (*FakeUser) IDCalledN

func (f *FakeUser) IDCalledN(n int) bool

IDCalledN returns true if FakeUser.ID was called at least n times

func (*FakeUser) IDCalledOnce

func (f *FakeUser) IDCalledOnce() bool

IDCalledOnce returns true if FakeUser.ID was called exactly once

func (*FakeUser) IDNotCalled

func (f *FakeUser) IDNotCalled() bool

IDNotCalled returns true if FakeUser.ID was not called

func (*FakeUser) Reset added in v0.3.0

func (f *FakeUser) Reset()

func (*FakeUser) SetIDStub added in v0.3.1

func (_f4 *FakeUser) SetIDStub(ident1 string)

SetIDStub configures User.ID to always return the given values

func (*FakeUser) SetStringStub added in v0.3.1

func (_f2 *FakeUser) SetStringStub(ident5 string)

SetStringStub configures User.String to always return the given values

func (*FakeUser) String

func (_f1 *FakeUser) String() (ident5 string)

func (*FakeUser) StringCalled

func (f *FakeUser) StringCalled() bool

StringCalled returns true if FakeUser.String was called

func (*FakeUser) StringCalledN

func (f *FakeUser) StringCalledN(n int) bool

StringCalledN returns true if FakeUser.String was called at least n times

func (*FakeUser) StringCalledOnce

func (f *FakeUser) StringCalledOnce() bool

StringCalledOnce returns true if FakeUser.String was called exactly once

func (*FakeUser) StringNotCalled

func (f *FakeUser) StringNotCalled() bool

StringNotCalled returns true if FakeUser.String was not called

type User

type User interface {
	fmt.Stringer
	ID() string
}

type UserIDInvocation added in v0.3.0

type UserIDInvocation struct {
	Results struct {
		Ident1 string
	}
}

UserIDInvocation represents a single call of FakeUser.ID

type UserStringInvocation added in v0.3.0

type UserStringInvocation struct {
	Results struct {
		Ident5 string
	}
}

UserStringInvocation represents a single call of FakeUser.String

type UserTestingT added in v0.3.0

type UserTestingT interface {
	Error(...interface{})
	Errorf(string, ...interface{})
	Fatal(...interface{})
	Helper()
}

UserTestingT represents the methods of "testing".T used by charlatan Fakes. It avoids importing the testing package.

Jump to

Keyboard shortcuts

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