mock

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2024 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conf

type Conf = conf.Conf

type ConfMock

type ConfMock struct {
	// GetStringFunc mocks the GetString method.
	GetStringFunc func(key string, defaultValue ...string) string

	// UnmarshalFunc mocks the Unmarshal method.
	UnmarshalFunc func(key string, config any, defaultValue ...any) error
	// contains filtered or unexported fields
}

ConfMock is a mock implementation of Conf.

func TestSomethingThatUsesConf(t *testing.T) {

	// make and configure a mocked Conf
	mockedConf := &ConfMock{
		GetStringFunc: func(key string, defaultValue ...string) string {
			panic("mock out the GetString method")
		},
		UnmarshalFunc: func(key string, config any, defaultValue ...any) error {
			panic("mock out the Unmarshal method")
		},
	}

	// use mockedConf in code that requires Conf
	// and then make assertions.

}

func (*ConfMock) GetString

func (mock *ConfMock) GetString(key string, defaultValue ...string) string

GetString calls GetStringFunc.

func (*ConfMock) GetStringCalls

func (mock *ConfMock) GetStringCalls() []struct {
	Key          string
	DefaultValue []string
}

GetStringCalls gets all the calls that were made to GetString. Check the length with:

len(mockedConf.GetStringCalls())

func (*ConfMock) Unmarshal

func (mock *ConfMock) Unmarshal(key string, config any, defaultValue ...any) error

Unmarshal calls UnmarshalFunc.

func (*ConfMock) UnmarshalCalls

func (mock *ConfMock) UnmarshalCalls() []struct {
	Key          string
	Config       any
	DefaultValue []any
}

UnmarshalCalls gets all the calls that were made to Unmarshal. Check the length with:

len(mockedConf.UnmarshalCalls())

Jump to

Keyboard shortcuts

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