## Search

Page index: https://gasmod.dev/llms.txt. Add index.md to any page URL for its Markdown.

This site has a search endpoint: https://context7.com/api/v2/ask?siteKey=ask_b845b566cb63bd033e9c576d&query=<URL-encoded question>. It returns documentation that answers the question, with a source link for each part. No API key is needed. If nothing matches, it says so.

# migrate/migratetest

> Package migratetest holds a mock of gas.MigrationManager, MockMigrationManager, for tests of services that register migrations.

The Markdown of https://gasmod.dev/reference/migrate/migratetest/ from the Gas documentation, whose index for LLMs is https://gasmod.dev/llms.txt

```go
import "github.com/gasmod/gas/migrate/migratetest"
```

Package migratetest holds a mock of gas.MigrationManager,
[MockMigrationManager](#MockMigrationManager), for tests of services that register migrations.

## Usage

The mock records each call, and returns what the function in the field
named after the method returns:

```go
m := &migratetest.MockMigrationManager{
	RunPendingFn: func() error { return errBoom },
}
err := m.RunPending()
// err is errBoom, and m.CallCount("RunPending") is 1
```

## Defaults

With a field nil, its method succeeds and does nothing:

- Name returns migrate.ServiceName.
- Init, Close, RegisterFS, RunPending, RunPendingContext, Down and
DownContext return nil.
- Register and RegisterSlice return nothing.

RunPendingContext returns what RunPendingFn returns, and DownContext
what DownFn returns.

## Calls

Each method appends a [Call](#Call) with its name and arguments, the context
of Init and Close included, before it calls its field. A call is
recorded under the method called only: gas's Start calls
RunPendingContext, so after it CallCount("RunPendingContext") is 1 and
CallCount("RunPending") is 0. To read them:

- Calls returns a copy of them in the order they were made.
- CallCount counts those of one method.
- Reset forgets them all.

## Concurrency

The methods may be called from several goroutines at once, as the calls
are kept under a lock, which Calls, CallCount and Reset take too.
Setting a field while a method runs is a data race.


## API reference

<a id="Call"></a>

### type Call

```go
type Call struct {
	// Method is the name of the method called.
	Method string
	// Args are the method's arguments, in order.
	Args []any
}
```

Call is one call of the mock's method.

<a id="MockMigrationManager"></a>

### type MockMigrationManager

```go
type MockMigrationManager struct {
	// NameFn is what Name returns. When it is nil, Name returns
	// migrate.ServiceName.
	NameFn func() string
	// InitFn is what Init returns. When it is nil, Init returns nil.
	InitFn func(ctx context.Context) error
	// CloseFn is what Close returns. When it is nil, Close returns nil.
	CloseFn func(ctx context.Context) error
	// RegisterFn is called by Register, when it is set.
	RegisterFn func(service gas.Service, m gas.Migration)
	// RegisterSliceFn is called by RegisterSlice, when it is set.
	RegisterSliceFn func(service gas.Service, migrations []gas.Migration)
	// RegisterFSFn is what RegisterFS returns. When it is nil, RegisterFS
	// returns nil.
	RegisterFSFn func(service gas.Service, fsys fs.FS) error
	// RunPendingFn is what RunPending returns. When it is nil, RunPending
	// returns nil.
	RunPendingFn func() error
	// DownFn is what Down returns. When it is nil, Down returns nil.
	DownFn func(n int) error
	// contains filtered or unexported fields
}
```

MockMigrationManager is a gas.MigrationManager that records its calls,
as described in the package documentation.

<a id="MockMigrationManager.CallCount"></a>

#### func (*MockMigrationManager) CallCount

```go
func (m *MockMigrationManager) CallCount(method string) int
```

CallCount returns how many calls were made to method.

<a id="MockMigrationManager.Calls"></a>

#### func (*MockMigrationManager) Calls

```go
func (m *MockMigrationManager) Calls() []Call
```

Calls returns a copy of the calls, in the order they were made.

<a id="MockMigrationManager.Close"></a>

#### func (*MockMigrationManager) Close

```go
func (m *MockMigrationManager) Close(ctx context.Context) error
```

Close records the call and returns CloseFn's result.

<a id="MockMigrationManager.Down"></a>

#### func (*MockMigrationManager) Down

```go
func (m *MockMigrationManager) Down(n int) error
```

Down records the call and returns DownFn's result.

<a id="MockMigrationManager.DownContext"></a>

#### func (*MockMigrationManager) DownContext

```go
func (m *MockMigrationManager) DownContext(ctx context.Context, n int) error
```

DownContext records the call, with ctx and n, and returns DownFn's
result.

<a id="MockMigrationManager.Init"></a>

#### func (*MockMigrationManager) Init

```go
func (m *MockMigrationManager) Init(ctx context.Context) error
```

Init records the call and returns InitFn's result.

<a id="MockMigrationManager.Name"></a>

#### func (*MockMigrationManager) Name

```go
func (m *MockMigrationManager) Name() string
```

Name records the call and returns NameFn's result.

<a id="MockMigrationManager.Register"></a>

#### func (*MockMigrationManager) Register

```go
func (m *MockMigrationManager) Register(service gas.Service, migration gas.Migration)
```

Register records the call and calls RegisterFn.

<a id="MockMigrationManager.RegisterFS"></a>

#### func (*MockMigrationManager) RegisterFS

```go
func (m *MockMigrationManager) RegisterFS(service gas.Service, fsys fs.FS) error
```

RegisterFS records the call and returns RegisterFSFn's result.

<a id="MockMigrationManager.RegisterSlice"></a>

#### func (*MockMigrationManager) RegisterSlice

```go
func (m *MockMigrationManager) RegisterSlice(service gas.Service, migrations []gas.Migration)
```

RegisterSlice records the call and calls RegisterSliceFn.

<a id="MockMigrationManager.Reset"></a>

#### func (*MockMigrationManager) Reset

```go
func (m *MockMigrationManager) Reset()
```

Reset forgets every call.

<a id="MockMigrationManager.RunPending"></a>

#### func (*MockMigrationManager) RunPending

```go
func (m *MockMigrationManager) RunPending() error
```

RunPending records the call and returns RunPendingFn's result.

<a id="MockMigrationManager.RunPendingContext"></a>

#### func (*MockMigrationManager) RunPendingContext

```go
func (m *MockMigrationManager) RunPendingContext(ctx context.Context) error
```

RunPendingContext records the call, with ctx, and returns RunPendingFn's
result.
