aboutsummaryrefslogtreecommitdiffstats
path: root/internal/bolttest/mock_migration_fs_repo.go
blob: d392732e5f138cc142370812d28bd935296a1fa0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package bolttest

import "github.com/eugenetriguba/bolt/internal/models"

type MockMigrationFsRepo struct {
	CreateReturnValue              CreateReturnValue
	CreateCallCount                int
	ListReturnValue                ListReturnValue
	ListCallCount                  int
	ReadUpgradeScriptReturnValue   ReadUpgradeScriptReturnValue
	ReadUpgradeScriptCallCount     int
	ReadDowngradeScriptReturnValue ReadDowngradeScriptReturnValue
	ReadDowngradeScriptCallCount   int
}

type CreateReturnValue struct {
	Err error
}

type ReadUpgradeScriptReturnValue struct {
	ScriptContents string
	Err            error
}

type ReadDowngradeScriptReturnValue = ReadUpgradeScriptReturnValue

func (repo *MockMigrationFsRepo) Create(migration *models.Migration) error {
	repo.CreateCallCount += 1
	return repo.CreateReturnValue.Err
}

func (repo *MockMigrationFsRepo) List() (map[string]*models.Migration, error) {
	repo.ListCallCount += 1
	return repo.ListReturnValue.Migrations, repo.ListReturnValue.Err
}

func (repo *MockMigrationFsRepo) ReadUpgradeScript(
	migration *models.Migration,
) (string, error) {
	repo.ReadUpgradeScriptCallCount += 1
	return repo.ReadUpgradeScriptReturnValue.ScriptContents, repo.ReadUpgradeScriptReturnValue.Err
}

func (repo *MockMigrationFsRepo) ReadDowngradeScript(
	migration *models.Migration,
) (string, error) {
	repo.ReadDowngradeScriptCallCount += 1
	return repo.ReadDowngradeScriptReturnValue.ScriptContents, repo.ReadDowngradeScriptReturnValue.Err
}