From 4588bf704d79103041d52b59036ad15f0670d998 Mon Sep 17 00:00:00 2001 From: haedhutner Date: Sat, 15 Mar 2025 19:03:22 +0200 Subject: [PATCH] Add mockery, mock interfaces --- .mockery.yml | 7 +- internal/mocks/CliFlagRetriever.go | 1116 +++++++++++++++++ internal/mocks/EnvVarRetriever.go | 644 ++++++++++ internal/mocks/MigrationPhaseRetriever.go | 197 +++ .../mocks/PilgrimConfigurationRetriever.go | 530 ++++++++ {pilgrim => internal/pilgrim_conf}/cli.go | 2 +- {pilgrim => internal/pilgrim_conf}/context.go | 4 +- {pilgrim => internal/pilgrim_conf}/env.go | 2 +- {pilgrim => internal/pilgrim_conf}/error.go | 2 +- .../pilgrim_conf}/url_parts.go | 2 +- internal/pilgrim_conf_test/cli_test.go | 209 +++ internal/pilgrim_conf_test/context_test.go | 149 +++ .../pilgrim_conf_test}/env_test.go | 50 +- .../pilgrim_conf_test}/url_parts_test.go | 14 +- main.go | 16 - pilgrim.go | 16 + pilgrim/test/cli_test.go | 209 --- pilgrim/test/context_test.go | 109 -- pilgrim/test/mock/context_mock.go | 207 --- 19 files changed, 2900 insertions(+), 585 deletions(-) create mode 100644 internal/mocks/CliFlagRetriever.go create mode 100644 internal/mocks/EnvVarRetriever.go create mode 100644 internal/mocks/MigrationPhaseRetriever.go create mode 100644 internal/mocks/PilgrimConfigurationRetriever.go rename {pilgrim => internal/pilgrim_conf}/cli.go (99%) rename {pilgrim => internal/pilgrim_conf}/context.go (98%) rename {pilgrim => internal/pilgrim_conf}/env.go (99%) rename {pilgrim => internal/pilgrim_conf}/error.go (92%) rename {pilgrim => internal/pilgrim_conf}/url_parts.go (99%) create mode 100644 internal/pilgrim_conf_test/cli_test.go create mode 100644 internal/pilgrim_conf_test/context_test.go rename {pilgrim/test => internal/pilgrim_conf_test}/env_test.go (55%) rename {pilgrim/test => internal/pilgrim_conf_test}/url_parts_test.go (72%) delete mode 100644 main.go create mode 100644 pilgrim.go delete mode 100644 pilgrim/test/cli_test.go delete mode 100644 pilgrim/test/context_test.go delete mode 100644 pilgrim/test/mock/context_mock.go diff --git a/.mockery.yml b/.mockery.yml index eb85148..ef7ae85 100644 --- a/.mockery.yml +++ b/.mockery.yml @@ -1,6 +1 @@ -with-expecter: True - -packages: - pilgrim: - interfaces: - CliFlagRetriever: \ No newline at end of file +with-expecter: True \ No newline at end of file diff --git a/internal/mocks/CliFlagRetriever.go b/internal/mocks/CliFlagRetriever.go new file mode 100644 index 0000000..d675983 --- /dev/null +++ b/internal/mocks/CliFlagRetriever.go @@ -0,0 +1,1116 @@ +// Code generated by mockery 2.53.2. DO NOT EDIT. + +package pilgrim_mock + +import ( + mock "github.com/stretchr/testify/mock" + pilgrim_conf "mvvasilev.dev/pilgrim/internal/pilgrim_conf" +) + +// CliFlagRetriever is an autogenerated mock type for the CliFlagRetriever type +type CliFlagRetriever struct { + mock.Mock +} + +type CliFlagRetriever_Expecter struct { + mock *mock.Mock +} + +func (_m *CliFlagRetriever) EXPECT() *CliFlagRetriever_Expecter { + return &CliFlagRetriever_Expecter{mock: &_m.Mock} +} + +// Args provides a mock function with no fields +func (_m *CliFlagRetriever) Args() (map[string]string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Args") + } + + var r0 map[string]string + var r1 bool + if rf, ok := ret.Get(0).(func() (map[string]string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() map[string]string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[string]string) + } + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_Args_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Args' +type CliFlagRetriever_Args_Call struct { + *mock.Call +} + +// Args is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) Args() *CliFlagRetriever_Args_Call { + return &CliFlagRetriever_Args_Call{Call: _e.mock.On("Args")} +} + +func (_c *CliFlagRetriever_Args_Call) Run(run func()) *CliFlagRetriever_Args_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_Args_Call) Return(value map[string]string, isProvided bool) *CliFlagRetriever_Args_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_Args_Call) RunAndReturn(run func() (map[string]string, bool)) *CliFlagRetriever_Args_Call { + _c.Call.Return(run) + return _c +} + +// Directory provides a mock function with no fields +func (_m *CliFlagRetriever) Directory() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Directory") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_Directory_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Directory' +type CliFlagRetriever_Directory_Call struct { + *mock.Call +} + +// Directory is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) Directory() *CliFlagRetriever_Directory_Call { + return &CliFlagRetriever_Directory_Call{Call: _e.mock.On("Directory")} +} + +func (_c *CliFlagRetriever_Directory_Call) Run(run func()) *CliFlagRetriever_Directory_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_Directory_Call) Return(value string, isProvided bool) *CliFlagRetriever_Directory_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_Directory_Call) RunAndReturn(run func() (string, bool)) *CliFlagRetriever_Directory_Call { + _c.Call.Return(run) + return _c +} + +// Driver provides a mock function with no fields +func (_m *CliFlagRetriever) Driver() (pilgrim_conf.DbDriver, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Driver") + } + + var r0 pilgrim_conf.DbDriver + var r1 bool + if rf, ok := ret.Get(0).(func() (pilgrim_conf.DbDriver, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() pilgrim_conf.DbDriver); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(pilgrim_conf.DbDriver) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_Driver_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Driver' +type CliFlagRetriever_Driver_Call struct { + *mock.Call +} + +// Driver is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) Driver() *CliFlagRetriever_Driver_Call { + return &CliFlagRetriever_Driver_Call{Call: _e.mock.On("Driver")} +} + +func (_c *CliFlagRetriever_Driver_Call) Run(run func()) *CliFlagRetriever_Driver_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_Driver_Call) Return(value pilgrim_conf.DbDriver, isProvided bool) *CliFlagRetriever_Driver_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_Driver_Call) RunAndReturn(run func() (pilgrim_conf.DbDriver, bool)) *CliFlagRetriever_Driver_Call { + _c.Call.Return(run) + return _c +} + +// Host provides a mock function with no fields +func (_m *CliFlagRetriever) Host() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Host") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_Host_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Host' +type CliFlagRetriever_Host_Call struct { + *mock.Call +} + +// Host is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) Host() *CliFlagRetriever_Host_Call { + return &CliFlagRetriever_Host_Call{Call: _e.mock.On("Host")} +} + +func (_c *CliFlagRetriever_Host_Call) Run(run func()) *CliFlagRetriever_Host_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_Host_Call) Return(value string, isProvided bool) *CliFlagRetriever_Host_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_Host_Call) RunAndReturn(run func() (string, bool)) *CliFlagRetriever_Host_Call { + _c.Call.Return(run) + return _c +} + +// IsChecksumValidationEnabled provides a mock function with no fields +func (_m *CliFlagRetriever) IsChecksumValidationEnabled() (bool, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for IsChecksumValidationEnabled") + } + + var r0 bool + var r1 bool + if rf, ok := ret.Get(0).(func() (bool, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_IsChecksumValidationEnabled_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsChecksumValidationEnabled' +type CliFlagRetriever_IsChecksumValidationEnabled_Call struct { + *mock.Call +} + +// IsChecksumValidationEnabled is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) IsChecksumValidationEnabled() *CliFlagRetriever_IsChecksumValidationEnabled_Call { + return &CliFlagRetriever_IsChecksumValidationEnabled_Call{Call: _e.mock.On("IsChecksumValidationEnabled")} +} + +func (_c *CliFlagRetriever_IsChecksumValidationEnabled_Call) Run(run func()) *CliFlagRetriever_IsChecksumValidationEnabled_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_IsChecksumValidationEnabled_Call) Return(value bool, isProvided bool) *CliFlagRetriever_IsChecksumValidationEnabled_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_IsChecksumValidationEnabled_Call) RunAndReturn(run func() (bool, bool)) *CliFlagRetriever_IsChecksumValidationEnabled_Call { + _c.Call.Return(run) + return _c +} + +// IsDown provides a mock function with no fields +func (_m *CliFlagRetriever) IsDown() (bool, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for IsDown") + } + + var r0 bool + var r1 bool + if rf, ok := ret.Get(0).(func() (bool, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_IsDown_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsDown' +type CliFlagRetriever_IsDown_Call struct { + *mock.Call +} + +// IsDown is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) IsDown() *CliFlagRetriever_IsDown_Call { + return &CliFlagRetriever_IsDown_Call{Call: _e.mock.On("IsDown")} +} + +func (_c *CliFlagRetriever_IsDown_Call) Run(run func()) *CliFlagRetriever_IsDown_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_IsDown_Call) Return(value bool, isProvided bool) *CliFlagRetriever_IsDown_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_IsDown_Call) RunAndReturn(run func() (bool, bool)) *CliFlagRetriever_IsDown_Call { + _c.Call.Return(run) + return _c +} + +// IsStrictOrderingEnabled provides a mock function with no fields +func (_m *CliFlagRetriever) IsStrictOrderingEnabled() (bool, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for IsStrictOrderingEnabled") + } + + var r0 bool + var r1 bool + if rf, ok := ret.Get(0).(func() (bool, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_IsStrictOrderingEnabled_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsStrictOrderingEnabled' +type CliFlagRetriever_IsStrictOrderingEnabled_Call struct { + *mock.Call +} + +// IsStrictOrderingEnabled is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) IsStrictOrderingEnabled() *CliFlagRetriever_IsStrictOrderingEnabled_Call { + return &CliFlagRetriever_IsStrictOrderingEnabled_Call{Call: _e.mock.On("IsStrictOrderingEnabled")} +} + +func (_c *CliFlagRetriever_IsStrictOrderingEnabled_Call) Run(run func()) *CliFlagRetriever_IsStrictOrderingEnabled_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_IsStrictOrderingEnabled_Call) Return(value bool, isProvided bool) *CliFlagRetriever_IsStrictOrderingEnabled_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_IsStrictOrderingEnabled_Call) RunAndReturn(run func() (bool, bool)) *CliFlagRetriever_IsStrictOrderingEnabled_Call { + _c.Call.Return(run) + return _c +} + +// IsUp provides a mock function with no fields +func (_m *CliFlagRetriever) IsUp() (bool, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for IsUp") + } + + var r0 bool + var r1 bool + if rf, ok := ret.Get(0).(func() (bool, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_IsUp_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsUp' +type CliFlagRetriever_IsUp_Call struct { + *mock.Call +} + +// IsUp is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) IsUp() *CliFlagRetriever_IsUp_Call { + return &CliFlagRetriever_IsUp_Call{Call: _e.mock.On("IsUp")} +} + +func (_c *CliFlagRetriever_IsUp_Call) Run(run func()) *CliFlagRetriever_IsUp_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_IsUp_Call) Return(value bool, isProvided bool) *CliFlagRetriever_IsUp_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_IsUp_Call) RunAndReturn(run func() (bool, bool)) *CliFlagRetriever_IsUp_Call { + _c.Call.Return(run) + return _c +} + +// IsValidatingChecksums provides a mock function with no fields +func (_m *CliFlagRetriever) IsValidatingChecksums() (bool, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for IsValidatingChecksums") + } + + var r0 bool + var r1 bool + if rf, ok := ret.Get(0).(func() (bool, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_IsValidatingChecksums_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsValidatingChecksums' +type CliFlagRetriever_IsValidatingChecksums_Call struct { + *mock.Call +} + +// IsValidatingChecksums is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) IsValidatingChecksums() *CliFlagRetriever_IsValidatingChecksums_Call { + return &CliFlagRetriever_IsValidatingChecksums_Call{Call: _e.mock.On("IsValidatingChecksums")} +} + +func (_c *CliFlagRetriever_IsValidatingChecksums_Call) Run(run func()) *CliFlagRetriever_IsValidatingChecksums_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_IsValidatingChecksums_Call) Return(value bool, isProvided bool) *CliFlagRetriever_IsValidatingChecksums_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_IsValidatingChecksums_Call) RunAndReturn(run func() (bool, bool)) *CliFlagRetriever_IsValidatingChecksums_Call { + _c.Call.Return(run) + return _c +} + +// IsValidatingLatest provides a mock function with no fields +func (_m *CliFlagRetriever) IsValidatingLatest() (bool, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for IsValidatingLatest") + } + + var r0 bool + var r1 bool + if rf, ok := ret.Get(0).(func() (bool, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_IsValidatingLatest_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsValidatingLatest' +type CliFlagRetriever_IsValidatingLatest_Call struct { + *mock.Call +} + +// IsValidatingLatest is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) IsValidatingLatest() *CliFlagRetriever_IsValidatingLatest_Call { + return &CliFlagRetriever_IsValidatingLatest_Call{Call: _e.mock.On("IsValidatingLatest")} +} + +func (_c *CliFlagRetriever_IsValidatingLatest_Call) Run(run func()) *CliFlagRetriever_IsValidatingLatest_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_IsValidatingLatest_Call) Return(value bool, isProvided bool) *CliFlagRetriever_IsValidatingLatest_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_IsValidatingLatest_Call) RunAndReturn(run func() (bool, bool)) *CliFlagRetriever_IsValidatingLatest_Call { + _c.Call.Return(run) + return _c +} + +// IsValidatingMigrationOrder provides a mock function with no fields +func (_m *CliFlagRetriever) IsValidatingMigrationOrder() (bool, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for IsValidatingMigrationOrder") + } + + var r0 bool + var r1 bool + if rf, ok := ret.Get(0).(func() (bool, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_IsValidatingMigrationOrder_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsValidatingMigrationOrder' +type CliFlagRetriever_IsValidatingMigrationOrder_Call struct { + *mock.Call +} + +// IsValidatingMigrationOrder is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) IsValidatingMigrationOrder() *CliFlagRetriever_IsValidatingMigrationOrder_Call { + return &CliFlagRetriever_IsValidatingMigrationOrder_Call{Call: _e.mock.On("IsValidatingMigrationOrder")} +} + +func (_c *CliFlagRetriever_IsValidatingMigrationOrder_Call) Run(run func()) *CliFlagRetriever_IsValidatingMigrationOrder_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_IsValidatingMigrationOrder_Call) Return(value bool, isProvided bool) *CliFlagRetriever_IsValidatingMigrationOrder_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_IsValidatingMigrationOrder_Call) RunAndReturn(run func() (bool, bool)) *CliFlagRetriever_IsValidatingMigrationOrder_Call { + _c.Call.Return(run) + return _c +} + +// MigrationTable provides a mock function with no fields +func (_m *CliFlagRetriever) MigrationTable() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for MigrationTable") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_MigrationTable_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MigrationTable' +type CliFlagRetriever_MigrationTable_Call struct { + *mock.Call +} + +// MigrationTable is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) MigrationTable() *CliFlagRetriever_MigrationTable_Call { + return &CliFlagRetriever_MigrationTable_Call{Call: _e.mock.On("MigrationTable")} +} + +func (_c *CliFlagRetriever_MigrationTable_Call) Run(run func()) *CliFlagRetriever_MigrationTable_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_MigrationTable_Call) Return(value string, isProvided bool) *CliFlagRetriever_MigrationTable_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_MigrationTable_Call) RunAndReturn(run func() (string, bool)) *CliFlagRetriever_MigrationTable_Call { + _c.Call.Return(run) + return _c +} + +// MigrationTableSchema provides a mock function with no fields +func (_m *CliFlagRetriever) MigrationTableSchema() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for MigrationTableSchema") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_MigrationTableSchema_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MigrationTableSchema' +type CliFlagRetriever_MigrationTableSchema_Call struct { + *mock.Call +} + +// MigrationTableSchema is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) MigrationTableSchema() *CliFlagRetriever_MigrationTableSchema_Call { + return &CliFlagRetriever_MigrationTableSchema_Call{Call: _e.mock.On("MigrationTableSchema")} +} + +func (_c *CliFlagRetriever_MigrationTableSchema_Call) Run(run func()) *CliFlagRetriever_MigrationTableSchema_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_MigrationTableSchema_Call) Return(value string, isProvided bool) *CliFlagRetriever_MigrationTableSchema_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_MigrationTableSchema_Call) RunAndReturn(run func() (string, bool)) *CliFlagRetriever_MigrationTableSchema_Call { + _c.Call.Return(run) + return _c +} + +// ParseFlags provides a mock function with no fields +func (_m *CliFlagRetriever) ParseFlags() { + _m.Called() +} + +// CliFlagRetriever_ParseFlags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ParseFlags' +type CliFlagRetriever_ParseFlags_Call struct { + *mock.Call +} + +// ParseFlags is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) ParseFlags() *CliFlagRetriever_ParseFlags_Call { + return &CliFlagRetriever_ParseFlags_Call{Call: _e.mock.On("ParseFlags")} +} + +func (_c *CliFlagRetriever_ParseFlags_Call) Run(run func()) *CliFlagRetriever_ParseFlags_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_ParseFlags_Call) Return() *CliFlagRetriever_ParseFlags_Call { + _c.Call.Return() + return _c +} + +func (_c *CliFlagRetriever_ParseFlags_Call) RunAndReturn(run func()) *CliFlagRetriever_ParseFlags_Call { + _c.Run(run) + return _c +} + +// Password provides a mock function with no fields +func (_m *CliFlagRetriever) Password() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Password") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_Password_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Password' +type CliFlagRetriever_Password_Call struct { + *mock.Call +} + +// Password is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) Password() *CliFlagRetriever_Password_Call { + return &CliFlagRetriever_Password_Call{Call: _e.mock.On("Password")} +} + +func (_c *CliFlagRetriever_Password_Call) Run(run func()) *CliFlagRetriever_Password_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_Password_Call) Return(value string, isProvided bool) *CliFlagRetriever_Password_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_Password_Call) RunAndReturn(run func() (string, bool)) *CliFlagRetriever_Password_Call { + _c.Call.Return(run) + return _c +} + +// Port provides a mock function with no fields +func (_m *CliFlagRetriever) Port() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Port") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_Port_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Port' +type CliFlagRetriever_Port_Call struct { + *mock.Call +} + +// Port is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) Port() *CliFlagRetriever_Port_Call { + return &CliFlagRetriever_Port_Call{Call: _e.mock.On("Port")} +} + +func (_c *CliFlagRetriever_Port_Call) Run(run func()) *CliFlagRetriever_Port_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_Port_Call) Return(value string, isProvided bool) *CliFlagRetriever_Port_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_Port_Call) RunAndReturn(run func() (string, bool)) *CliFlagRetriever_Port_Call { + _c.Call.Return(run) + return _c +} + +// Script provides a mock function with no fields +func (_m *CliFlagRetriever) Script() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Script") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_Script_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Script' +type CliFlagRetriever_Script_Call struct { + *mock.Call +} + +// Script is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) Script() *CliFlagRetriever_Script_Call { + return &CliFlagRetriever_Script_Call{Call: _e.mock.On("Script")} +} + +func (_c *CliFlagRetriever_Script_Call) Run(run func()) *CliFlagRetriever_Script_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_Script_Call) Return(value string, isProvided bool) *CliFlagRetriever_Script_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_Script_Call) RunAndReturn(run func() (string, bool)) *CliFlagRetriever_Script_Call { + _c.Call.Return(run) + return _c +} + +// Segments provides a mock function with no fields +func (_m *CliFlagRetriever) Segments() ([]string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Segments") + } + + var r0 []string + var r1 bool + if rf, ok := ret.Get(0).(func() ([]string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_Segments_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Segments' +type CliFlagRetriever_Segments_Call struct { + *mock.Call +} + +// Segments is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) Segments() *CliFlagRetriever_Segments_Call { + return &CliFlagRetriever_Segments_Call{Call: _e.mock.On("Segments")} +} + +func (_c *CliFlagRetriever_Segments_Call) Run(run func()) *CliFlagRetriever_Segments_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_Segments_Call) Return(value []string, isProvided bool) *CliFlagRetriever_Segments_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_Segments_Call) RunAndReturn(run func() ([]string, bool)) *CliFlagRetriever_Segments_Call { + _c.Call.Return(run) + return _c +} + +// Url provides a mock function with no fields +func (_m *CliFlagRetriever) Url() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Url") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_Url_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Url' +type CliFlagRetriever_Url_Call struct { + *mock.Call +} + +// Url is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) Url() *CliFlagRetriever_Url_Call { + return &CliFlagRetriever_Url_Call{Call: _e.mock.On("Url")} +} + +func (_c *CliFlagRetriever_Url_Call) Run(run func()) *CliFlagRetriever_Url_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_Url_Call) Return(value string, isProvided bool) *CliFlagRetriever_Url_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_Url_Call) RunAndReturn(run func() (string, bool)) *CliFlagRetriever_Url_Call { + _c.Call.Return(run) + return _c +} + +// Username provides a mock function with no fields +func (_m *CliFlagRetriever) Username() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Username") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// CliFlagRetriever_Username_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Username' +type CliFlagRetriever_Username_Call struct { + *mock.Call +} + +// Username is a helper method to define mock.On call +func (_e *CliFlagRetriever_Expecter) Username() *CliFlagRetriever_Username_Call { + return &CliFlagRetriever_Username_Call{Call: _e.mock.On("Username")} +} + +func (_c *CliFlagRetriever_Username_Call) Run(run func()) *CliFlagRetriever_Username_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *CliFlagRetriever_Username_Call) Return(value string, isProvided bool) *CliFlagRetriever_Username_Call { + _c.Call.Return(value, isProvided) + return _c +} + +func (_c *CliFlagRetriever_Username_Call) RunAndReturn(run func() (string, bool)) *CliFlagRetriever_Username_Call { + _c.Call.Return(run) + return _c +} + +// NewCliFlagRetriever creates a new instance of CliFlagRetriever. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewCliFlagRetriever(t interface { + mock.TestingT + Cleanup(func()) +}) *CliFlagRetriever { + mock := &CliFlagRetriever{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/mocks/EnvVarRetriever.go b/internal/mocks/EnvVarRetriever.go new file mode 100644 index 0000000..8900325 --- /dev/null +++ b/internal/mocks/EnvVarRetriever.go @@ -0,0 +1,644 @@ +// Code generated by mockery 2.53.2. DO NOT EDIT. + +package pilgrim_mock + +import ( + mock "github.com/stretchr/testify/mock" + pilgrim_conf "mvvasilev.dev/pilgrim/internal/pilgrim_conf" +) + +// EnvVarRetriever is an autogenerated mock type for the EnvVarRetriever type +type EnvVarRetriever struct { + mock.Mock +} + +type EnvVarRetriever_Expecter struct { + mock *mock.Mock +} + +func (_m *EnvVarRetriever) EXPECT() *EnvVarRetriever_Expecter { + return &EnvVarRetriever_Expecter{mock: &_m.Mock} +} + +// Args provides a mock function with no fields +func (_m *EnvVarRetriever) Args() (map[string]string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Args") + } + + var r0 map[string]string + var r1 bool + if rf, ok := ret.Get(0).(func() (map[string]string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() map[string]string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[string]string) + } + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// EnvVarRetriever_Args_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Args' +type EnvVarRetriever_Args_Call struct { + *mock.Call +} + +// Args is a helper method to define mock.On call +func (_e *EnvVarRetriever_Expecter) Args() *EnvVarRetriever_Args_Call { + return &EnvVarRetriever_Args_Call{Call: _e.mock.On("Args")} +} + +func (_c *EnvVarRetriever_Args_Call) Run(run func()) *EnvVarRetriever_Args_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *EnvVarRetriever_Args_Call) Return(value map[string]string, isDefined bool) *EnvVarRetriever_Args_Call { + _c.Call.Return(value, isDefined) + return _c +} + +func (_c *EnvVarRetriever_Args_Call) RunAndReturn(run func() (map[string]string, bool)) *EnvVarRetriever_Args_Call { + _c.Call.Return(run) + return _c +} + +// Directory provides a mock function with no fields +func (_m *EnvVarRetriever) Directory() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Directory") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// EnvVarRetriever_Directory_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Directory' +type EnvVarRetriever_Directory_Call struct { + *mock.Call +} + +// Directory is a helper method to define mock.On call +func (_e *EnvVarRetriever_Expecter) Directory() *EnvVarRetriever_Directory_Call { + return &EnvVarRetriever_Directory_Call{Call: _e.mock.On("Directory")} +} + +func (_c *EnvVarRetriever_Directory_Call) Run(run func()) *EnvVarRetriever_Directory_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *EnvVarRetriever_Directory_Call) Return(value string, isDefined bool) *EnvVarRetriever_Directory_Call { + _c.Call.Return(value, isDefined) + return _c +} + +func (_c *EnvVarRetriever_Directory_Call) RunAndReturn(run func() (string, bool)) *EnvVarRetriever_Directory_Call { + _c.Call.Return(run) + return _c +} + +// Driver provides a mock function with no fields +func (_m *EnvVarRetriever) Driver() (pilgrim_conf.DbDriver, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Driver") + } + + var r0 pilgrim_conf.DbDriver + var r1 bool + if rf, ok := ret.Get(0).(func() (pilgrim_conf.DbDriver, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() pilgrim_conf.DbDriver); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(pilgrim_conf.DbDriver) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// EnvVarRetriever_Driver_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Driver' +type EnvVarRetriever_Driver_Call struct { + *mock.Call +} + +// Driver is a helper method to define mock.On call +func (_e *EnvVarRetriever_Expecter) Driver() *EnvVarRetriever_Driver_Call { + return &EnvVarRetriever_Driver_Call{Call: _e.mock.On("Driver")} +} + +func (_c *EnvVarRetriever_Driver_Call) Run(run func()) *EnvVarRetriever_Driver_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *EnvVarRetriever_Driver_Call) Return(value pilgrim_conf.DbDriver, isDefined bool) *EnvVarRetriever_Driver_Call { + _c.Call.Return(value, isDefined) + return _c +} + +func (_c *EnvVarRetriever_Driver_Call) RunAndReturn(run func() (pilgrim_conf.DbDriver, bool)) *EnvVarRetriever_Driver_Call { + _c.Call.Return(run) + return _c +} + +// Host provides a mock function with no fields +func (_m *EnvVarRetriever) Host() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Host") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// EnvVarRetriever_Host_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Host' +type EnvVarRetriever_Host_Call struct { + *mock.Call +} + +// Host is a helper method to define mock.On call +func (_e *EnvVarRetriever_Expecter) Host() *EnvVarRetriever_Host_Call { + return &EnvVarRetriever_Host_Call{Call: _e.mock.On("Host")} +} + +func (_c *EnvVarRetriever_Host_Call) Run(run func()) *EnvVarRetriever_Host_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *EnvVarRetriever_Host_Call) Return(value string, isDefined bool) *EnvVarRetriever_Host_Call { + _c.Call.Return(value, isDefined) + return _c +} + +func (_c *EnvVarRetriever_Host_Call) RunAndReturn(run func() (string, bool)) *EnvVarRetriever_Host_Call { + _c.Call.Return(run) + return _c +} + +// MigrationTable provides a mock function with no fields +func (_m *EnvVarRetriever) MigrationTable() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for MigrationTable") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// EnvVarRetriever_MigrationTable_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MigrationTable' +type EnvVarRetriever_MigrationTable_Call struct { + *mock.Call +} + +// MigrationTable is a helper method to define mock.On call +func (_e *EnvVarRetriever_Expecter) MigrationTable() *EnvVarRetriever_MigrationTable_Call { + return &EnvVarRetriever_MigrationTable_Call{Call: _e.mock.On("MigrationTable")} +} + +func (_c *EnvVarRetriever_MigrationTable_Call) Run(run func()) *EnvVarRetriever_MigrationTable_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *EnvVarRetriever_MigrationTable_Call) Return(value string, isDefined bool) *EnvVarRetriever_MigrationTable_Call { + _c.Call.Return(value, isDefined) + return _c +} + +func (_c *EnvVarRetriever_MigrationTable_Call) RunAndReturn(run func() (string, bool)) *EnvVarRetriever_MigrationTable_Call { + _c.Call.Return(run) + return _c +} + +// MigrationTableSchema provides a mock function with no fields +func (_m *EnvVarRetriever) MigrationTableSchema() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for MigrationTableSchema") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// EnvVarRetriever_MigrationTableSchema_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MigrationTableSchema' +type EnvVarRetriever_MigrationTableSchema_Call struct { + *mock.Call +} + +// MigrationTableSchema is a helper method to define mock.On call +func (_e *EnvVarRetriever_Expecter) MigrationTableSchema() *EnvVarRetriever_MigrationTableSchema_Call { + return &EnvVarRetriever_MigrationTableSchema_Call{Call: _e.mock.On("MigrationTableSchema")} +} + +func (_c *EnvVarRetriever_MigrationTableSchema_Call) Run(run func()) *EnvVarRetriever_MigrationTableSchema_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *EnvVarRetriever_MigrationTableSchema_Call) Return(value string, isDefined bool) *EnvVarRetriever_MigrationTableSchema_Call { + _c.Call.Return(value, isDefined) + return _c +} + +func (_c *EnvVarRetriever_MigrationTableSchema_Call) RunAndReturn(run func() (string, bool)) *EnvVarRetriever_MigrationTableSchema_Call { + _c.Call.Return(run) + return _c +} + +// Password provides a mock function with no fields +func (_m *EnvVarRetriever) Password() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Password") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// EnvVarRetriever_Password_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Password' +type EnvVarRetriever_Password_Call struct { + *mock.Call +} + +// Password is a helper method to define mock.On call +func (_e *EnvVarRetriever_Expecter) Password() *EnvVarRetriever_Password_Call { + return &EnvVarRetriever_Password_Call{Call: _e.mock.On("Password")} +} + +func (_c *EnvVarRetriever_Password_Call) Run(run func()) *EnvVarRetriever_Password_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *EnvVarRetriever_Password_Call) Return(value string, isDefined bool) *EnvVarRetriever_Password_Call { + _c.Call.Return(value, isDefined) + return _c +} + +func (_c *EnvVarRetriever_Password_Call) RunAndReturn(run func() (string, bool)) *EnvVarRetriever_Password_Call { + _c.Call.Return(run) + return _c +} + +// Port provides a mock function with no fields +func (_m *EnvVarRetriever) Port() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Port") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// EnvVarRetriever_Port_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Port' +type EnvVarRetriever_Port_Call struct { + *mock.Call +} + +// Port is a helper method to define mock.On call +func (_e *EnvVarRetriever_Expecter) Port() *EnvVarRetriever_Port_Call { + return &EnvVarRetriever_Port_Call{Call: _e.mock.On("Port")} +} + +func (_c *EnvVarRetriever_Port_Call) Run(run func()) *EnvVarRetriever_Port_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *EnvVarRetriever_Port_Call) Return(value string, isDefined bool) *EnvVarRetriever_Port_Call { + _c.Call.Return(value, isDefined) + return _c +} + +func (_c *EnvVarRetriever_Port_Call) RunAndReturn(run func() (string, bool)) *EnvVarRetriever_Port_Call { + _c.Call.Return(run) + return _c +} + +// Segments provides a mock function with no fields +func (_m *EnvVarRetriever) Segments() ([]string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Segments") + } + + var r0 []string + var r1 bool + if rf, ok := ret.Get(0).(func() ([]string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// EnvVarRetriever_Segments_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Segments' +type EnvVarRetriever_Segments_Call struct { + *mock.Call +} + +// Segments is a helper method to define mock.On call +func (_e *EnvVarRetriever_Expecter) Segments() *EnvVarRetriever_Segments_Call { + return &EnvVarRetriever_Segments_Call{Call: _e.mock.On("Segments")} +} + +func (_c *EnvVarRetriever_Segments_Call) Run(run func()) *EnvVarRetriever_Segments_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *EnvVarRetriever_Segments_Call) Return(value []string, isDefined bool) *EnvVarRetriever_Segments_Call { + _c.Call.Return(value, isDefined) + return _c +} + +func (_c *EnvVarRetriever_Segments_Call) RunAndReturn(run func() ([]string, bool)) *EnvVarRetriever_Segments_Call { + _c.Call.Return(run) + return _c +} + +// Url provides a mock function with no fields +func (_m *EnvVarRetriever) Url() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Url") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// EnvVarRetriever_Url_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Url' +type EnvVarRetriever_Url_Call struct { + *mock.Call +} + +// Url is a helper method to define mock.On call +func (_e *EnvVarRetriever_Expecter) Url() *EnvVarRetriever_Url_Call { + return &EnvVarRetriever_Url_Call{Call: _e.mock.On("Url")} +} + +func (_c *EnvVarRetriever_Url_Call) Run(run func()) *EnvVarRetriever_Url_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *EnvVarRetriever_Url_Call) Return(value string, isDefined bool) *EnvVarRetriever_Url_Call { + _c.Call.Return(value, isDefined) + return _c +} + +func (_c *EnvVarRetriever_Url_Call) RunAndReturn(run func() (string, bool)) *EnvVarRetriever_Url_Call { + _c.Call.Return(run) + return _c +} + +// Username provides a mock function with no fields +func (_m *EnvVarRetriever) Username() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Username") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// EnvVarRetriever_Username_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Username' +type EnvVarRetriever_Username_Call struct { + *mock.Call +} + +// Username is a helper method to define mock.On call +func (_e *EnvVarRetriever_Expecter) Username() *EnvVarRetriever_Username_Call { + return &EnvVarRetriever_Username_Call{Call: _e.mock.On("Username")} +} + +func (_c *EnvVarRetriever_Username_Call) Run(run func()) *EnvVarRetriever_Username_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *EnvVarRetriever_Username_Call) Return(value string, isDefined bool) *EnvVarRetriever_Username_Call { + _c.Call.Return(value, isDefined) + return _c +} + +func (_c *EnvVarRetriever_Username_Call) RunAndReturn(run func() (string, bool)) *EnvVarRetriever_Username_Call { + _c.Call.Return(run) + return _c +} + +// NewEnvVarRetriever creates a new instance of EnvVarRetriever. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewEnvVarRetriever(t interface { + mock.TestingT + Cleanup(func()) +}) *EnvVarRetriever { + mock := &EnvVarRetriever{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/mocks/MigrationPhaseRetriever.go b/internal/mocks/MigrationPhaseRetriever.go new file mode 100644 index 0000000..9840f5c --- /dev/null +++ b/internal/mocks/MigrationPhaseRetriever.go @@ -0,0 +1,197 @@ +// Code generated by mockery 2.53.2. DO NOT EDIT. + +package pilgrim_mock + +import mock "github.com/stretchr/testify/mock" + +// MigrationPhaseRetriever is an autogenerated mock type for the MigrationPhaseRetriever type +type MigrationPhaseRetriever struct { + mock.Mock +} + +type MigrationPhaseRetriever_Expecter struct { + mock *mock.Mock +} + +func (_m *MigrationPhaseRetriever) EXPECT() *MigrationPhaseRetriever_Expecter { + return &MigrationPhaseRetriever_Expecter{mock: &_m.Mock} +} + +// IsDown provides a mock function with no fields +func (_m *MigrationPhaseRetriever) IsDown() (bool, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for IsDown") + } + + var r0 bool + var r1 bool + if rf, ok := ret.Get(0).(func() (bool, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// MigrationPhaseRetriever_IsDown_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsDown' +type MigrationPhaseRetriever_IsDown_Call struct { + *mock.Call +} + +// IsDown is a helper method to define mock.On call +func (_e *MigrationPhaseRetriever_Expecter) IsDown() *MigrationPhaseRetriever_IsDown_Call { + return &MigrationPhaseRetriever_IsDown_Call{Call: _e.mock.On("IsDown")} +} + +func (_c *MigrationPhaseRetriever_IsDown_Call) Run(run func()) *MigrationPhaseRetriever_IsDown_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MigrationPhaseRetriever_IsDown_Call) Return(isDown bool, isDownProvided bool) *MigrationPhaseRetriever_IsDown_Call { + _c.Call.Return(isDown, isDownProvided) + return _c +} + +func (_c *MigrationPhaseRetriever_IsDown_Call) RunAndReturn(run func() (bool, bool)) *MigrationPhaseRetriever_IsDown_Call { + _c.Call.Return(run) + return _c +} + +// IsUp provides a mock function with no fields +func (_m *MigrationPhaseRetriever) IsUp() (bool, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for IsUp") + } + + var r0 bool + var r1 bool + if rf, ok := ret.Get(0).(func() (bool, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// MigrationPhaseRetriever_IsUp_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsUp' +type MigrationPhaseRetriever_IsUp_Call struct { + *mock.Call +} + +// IsUp is a helper method to define mock.On call +func (_e *MigrationPhaseRetriever_Expecter) IsUp() *MigrationPhaseRetriever_IsUp_Call { + return &MigrationPhaseRetriever_IsUp_Call{Call: _e.mock.On("IsUp")} +} + +func (_c *MigrationPhaseRetriever_IsUp_Call) Run(run func()) *MigrationPhaseRetriever_IsUp_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MigrationPhaseRetriever_IsUp_Call) Return(isUp bool, isUpProvided bool) *MigrationPhaseRetriever_IsUp_Call { + _c.Call.Return(isUp, isUpProvided) + return _c +} + +func (_c *MigrationPhaseRetriever_IsUp_Call) RunAndReturn(run func() (bool, bool)) *MigrationPhaseRetriever_IsUp_Call { + _c.Call.Return(run) + return _c +} + +// Script provides a mock function with no fields +func (_m *MigrationPhaseRetriever) Script() (string, bool) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Script") + } + + var r0 string + var r1 bool + if rf, ok := ret.Get(0).(func() (string, bool)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() bool); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// MigrationPhaseRetriever_Script_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Script' +type MigrationPhaseRetriever_Script_Call struct { + *mock.Call +} + +// Script is a helper method to define mock.On call +func (_e *MigrationPhaseRetriever_Expecter) Script() *MigrationPhaseRetriever_Script_Call { + return &MigrationPhaseRetriever_Script_Call{Call: _e.mock.On("Script")} +} + +func (_c *MigrationPhaseRetriever_Script_Call) Run(run func()) *MigrationPhaseRetriever_Script_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MigrationPhaseRetriever_Script_Call) Return(script string, isScriptProvided bool) *MigrationPhaseRetriever_Script_Call { + _c.Call.Return(script, isScriptProvided) + return _c +} + +func (_c *MigrationPhaseRetriever_Script_Call) RunAndReturn(run func() (string, bool)) *MigrationPhaseRetriever_Script_Call { + _c.Call.Return(run) + return _c +} + +// NewMigrationPhaseRetriever creates a new instance of MigrationPhaseRetriever. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMigrationPhaseRetriever(t interface { + mock.TestingT + Cleanup(func()) +}) *MigrationPhaseRetriever { + mock := &MigrationPhaseRetriever{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/mocks/PilgrimConfigurationRetriever.go b/internal/mocks/PilgrimConfigurationRetriever.go new file mode 100644 index 0000000..b4ffb95 --- /dev/null +++ b/internal/mocks/PilgrimConfigurationRetriever.go @@ -0,0 +1,530 @@ +// Code generated by mockery 2.53.2. DO NOT EDIT. + +package pilgrim_mock + +import ( + mock "github.com/stretchr/testify/mock" + pilgrim_conf "mvvasilev.dev/pilgrim/internal/pilgrim_conf" +) + +// PilgrimConfigurationRetriever is an autogenerated mock type for the PilgrimConfigurationRetriever type +type PilgrimConfigurationRetriever struct { + mock.Mock +} + +type PilgrimConfigurationRetriever_Expecter struct { + mock *mock.Mock +} + +func (_m *PilgrimConfigurationRetriever) EXPECT() *PilgrimConfigurationRetriever_Expecter { + return &PilgrimConfigurationRetriever_Expecter{mock: &_m.Mock} +} + +// MigrationDirectory provides a mock function with no fields +func (_m *PilgrimConfigurationRetriever) MigrationDirectory() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for MigrationDirectory") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// PilgrimConfigurationRetriever_MigrationDirectory_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MigrationDirectory' +type PilgrimConfigurationRetriever_MigrationDirectory_Call struct { + *mock.Call +} + +// MigrationDirectory is a helper method to define mock.On call +func (_e *PilgrimConfigurationRetriever_Expecter) MigrationDirectory() *PilgrimConfigurationRetriever_MigrationDirectory_Call { + return &PilgrimConfigurationRetriever_MigrationDirectory_Call{Call: _e.mock.On("MigrationDirectory")} +} + +func (_c *PilgrimConfigurationRetriever_MigrationDirectory_Call) Run(run func()) *PilgrimConfigurationRetriever_MigrationDirectory_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *PilgrimConfigurationRetriever_MigrationDirectory_Call) Return(_a0 string) *PilgrimConfigurationRetriever_MigrationDirectory_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *PilgrimConfigurationRetriever_MigrationDirectory_Call) RunAndReturn(run func() string) *PilgrimConfigurationRetriever_MigrationDirectory_Call { + _c.Call.Return(run) + return _c +} + +// MigrationIsChecksumValidationEnabled provides a mock function with no fields +func (_m *PilgrimConfigurationRetriever) MigrationIsChecksumValidationEnabled() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for MigrationIsChecksumValidationEnabled") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// PilgrimConfigurationRetriever_MigrationIsChecksumValidationEnabled_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MigrationIsChecksumValidationEnabled' +type PilgrimConfigurationRetriever_MigrationIsChecksumValidationEnabled_Call struct { + *mock.Call +} + +// MigrationIsChecksumValidationEnabled is a helper method to define mock.On call +func (_e *PilgrimConfigurationRetriever_Expecter) MigrationIsChecksumValidationEnabled() *PilgrimConfigurationRetriever_MigrationIsChecksumValidationEnabled_Call { + return &PilgrimConfigurationRetriever_MigrationIsChecksumValidationEnabled_Call{Call: _e.mock.On("MigrationIsChecksumValidationEnabled")} +} + +func (_c *PilgrimConfigurationRetriever_MigrationIsChecksumValidationEnabled_Call) Run(run func()) *PilgrimConfigurationRetriever_MigrationIsChecksumValidationEnabled_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *PilgrimConfigurationRetriever_MigrationIsChecksumValidationEnabled_Call) Return(_a0 bool) *PilgrimConfigurationRetriever_MigrationIsChecksumValidationEnabled_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *PilgrimConfigurationRetriever_MigrationIsChecksumValidationEnabled_Call) RunAndReturn(run func() bool) *PilgrimConfigurationRetriever_MigrationIsChecksumValidationEnabled_Call { + _c.Call.Return(run) + return _c +} + +// MigrationPhase provides a mock function with no fields +func (_m *PilgrimConfigurationRetriever) MigrationPhase() pilgrim_conf.MigrationPhase { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for MigrationPhase") + } + + var r0 pilgrim_conf.MigrationPhase + if rf, ok := ret.Get(0).(func() pilgrim_conf.MigrationPhase); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(pilgrim_conf.MigrationPhase) + } + + return r0 +} + +// PilgrimConfigurationRetriever_MigrationPhase_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MigrationPhase' +type PilgrimConfigurationRetriever_MigrationPhase_Call struct { + *mock.Call +} + +// MigrationPhase is a helper method to define mock.On call +func (_e *PilgrimConfigurationRetriever_Expecter) MigrationPhase() *PilgrimConfigurationRetriever_MigrationPhase_Call { + return &PilgrimConfigurationRetriever_MigrationPhase_Call{Call: _e.mock.On("MigrationPhase")} +} + +func (_c *PilgrimConfigurationRetriever_MigrationPhase_Call) Run(run func()) *PilgrimConfigurationRetriever_MigrationPhase_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *PilgrimConfigurationRetriever_MigrationPhase_Call) Return(_a0 pilgrim_conf.MigrationPhase) *PilgrimConfigurationRetriever_MigrationPhase_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *PilgrimConfigurationRetriever_MigrationPhase_Call) RunAndReturn(run func() pilgrim_conf.MigrationPhase) *PilgrimConfigurationRetriever_MigrationPhase_Call { + _c.Call.Return(run) + return _c +} + +// MigrationSchema provides a mock function with no fields +func (_m *PilgrimConfigurationRetriever) MigrationSchema() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for MigrationSchema") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// PilgrimConfigurationRetriever_MigrationSchema_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MigrationSchema' +type PilgrimConfigurationRetriever_MigrationSchema_Call struct { + *mock.Call +} + +// MigrationSchema is a helper method to define mock.On call +func (_e *PilgrimConfigurationRetriever_Expecter) MigrationSchema() *PilgrimConfigurationRetriever_MigrationSchema_Call { + return &PilgrimConfigurationRetriever_MigrationSchema_Call{Call: _e.mock.On("MigrationSchema")} +} + +func (_c *PilgrimConfigurationRetriever_MigrationSchema_Call) Run(run func()) *PilgrimConfigurationRetriever_MigrationSchema_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *PilgrimConfigurationRetriever_MigrationSchema_Call) Return(_a0 string) *PilgrimConfigurationRetriever_MigrationSchema_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *PilgrimConfigurationRetriever_MigrationSchema_Call) RunAndReturn(run func() string) *PilgrimConfigurationRetriever_MigrationSchema_Call { + _c.Call.Return(run) + return _c +} + +// MigrationScript provides a mock function with no fields +func (_m *PilgrimConfigurationRetriever) MigrationScript() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for MigrationScript") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// PilgrimConfigurationRetriever_MigrationScript_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MigrationScript' +type PilgrimConfigurationRetriever_MigrationScript_Call struct { + *mock.Call +} + +// MigrationScript is a helper method to define mock.On call +func (_e *PilgrimConfigurationRetriever_Expecter) MigrationScript() *PilgrimConfigurationRetriever_MigrationScript_Call { + return &PilgrimConfigurationRetriever_MigrationScript_Call{Call: _e.mock.On("MigrationScript")} +} + +func (_c *PilgrimConfigurationRetriever_MigrationScript_Call) Run(run func()) *PilgrimConfigurationRetriever_MigrationScript_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *PilgrimConfigurationRetriever_MigrationScript_Call) Return(_a0 string) *PilgrimConfigurationRetriever_MigrationScript_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *PilgrimConfigurationRetriever_MigrationScript_Call) RunAndReturn(run func() string) *PilgrimConfigurationRetriever_MigrationScript_Call { + _c.Call.Return(run) + return _c +} + +// MigrationStrictOrdering provides a mock function with no fields +func (_m *PilgrimConfigurationRetriever) MigrationStrictOrdering() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for MigrationStrictOrdering") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// PilgrimConfigurationRetriever_MigrationStrictOrdering_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MigrationStrictOrdering' +type PilgrimConfigurationRetriever_MigrationStrictOrdering_Call struct { + *mock.Call +} + +// MigrationStrictOrdering is a helper method to define mock.On call +func (_e *PilgrimConfigurationRetriever_Expecter) MigrationStrictOrdering() *PilgrimConfigurationRetriever_MigrationStrictOrdering_Call { + return &PilgrimConfigurationRetriever_MigrationStrictOrdering_Call{Call: _e.mock.On("MigrationStrictOrdering")} +} + +func (_c *PilgrimConfigurationRetriever_MigrationStrictOrdering_Call) Run(run func()) *PilgrimConfigurationRetriever_MigrationStrictOrdering_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *PilgrimConfigurationRetriever_MigrationStrictOrdering_Call) Return(_a0 bool) *PilgrimConfigurationRetriever_MigrationStrictOrdering_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *PilgrimConfigurationRetriever_MigrationStrictOrdering_Call) RunAndReturn(run func() bool) *PilgrimConfigurationRetriever_MigrationStrictOrdering_Call { + _c.Call.Return(run) + return _c +} + +// MigrationTable provides a mock function with no fields +func (_m *PilgrimConfigurationRetriever) MigrationTable() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for MigrationTable") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// PilgrimConfigurationRetriever_MigrationTable_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MigrationTable' +type PilgrimConfigurationRetriever_MigrationTable_Call struct { + *mock.Call +} + +// MigrationTable is a helper method to define mock.On call +func (_e *PilgrimConfigurationRetriever_Expecter) MigrationTable() *PilgrimConfigurationRetriever_MigrationTable_Call { + return &PilgrimConfigurationRetriever_MigrationTable_Call{Call: _e.mock.On("MigrationTable")} +} + +func (_c *PilgrimConfigurationRetriever_MigrationTable_Call) Run(run func()) *PilgrimConfigurationRetriever_MigrationTable_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *PilgrimConfigurationRetriever_MigrationTable_Call) Return(_a0 string) *PilgrimConfigurationRetriever_MigrationTable_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *PilgrimConfigurationRetriever_MigrationTable_Call) RunAndReturn(run func() string) *PilgrimConfigurationRetriever_MigrationTable_Call { + _c.Call.Return(run) + return _c +} + +// UrlParts provides a mock function with no fields +func (_m *PilgrimConfigurationRetriever) UrlParts() pilgrim_conf.UrlParts { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for UrlParts") + } + + var r0 pilgrim_conf.UrlParts + if rf, ok := ret.Get(0).(func() pilgrim_conf.UrlParts); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(pilgrim_conf.UrlParts) + } + + return r0 +} + +// PilgrimConfigurationRetriever_UrlParts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UrlParts' +type PilgrimConfigurationRetriever_UrlParts_Call struct { + *mock.Call +} + +// UrlParts is a helper method to define mock.On call +func (_e *PilgrimConfigurationRetriever_Expecter) UrlParts() *PilgrimConfigurationRetriever_UrlParts_Call { + return &PilgrimConfigurationRetriever_UrlParts_Call{Call: _e.mock.On("UrlParts")} +} + +func (_c *PilgrimConfigurationRetriever_UrlParts_Call) Run(run func()) *PilgrimConfigurationRetriever_UrlParts_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *PilgrimConfigurationRetriever_UrlParts_Call) Return(_a0 pilgrim_conf.UrlParts) *PilgrimConfigurationRetriever_UrlParts_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *PilgrimConfigurationRetriever_UrlParts_Call) RunAndReturn(run func() pilgrim_conf.UrlParts) *PilgrimConfigurationRetriever_UrlParts_Call { + _c.Call.Return(run) + return _c +} + +// ValidateChecksums provides a mock function with no fields +func (_m *PilgrimConfigurationRetriever) ValidateChecksums() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for ValidateChecksums") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// PilgrimConfigurationRetriever_ValidateChecksums_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ValidateChecksums' +type PilgrimConfigurationRetriever_ValidateChecksums_Call struct { + *mock.Call +} + +// ValidateChecksums is a helper method to define mock.On call +func (_e *PilgrimConfigurationRetriever_Expecter) ValidateChecksums() *PilgrimConfigurationRetriever_ValidateChecksums_Call { + return &PilgrimConfigurationRetriever_ValidateChecksums_Call{Call: _e.mock.On("ValidateChecksums")} +} + +func (_c *PilgrimConfigurationRetriever_ValidateChecksums_Call) Run(run func()) *PilgrimConfigurationRetriever_ValidateChecksums_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *PilgrimConfigurationRetriever_ValidateChecksums_Call) Return(_a0 bool) *PilgrimConfigurationRetriever_ValidateChecksums_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *PilgrimConfigurationRetriever_ValidateChecksums_Call) RunAndReturn(run func() bool) *PilgrimConfigurationRetriever_ValidateChecksums_Call { + _c.Call.Return(run) + return _c +} + +// ValidateLatest provides a mock function with no fields +func (_m *PilgrimConfigurationRetriever) ValidateLatest() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for ValidateLatest") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// PilgrimConfigurationRetriever_ValidateLatest_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ValidateLatest' +type PilgrimConfigurationRetriever_ValidateLatest_Call struct { + *mock.Call +} + +// ValidateLatest is a helper method to define mock.On call +func (_e *PilgrimConfigurationRetriever_Expecter) ValidateLatest() *PilgrimConfigurationRetriever_ValidateLatest_Call { + return &PilgrimConfigurationRetriever_ValidateLatest_Call{Call: _e.mock.On("ValidateLatest")} +} + +func (_c *PilgrimConfigurationRetriever_ValidateLatest_Call) Run(run func()) *PilgrimConfigurationRetriever_ValidateLatest_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *PilgrimConfigurationRetriever_ValidateLatest_Call) Return(_a0 bool) *PilgrimConfigurationRetriever_ValidateLatest_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *PilgrimConfigurationRetriever_ValidateLatest_Call) RunAndReturn(run func() bool) *PilgrimConfigurationRetriever_ValidateLatest_Call { + _c.Call.Return(run) + return _c +} + +// ValidateMigrationOrder provides a mock function with no fields +func (_m *PilgrimConfigurationRetriever) ValidateMigrationOrder() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for ValidateMigrationOrder") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// PilgrimConfigurationRetriever_ValidateMigrationOrder_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ValidateMigrationOrder' +type PilgrimConfigurationRetriever_ValidateMigrationOrder_Call struct { + *mock.Call +} + +// ValidateMigrationOrder is a helper method to define mock.On call +func (_e *PilgrimConfigurationRetriever_Expecter) ValidateMigrationOrder() *PilgrimConfigurationRetriever_ValidateMigrationOrder_Call { + return &PilgrimConfigurationRetriever_ValidateMigrationOrder_Call{Call: _e.mock.On("ValidateMigrationOrder")} +} + +func (_c *PilgrimConfigurationRetriever_ValidateMigrationOrder_Call) Run(run func()) *PilgrimConfigurationRetriever_ValidateMigrationOrder_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *PilgrimConfigurationRetriever_ValidateMigrationOrder_Call) Return(_a0 bool) *PilgrimConfigurationRetriever_ValidateMigrationOrder_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *PilgrimConfigurationRetriever_ValidateMigrationOrder_Call) RunAndReturn(run func() bool) *PilgrimConfigurationRetriever_ValidateMigrationOrder_Call { + _c.Call.Return(run) + return _c +} + +// NewPilgrimConfigurationRetriever creates a new instance of PilgrimConfigurationRetriever. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewPilgrimConfigurationRetriever(t interface { + mock.TestingT + Cleanup(func()) +}) *PilgrimConfigurationRetriever { + mock := &PilgrimConfigurationRetriever{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pilgrim/cli.go b/internal/pilgrim_conf/cli.go similarity index 99% rename from pilgrim/cli.go rename to internal/pilgrim_conf/cli.go index 567feee..aec34da 100644 --- a/pilgrim/cli.go +++ b/internal/pilgrim_conf/cli.go @@ -1,4 +1,4 @@ -package pilgrim +package pilgrim_conf import ( "flag" diff --git a/pilgrim/context.go b/internal/pilgrim_conf/context.go similarity index 98% rename from pilgrim/context.go rename to internal/pilgrim_conf/context.go index d26db8a..0dd80f6 100644 --- a/pilgrim/context.go +++ b/internal/pilgrim_conf/context.go @@ -1,4 +1,4 @@ -package pilgrim +package pilgrim_conf import ( "log" @@ -102,7 +102,7 @@ func NewPilgrimContext(cli CliFlagRetriever, env EnvVarRetriever) *pilgrimContex log.Fatalln(err) } - migrationPhase, migrationScript, err := determineMigrationPhaseAndScript(cli) + migrationPhase, migrationScript, _ := determineMigrationPhaseAndScript(cli) migrationDirectory := PickFirstAvailable(cli.Directory, env.Directory, func() (string, bool) { return DefaultMigrationDirectory, true }) migrationSchema := PickFirstAvailable(cli.MigrationTableSchema, env.MigrationTableSchema, pickFirstDefault(EmptyString)) // Default depends on driver, set empty for now diff --git a/pilgrim/env.go b/internal/pilgrim_conf/env.go similarity index 99% rename from pilgrim/env.go rename to internal/pilgrim_conf/env.go index fe2edf5..a3ffc70 100644 --- a/pilgrim/env.go +++ b/internal/pilgrim_conf/env.go @@ -1,4 +1,4 @@ -package pilgrim +package pilgrim_conf import "os" diff --git a/pilgrim/error.go b/internal/pilgrim_conf/error.go similarity index 92% rename from pilgrim/error.go rename to internal/pilgrim_conf/error.go index 41fb18a..5576fd4 100644 --- a/pilgrim/error.go +++ b/internal/pilgrim_conf/error.go @@ -1,4 +1,4 @@ -package pilgrim +package pilgrim_conf type pilgrimValidationError struct { validationError string diff --git a/pilgrim/url_parts.go b/internal/pilgrim_conf/url_parts.go similarity index 99% rename from pilgrim/url_parts.go rename to internal/pilgrim_conf/url_parts.go index eacfd13..e2a00ad 100644 --- a/pilgrim/url_parts.go +++ b/internal/pilgrim_conf/url_parts.go @@ -1,4 +1,4 @@ -package pilgrim +package pilgrim_conf import ( "fmt" diff --git a/internal/pilgrim_conf_test/cli_test.go b/internal/pilgrim_conf_test/cli_test.go new file mode 100644 index 0000000..66a6d5d --- /dev/null +++ b/internal/pilgrim_conf_test/cli_test.go @@ -0,0 +1,209 @@ +package pilgrim_conf_test + +import ( + "flag" + "fmt" + "testing" + + "github.com/stretchr/testify/assert" + "mvvasilev.dev/pilgrim/internal/pilgrim_conf" +) + +func Test_CliContext_Url(t *testing.T) { + test_cliValue( + t, + func(cli pilgrim_conf.CliFlagRetriever) (string, bool) { return cli.Url() }, + pilgrim_conf.Flag_Url, + "driver://localhost:3306", + ) +} + +func Test_CliContext_Driver(t *testing.T) { + test_cliValue( + t, + func(cli pilgrim_conf.CliFlagRetriever) (pilgrim_conf.DbDriver, bool) { return cli.Driver() }, + pilgrim_conf.Flag_Driver, + "driver", + ) +} + +func Test_CliContext_Username(t *testing.T) { + test_cliValue( + t, + func(cli pilgrim_conf.CliFlagRetriever) (string, bool) { return cli.Username() }, + pilgrim_conf.Flag_Username, + "username", + ) +} + +func Test_CliContext_Password(t *testing.T) { + test_cliValue( + t, + func(cli pilgrim_conf.CliFlagRetriever) (string, bool) { return cli.Password() }, + pilgrim_conf.Flag_Password, + "password", + ) +} + +func Test_CliContext_Host(t *testing.T) { + test_cliValue( + t, + func(cli pilgrim_conf.CliFlagRetriever) (string, bool) { return cli.Host() }, + pilgrim_conf.Flag_Host, + "localhost", + ) +} + +func Test_CliContext_Port(t *testing.T) { + test_cliValue( + t, + func(cli pilgrim_conf.CliFlagRetriever) (string, bool) { return cli.Port() }, + pilgrim_conf.Flag_Port, + "3306", + ) +} + +func Test_CliContext_Segments(t *testing.T) { + expectedValue := []string{ + "segment1", "segment2", "segment3", + } + + flag.Set(pilgrim_conf.Flag_Segments, "segment1/segment2/segment3") + + value, _ := pilgrim_conf.CliContext().Segments() + + assert.Equal(t, expectedValue, value) +} + +func Test_CliContext_Args(t *testing.T) { + expectedValue := map[string]string{ + "arg1": "val1", + "arg2": "val2", + "arg3": "val3", + } + + flag.Set(pilgrim_conf.Flag_Args, "arg1=val1&arg2=val2&arg3=val3") + + value, _ := pilgrim_conf.CliContext().Args() + + assert.Equal(t, expectedValue, value) +} + +func Test_CliContext_Directory(t *testing.T) { + test_cliValue( + t, + func(cli pilgrim_conf.CliFlagRetriever) (string, bool) { return cli.Directory() }, + pilgrim_conf.Flag_Directory, + "./custom-migrations", + ) +} + +func Test_CliContext_Script(t *testing.T) { + test_cliValue( + t, + func(cli pilgrim_conf.CliFlagRetriever) (string, bool) { return cli.Script() }, + pilgrim_conf.Flag_Script, + "2024-10-13/1_SomeScript.sql", + ) +} + +func Test_CliContext_MigrationTable(t *testing.T) { + test_cliValue( + t, + func(cli pilgrim_conf.CliFlagRetriever) (string, bool) { return cli.MigrationTable() }, + pilgrim_conf.Flag_Table, + "CustomMigrationsTable", + ) +} + +func Test_CliContext_MigrationTableSchema(t *testing.T) { + test_cliValue( + t, + func(cli pilgrim_conf.CliFlagRetriever) (string, bool) { + return pilgrim_conf.CliContext().MigrationTableSchema() + }, + pilgrim_conf.Flag_Schema, + "public", + ) +} + +func Test_CliContext_Up(t *testing.T) { + test_cliValue( + t, + func(cli pilgrim_conf.CliFlagRetriever) (bool, bool) { return cli.IsUp() }, + pilgrim_conf.Flag_Up, + true, + ) +} + +func Test_CliContext_Down(t *testing.T) { + test_cliValue( + t, + func(cli pilgrim_conf.CliFlagRetriever) (bool, bool) { return cli.IsDown() }, + pilgrim_conf.Flag_Down, + true, + ) +} +func Test_CliContext_StrictOrdering(t *testing.T) { + test_cliValue( + t, + func(cli pilgrim_conf.CliFlagRetriever) (bool, bool) { + return pilgrim_conf.CliContext().IsStrictOrderingEnabled() + }, + pilgrim_conf.Flag_StrictOrdering, + true, + ) +} + +func Test_CliContext_DisableChecksumValidation(t *testing.T) { + expectedValue := false + + flag.Set(pilgrim_conf.Flag_DisableChecksumValidation, "true") + + value, _ := pilgrim_conf.CliContext().IsChecksumValidationEnabled() + + assert.Equal(t, expectedValue, value) +} + +func Test_CliContext_ValidateChecksums(t *testing.T) { + test_cliValue( + t, + func(cli pilgrim_conf.CliFlagRetriever) (bool, bool) { + return cli.IsValidatingChecksums() + }, + pilgrim_conf.Flag_ValidateChecksums, + true, + ) +} + +func Test_CliContext_ValidateMigrationOrder(t *testing.T) { + test_cliValue( + t, + func(cli pilgrim_conf.CliFlagRetriever) (bool, bool) { + return cli.IsValidatingMigrationOrder() + }, + pilgrim_conf.Flag_ValidateMigrationOrder, + true, + ) +} + +func Test_CliContext_ValidateLatest(t *testing.T) { + test_cliValue( + t, + func(cli pilgrim_conf.CliFlagRetriever) (bool, bool) { return cli.IsValidatingLatest() }, + pilgrim_conf.Flag_ValidateLatest, + true, + ) +} + +func test_cliValue[T string | pilgrim_conf.DbDriver | bool](t *testing.T, cliVal func(cli pilgrim_conf.CliFlagRetriever) (value T, isProvided bool), flagName string, expectedVal T) { + cli := pilgrim_conf.CliContext() + + flag.Set(flagName, fmt.Sprintf("%v", expectedVal)) + + cli.ParseFlags() + + value, _ := cliVal(cli) + + assert.Equal(t, expectedVal, value) +} diff --git a/internal/pilgrim_conf_test/context_test.go b/internal/pilgrim_conf_test/context_test.go new file mode 100644 index 0000000..7b3c306 --- /dev/null +++ b/internal/pilgrim_conf_test/context_test.go @@ -0,0 +1,149 @@ +package pilgrim_conf_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + pilgrim_mock "mvvasilev.dev/pilgrim/internal/mocks" + "mvvasilev.dev/pilgrim/internal/pilgrim_conf" +) + +const CliUrlValue = "postgres://cli_host:5432/cli_segment1/cli_segment2?cli_arg1=cli_val1&cli_arg2=cli_val2" +const CliDriverValue = pilgrim_conf.DbDriver_Postgres + +func runTest( + setupMocks func( + env *pilgrim_mock.EnvVarRetriever, + cli *pilgrim_mock.CliFlagRetriever, + ), + test func( + env *pilgrim_mock.EnvVarRetriever, + cli *pilgrim_mock.CliFlagRetriever, + ), +) { + env, cli := new(pilgrim_mock.EnvVarRetriever), new(pilgrim_mock.CliFlagRetriever) + + setupMocks(env, cli) + + env.EXPECT().Url().Return("", false) + env.EXPECT().Driver().Return(pilgrim_conf.DbDriver_Postgres, false) + env.EXPECT().Username().Return("", false) + env.EXPECT().Password().Return("", false) + env.EXPECT().Host().Return("", false) + env.EXPECT().Port().Return("", false) + env.EXPECT().Segments().Return([]string{}, false) + env.EXPECT().Args().Return(map[string]string{}, false) + env.EXPECT().Directory().Return("", false) + env.EXPECT().MigrationTable().Return("", false) + env.EXPECT().MigrationTableSchema().Return("", false) + + cli.EXPECT().Url().Return("", false) + cli.EXPECT().Driver().Return(pilgrim_conf.DbDriver_Postgres, false) + cli.EXPECT().Username().Return("", false) + cli.EXPECT().Password().Return("", false) + cli.EXPECT().Host().Return("", false) + cli.EXPECT().Port().Return("", false) + cli.EXPECT().Segments().Return([]string{}, false) + cli.EXPECT().Args().Return(map[string]string{}, false) + cli.EXPECT().Directory().Return("", false) + cli.EXPECT().IsUp().Return(false, false) + cli.EXPECT().IsDown().Return(false, false) + cli.EXPECT().Script().Return("", false) + cli.EXPECT().MigrationTable().Return("", false) + cli.EXPECT().MigrationTableSchema().Return("", false) + cli.EXPECT().IsChecksumValidationEnabled().Return(false, false) + cli.EXPECT().IsStrictOrderingEnabled().Return(false, false) + cli.EXPECT().IsValidatingMigrationOrder().Return(false, false) + cli.EXPECT().IsValidatingLatest().Return(false, false) + cli.EXPECT().IsValidatingChecksums().Return(false, false) + + test(env, cli) +} + +func Test_PilgrimContext_CliDriverOverridesCliUrlDriver(t *testing.T) { + runTest( + func(env *pilgrim_mock.EnvVarRetriever, cli *pilgrim_mock.CliFlagRetriever) { + env.EXPECT().Driver().Return(pilgrim_conf.DbDriver_MSSQL, true) + cli.EXPECT().Driver().Return(pilgrim_conf.DbDriver_MySQL, true) // This should be of highest priority + cli.EXPECT().Url().Return("postgres://cli_host:5432/cli_segment1/cli_segment2?cli_arg1=cli_val1&cli_arg2=cli_val2", true) + }, + func(env *pilgrim_mock.EnvVarRetriever, cli *pilgrim_mock.CliFlagRetriever) { + ctx := pilgrim_conf.NewPilgrimContext(cli, env) + + assert.Equal(t, pilgrim_conf.DbDriver_MySQL, ctx.UrlParts().Driver) + }, + ) +} + +// func Test_PilgrimContext_EnvDriverOverridesEnvUrlDriver(t *testing.T) { +// context, _, _ := createPilgrimContextWithDependencies( +// map[string]string{}, +// map[string]string{ +// EnvVarKey_Url: "mariadb://env_host:3306/env_segment1/env_segment2?env_arg1=env_val1&env_arg2=env_val2", +// EnvVarKey_Driver: "postgres", +// }, +// ) + +// assert.Equal(t, DbDriver_Postgres, context.UrlParts().Driver) +// } + +// func Test_PilgrimContext_CliUrlDriverOverridesEnvDriver(t *testing.T) { +// context, _, _ := createPilgrimContextWithDependencies( +// map[string]string{ +// Flag_Url: CliUrlValue, +// }, +// map[string]string{ +// EnvVarKey_Driver: "mariadb", +// }, +// ) + +// assert.Equal(t, CliDriverValue, context.UrlParts().Driver) +// } + +// func Test_PilgrimContext_CliDriverOverridesEnvDriver(t *testing.T) { +// context, _, _ := createPilgrimContextWithDependencies( +// map[string]string{ +// Flag_Driver: string(CliDriverValue), +// }, +// map[string]string{ +// EnvVarKey_Driver: "mariadb", +// }, +// ) + +// assert.Equal(t, CliDriverValue, context.UrlParts().Driver) +// } + +// func Test_PilgrimContext_EnvDriverIsUsedIfNoCliDriverProvided(t *testing.T) { +// context, _, _ := createPilgrimContextWithDependencies( +// map[string]string{}, +// map[string]string{ +// EnvVarKey_Driver: "mariadb", +// }, +// ) + +// assert.Equal(t, DbDriver_MariaDB, context.UrlParts().Driver) +// } + +// func Test_PilgrimContext_EnvUrlDriverIsUsedIfNoCliDriverProvided(t *testing.T) { +// context, _, _ := createPilgrimContextWithDependencies( +// map[string]string{}, +// map[string]string{ +// EnvVarKey_Url: "mariadb://env_host:3306/env_segment1/env_segment2?env_arg1=env_val1&env_arg2=env_val2", +// }, +// ) + +// assert.Equal(t, DbDriver_MariaDB, context.UrlParts().Driver) +// } + +// func Test_PilgrimContext_EnvUrlDriverIsNotUsedIfNoCliDriverOverrideProvided(t *testing.T) { +// context, _, _ := createPilgrimContextWithDependencies( +// map[string]string{ +// Flag_Driver: "postgres", +// }, +// map[string]string{ +// EnvVarKey_Url: "mariadb://env_host:3306/env_segment1/env_segment2?env_arg1=env_val1&env_arg2=env_val2", +// }, +// ) + +// assert.Equal(t, DbDriver_Postgres, context.UrlParts().Driver) +// } diff --git a/pilgrim/test/env_test.go b/internal/pilgrim_conf_test/env_test.go similarity index 55% rename from pilgrim/test/env_test.go rename to internal/pilgrim_conf_test/env_test.go index bb69bdc..a1e0a94 100644 --- a/pilgrim/test/env_test.go +++ b/internal/pilgrim_conf_test/env_test.go @@ -1,11 +1,11 @@ -package pilgrim_test +package pilgrim_conf_test import ( "os" "testing" "github.com/stretchr/testify/assert" - "mvvasilev.dev/pilgrim/pilgrim" + pilgrim_conf "mvvasilev.dev/pilgrim/internal/pilgrim_conf" ) func test_envVarContext_StringValue( @@ -25,18 +25,18 @@ func test_envVarContext_StringValue( func Test_envVarContext_Url(t *testing.T) { test_envVarContext_StringValue( t, - pilgrim.EnvVarKey_Url, - func() (string, bool) { return pilgrim.NewEnvVarContext().Url() }, + pilgrim_conf.EnvVarKey_Url, + func() (string, bool) { return pilgrim_conf.NewEnvVarContext().Url() }, "driver://user:pass@host:port/segment1/segment2?arg1=val1&arg2=val2", ) } func Test_envVarContext_Driver(t *testing.T) { - expectedVal := pilgrim.DbDriver_MariaDB + expectedVal := pilgrim_conf.DbDriver_MariaDB - os.Setenv(pilgrim.EnvVarKey_Driver, string(pilgrim.DbDriver_MariaDB)) + os.Setenv(pilgrim_conf.EnvVarKey_Driver, string(pilgrim_conf.DbDriver_MariaDB)) - val, isDefined := pilgrim.NewEnvVarContext().Driver() + val, isDefined := pilgrim_conf.NewEnvVarContext().Driver() assert.True(t, isDefined) assert.Equal(t, expectedVal, val) @@ -45,8 +45,8 @@ func Test_envVarContext_Driver(t *testing.T) { func Test_envVarContext_Username(t *testing.T) { test_envVarContext_StringValue( t, - pilgrim.EnvVarKey_Username, - func() (string, bool) { return pilgrim.NewEnvVarContext().Username() }, + pilgrim_conf.EnvVarKey_Username, + func() (string, bool) { return pilgrim_conf.NewEnvVarContext().Username() }, "username", ) } @@ -54,8 +54,8 @@ func Test_envVarContext_Username(t *testing.T) { func Test_envVarContext_Password(t *testing.T) { test_envVarContext_StringValue( t, - pilgrim.EnvVarKey_Password, - func() (string, bool) { return pilgrim.NewEnvVarContext().Password() }, + pilgrim_conf.EnvVarKey_Password, + func() (string, bool) { return pilgrim_conf.NewEnvVarContext().Password() }, "password", ) } @@ -63,8 +63,8 @@ func Test_envVarContext_Password(t *testing.T) { func Test_envVarContext_Host(t *testing.T) { test_envVarContext_StringValue( t, - pilgrim.EnvVarKey_Host, - func() (string, bool) { return pilgrim.NewEnvVarContext().Host() }, + pilgrim_conf.EnvVarKey_Host, + func() (string, bool) { return pilgrim_conf.NewEnvVarContext().Host() }, "localhost", ) } @@ -72,8 +72,8 @@ func Test_envVarContext_Host(t *testing.T) { func Test_envVarContext_Port(t *testing.T) { test_envVarContext_StringValue( t, - pilgrim.EnvVarKey_Port, - func() (string, bool) { return pilgrim.NewEnvVarContext().Port() }, + pilgrim_conf.EnvVarKey_Port, + func() (string, bool) { return pilgrim_conf.NewEnvVarContext().Port() }, "3306", ) } @@ -81,8 +81,8 @@ func Test_envVarContext_Port(t *testing.T) { func Test_envVarContext_Directory(t *testing.T) { test_envVarContext_StringValue( t, - pilgrim.EnvVarKey_Directory, - func() (string, bool) { return pilgrim.NewEnvVarContext().Directory() }, + pilgrim_conf.EnvVarKey_Directory, + func() (string, bool) { return pilgrim_conf.NewEnvVarContext().Directory() }, "./custom-directory/migrations", ) } @@ -90,8 +90,8 @@ func Test_envVarContext_Directory(t *testing.T) { func Test_envVarContext_MigrationTable(t *testing.T) { test_envVarContext_StringValue( t, - pilgrim.EnvVarKey_Table, - func() (string, bool) { return pilgrim.NewEnvVarContext().MigrationTable() }, + pilgrim_conf.EnvVarKey_Table, + func() (string, bool) { return pilgrim_conf.NewEnvVarContext().MigrationTable() }, "pilgrim_migrations_custom_table", ) } @@ -99,8 +99,8 @@ func Test_envVarContext_MigrationTable(t *testing.T) { func Test_envVarContext_MigrationTableSchema(t *testing.T) { test_envVarContext_StringValue( t, - pilgrim.EnvVarKey_Schema, - func() (string, bool) { return pilgrim.NewEnvVarContext().MigrationTableSchema() }, + pilgrim_conf.EnvVarKey_Schema, + func() (string, bool) { return pilgrim_conf.NewEnvVarContext().MigrationTableSchema() }, "public", ) } @@ -108,9 +108,9 @@ func Test_envVarContext_MigrationTableSchema(t *testing.T) { func Test_envVarContext_Segments(t *testing.T) { expectedVal := []string{"segment1", "segment2", "segment3"} - os.Setenv(pilgrim.EnvVarKey_Segments, "segment1/segment2/segment3") + os.Setenv(pilgrim_conf.EnvVarKey_Segments, "segment1/segment2/segment3") - val, isDefined := pilgrim.NewEnvVarContext().Segments() + val, isDefined := pilgrim_conf.NewEnvVarContext().Segments() assert.True(t, isDefined) assert.Equal(t, expectedVal, val) @@ -123,9 +123,9 @@ func Test_envVarContext_Args(t *testing.T) { "arg3": "val3", } - os.Setenv(pilgrim.EnvVarKey_Arguments, "arg1=val1&arg2=val2&arg3=val3") + os.Setenv(pilgrim_conf.EnvVarKey_Arguments, "arg1=val1&arg2=val2&arg3=val3") - val, isDefined := pilgrim.NewEnvVarContext().Args() + val, isDefined := pilgrim_conf.NewEnvVarContext().Args() assert.True(t, isDefined) assert.Equal(t, expectedVal, val) diff --git a/pilgrim/test/url_parts_test.go b/internal/pilgrim_conf_test/url_parts_test.go similarity index 72% rename from pilgrim/test/url_parts_test.go rename to internal/pilgrim_conf_test/url_parts_test.go index 997c834..4088dae 100644 --- a/pilgrim/test/url_parts_test.go +++ b/internal/pilgrim_conf_test/url_parts_test.go @@ -1,10 +1,10 @@ -package pilgrim_test +package pilgrim_conf_test import ( "testing" "github.com/stretchr/testify/assert" - "mvvasilev.dev/pilgrim/pilgrim" + "mvvasilev.dev/pilgrim/internal/pilgrim_conf" ) func Test_ParseDatabaseUrl(t *testing.T) { @@ -15,14 +15,14 @@ func Test_ParseDatabaseUrl(t *testing.T) { tests := []struct { name string args args - want pilgrim.UrlParts + want pilgrim_conf.UrlParts }{ { name: "parses_url_correctly", args: args{ cliUrl: "driver://user:pass@localhost:9999/segment1/segment2?arg1=val1&arg2=val2", }, - want: pilgrim.UrlParts{ + want: pilgrim_conf.UrlParts{ Driver: "driver", Username: "user", Password: "pass", @@ -42,7 +42,7 @@ func Test_ParseDatabaseUrl(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := pilgrim.ParseDatabaseUrl(tt.args.cliUrl); !assert.ObjectsAreEqual(got, tt.want) { + if got := pilgrim_conf.ParseDatabaseUrl(tt.args.cliUrl); !assert.ObjectsAreEqual(got, tt.want) { t.Errorf("ParseDatabaseUrl() = %v, want %v", got, tt.want) } }) @@ -50,7 +50,7 @@ func Test_ParseDatabaseUrl(t *testing.T) { } func Test_UrlParts_Validate_ValidUrl(t *testing.T) { - urlParts := pilgrim.ParseDatabaseUrl("mssql://user:pass@localhost:9999/segment1/segment2?arg1=val1&arg2=val2") + urlParts := pilgrim_conf.ParseDatabaseUrl("mssql://user:pass@localhost:9999/segment1/segment2?arg1=val1&arg2=val2") isValid, err := urlParts.Validate() assert.True(t, isValid, "Valid DatabaseUrl returned as invalid") @@ -58,7 +58,7 @@ func Test_UrlParts_Validate_ValidUrl(t *testing.T) { } func Test_UrlParts_Validate_InvalidUrl(t *testing.T) { - urlParts := pilgrim.ParseDatabaseUrl("invalid-driver://user:pass@localhost:9999/segment1/segment2?arg1=val1&arg2=val2") + urlParts := pilgrim_conf.ParseDatabaseUrl("invalid-driver://user:pass@localhost:9999/segment1/segment2?arg1=val1&arg2=val2") isValid, err := urlParts.Validate() assert.True(t, !isValid, "Invalid DatabaseUrl returned as valid") diff --git a/main.go b/main.go deleted file mode 100644 index a513851..0000000 --- a/main.go +++ /dev/null @@ -1,16 +0,0 @@ -package main - -import ( - "log" - - "mvvasilev.dev/pilgrim/pilgrim" -) - -func main() { - pilgrimContext := pilgrim.NewPilgrimContext( - pilgrim.CliContext(), - pilgrim.NewEnvVarContext(), - ) - - log.Println(pilgrimContext) -} diff --git a/pilgrim.go b/pilgrim.go new file mode 100644 index 0000000..f4cfba2 --- /dev/null +++ b/pilgrim.go @@ -0,0 +1,16 @@ +package pilgrim + +import ( + "log" + + "mvvasilev.dev/pilgrim/internal/pilgrim_conf" +) + +func main() { + pilgrimContext := pilgrim_conf.NewPilgrimContext( + pilgrim_conf.CliContext(), + pilgrim_conf.NewEnvVarContext(), + ) + + log.Println(pilgrimContext) +} diff --git a/pilgrim/test/cli_test.go b/pilgrim/test/cli_test.go deleted file mode 100644 index cf3fde6..0000000 --- a/pilgrim/test/cli_test.go +++ /dev/null @@ -1,209 +0,0 @@ -package pilgrim_test - -import ( - "flag" - "fmt" - "testing" - - "github.com/stretchr/testify/assert" - "mvvasilev.dev/pilgrim/pilgrim" -) - -func Test_CliContext_Url(t *testing.T) { - test_cliValue( - t, - func(cli pilgrim.CliFlagRetriever) (string, bool) { return cli.Url() }, - pilgrim.Flag_Url, - "driver://localhost:3306", - ) -} - -func Test_CliContext_Driver(t *testing.T) { - test_cliValue( - t, - func(cli pilgrim.CliFlagRetriever) (pilgrim.DbDriver, bool) { return cli.Driver() }, - pilgrim.Flag_Driver, - "driver", - ) -} - -func Test_CliContext_Username(t *testing.T) { - test_cliValue( - t, - func(cli pilgrim.CliFlagRetriever) (string, bool) { return cli.Username() }, - pilgrim.Flag_Username, - "username", - ) -} - -func Test_CliContext_Password(t *testing.T) { - test_cliValue( - t, - func(cli pilgrim.CliFlagRetriever) (string, bool) { return cli.Password() }, - pilgrim.Flag_Password, - "password", - ) -} - -func Test_CliContext_Host(t *testing.T) { - test_cliValue( - t, - func(cli pilgrim.CliFlagRetriever) (string, bool) { return cli.Host() }, - pilgrim.Flag_Host, - "localhost", - ) -} - -func Test_CliContext_Port(t *testing.T) { - test_cliValue( - t, - func(cli pilgrim.CliFlagRetriever) (string, bool) { return cli.Port() }, - pilgrim.Flag_Port, - "3306", - ) -} - -func Test_CliContext_Segments(t *testing.T) { - expectedValue := []string{ - "segment1", "segment2", "segment3", - } - - flag.Set(pilgrim.Flag_Segments, "segment1/segment2/segment3") - - value, _ := pilgrim.CliContext().Segments() - - assert.Equal(t, expectedValue, value) -} - -func Test_CliContext_Args(t *testing.T) { - expectedValue := map[string]string{ - "arg1": "val1", - "arg2": "val2", - "arg3": "val3", - } - - flag.Set(pilgrim.Flag_Args, "arg1=val1&arg2=val2&arg3=val3") - - value, _ := pilgrim.CliContext().Args() - - assert.Equal(t, expectedValue, value) -} - -func Test_CliContext_Directory(t *testing.T) { - test_cliValue( - t, - func(cli pilgrim.CliFlagRetriever) (string, bool) { return cli.Directory() }, - pilgrim.Flag_Directory, - "./custom-migrations", - ) -} - -func Test_CliContext_Script(t *testing.T) { - test_cliValue( - t, - func(cli pilgrim.CliFlagRetriever) (string, bool) { return cli.Script() }, - pilgrim.Flag_Script, - "2024-10-13/1_SomeScript.sql", - ) -} - -func Test_CliContext_MigrationTable(t *testing.T) { - test_cliValue( - t, - func(cli pilgrim.CliFlagRetriever) (string, bool) { return cli.MigrationTable() }, - pilgrim.Flag_Table, - "CustomMigrationsTable", - ) -} - -func Test_CliContext_MigrationTableSchema(t *testing.T) { - test_cliValue( - t, - func(cli pilgrim.CliFlagRetriever) (string, bool) { - return pilgrim.CliContext().MigrationTableSchema() - }, - pilgrim.Flag_Schema, - "public", - ) -} - -func Test_CliContext_Up(t *testing.T) { - test_cliValue( - t, - func(cli pilgrim.CliFlagRetriever) (bool, bool) { return cli.IsUp() }, - pilgrim.Flag_Up, - true, - ) -} - -func Test_CliContext_Down(t *testing.T) { - test_cliValue( - t, - func(cli pilgrim.CliFlagRetriever) (bool, bool) { return cli.IsDown() }, - pilgrim.Flag_Down, - true, - ) -} -func Test_CliContext_StrictOrdering(t *testing.T) { - test_cliValue( - t, - func(cli pilgrim.CliFlagRetriever) (bool, bool) { - return pilgrim.CliContext().IsStrictOrderingEnabled() - }, - pilgrim.Flag_StrictOrdering, - true, - ) -} - -func Test_CliContext_DisableChecksumValidation(t *testing.T) { - expectedValue := false - - flag.Set(pilgrim.Flag_DisableChecksumValidation, "true") - - value, _ := pilgrim.CliContext().IsChecksumValidationEnabled() - - assert.Equal(t, expectedValue, value) -} - -func Test_CliContext_ValidateChecksums(t *testing.T) { - test_cliValue( - t, - func(cli pilgrim.CliFlagRetriever) (bool, bool) { - return cli.IsValidatingChecksums() - }, - pilgrim.Flag_ValidateChecksums, - true, - ) -} - -func Test_CliContext_ValidateMigrationOrder(t *testing.T) { - test_cliValue( - t, - func(cli pilgrim.CliFlagRetriever) (bool, bool) { - return cli.IsValidatingMigrationOrder() - }, - pilgrim.Flag_ValidateMigrationOrder, - true, - ) -} - -func Test_CliContext_ValidateLatest(t *testing.T) { - test_cliValue( - t, - func(cli pilgrim.CliFlagRetriever) (bool, bool) { return cli.IsValidatingLatest() }, - pilgrim.Flag_ValidateLatest, - true, - ) -} - -func test_cliValue[T string | pilgrim.DbDriver | bool](t *testing.T, cliVal func(cli pilgrim.CliFlagRetriever) (value T, isProvided bool), flagName string, expectedVal T) { - cli := pilgrim.CliContext() - - flag.Set(flagName, fmt.Sprintf("%v", expectedVal)) - - cli.ParseFlags() - - value, _ := cliVal(cli) - - assert.Equal(t, expectedVal, value) -} diff --git a/pilgrim/test/context_test.go b/pilgrim/test/context_test.go deleted file mode 100644 index af2bfba..0000000 --- a/pilgrim/test/context_test.go +++ /dev/null @@ -1,109 +0,0 @@ -package pilgrim_test - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" - "mvvasilev.dev/pilgrim/pilgrim" -) - -type MockCliFlagRetriever struct { - mock.Mock -} - -type MockEnvVarRetriever struct { - mock.Mock -} - -const CliUrlValue = "postgres://cli_host:5432/cli_segment1/cli_segment2?cli_arg1=cli_val1&cli_arg2=cli_val2" -const CliDriverValue = pilgrim.DbDriver_Postgres - -func Test_PilgrimContext_CliDriverOverridesCliUrlDriver(t *testing.T) { - env, cli := new(MockEnvVarRetriever), new(MockCliFlagRetriever) - - env.On("Driver") - - context, _, _ := createPilgrimContextWithDependencies( - map[string]string{ - pilgrim.Flag_Url: CliUrlValue, - pilgrim.Flag_Driver: string(CliDriverValue), - }, - map[string]string{}, - ) - - assert.Equal(t, CliDriverValue, context.UrlParts().Driver, CliDriverValue) -} - -func Test_PilgrimContext_EnvDriverOverridesEnvUrlDriver(t *testing.T) { - context, _, _ := createPilgrimContextWithDependencies( - map[string]string{}, - map[string]string{ - pilgrim.EnvVarKey_Url: "mariadb://env_host:3306/env_segment1/env_segment2?env_arg1=env_val1&env_arg2=env_val2", - pilgrim.EnvVarKey_Driver: "postgres", - }, - ) - - assert.Equal(t, pilgrim.DbDriver_Postgres, context.UrlParts().Driver) -} - -func Test_PilgrimContext_CliUrlDriverOverridesEnvDriver(t *testing.T) { - context, _, _ := createPilgrimContextWithDependencies( - map[string]string{ - pilgrim.Flag_Url: CliUrlValue, - }, - map[string]string{ - pilgrim.EnvVarKey_Driver: "mariadb", - }, - ) - - assert.Equal(t, CliDriverValue, context.UrlParts().Driver) -} - -func Test_PilgrimContext_CliDriverOverridesEnvDriver(t *testing.T) { - context, _, _ := createPilgrimContextWithDependencies( - map[string]string{ - pilgrim.Flag_Driver: string(CliDriverValue), - }, - map[string]string{ - pilgrim.EnvVarKey_Driver: "mariadb", - }, - ) - - assert.Equal(t, CliDriverValue, context.UrlParts().Driver) -} - -func Test_PilgrimContext_EnvDriverIsUsedIfNoCliDriverProvided(t *testing.T) { - context, _, _ := createPilgrimContextWithDependencies( - map[string]string{}, - map[string]string{ - pilgrim.EnvVarKey_Driver: "mariadb", - }, - ) - - assert.Equal(t, pilgrim.DbDriver_MariaDB, context.UrlParts().Driver) -} - -func Test_PilgrimContext_EnvUrlDriverIsUsedIfNoCliDriverProvided(t *testing.T) { - context, _, _ := createPilgrimContextWithDependencies( - map[string]string{}, - map[string]string{ - pilgrim.EnvVarKey_Url: "mariadb://env_host:3306/env_segment1/env_segment2?env_arg1=env_val1&env_arg2=env_val2", - }, - ) - - assert.Equal(t, pilgrim.DbDriver_MariaDB, context.UrlParts().Driver) -} - -func Test_PilgrimContext_EnvUrlDriverIsNotUsedIfNoCliDriverOverrideProvided(t *testing.T) { - context, _, _ := createPilgrimContextWithDependencies( - map[string]string{ - pilgrim.Flag_Driver: "postgres", - }, - map[string]string{ - pilgrim.EnvVarKey_Url: "mariadb://env_host:3306/env_segment1/env_segment2?env_arg1=env_val1&env_arg2=env_val2", - }, - ) - - assert.Equal(t, pilgrim.DbDriver_Postgres, context.UrlParts().Driver) -} diff --git a/pilgrim/test/mock/context_mock.go b/pilgrim/test/mock/context_mock.go deleted file mode 100644 index b7b000e..0000000 --- a/pilgrim/test/mock/context_mock.go +++ /dev/null @@ -1,207 +0,0 @@ -package pilgrim_mock - -import "mvvasilev.dev/pilgrim/pilgrim" - -type cliContextMock struct { - stringFlags map[string]func() (value string, isProvided bool) - boolFlags map[string]func() (value bool, isProvided bool) - segments func() (value []string, isProvided bool) - args func() (value map[string]string, isProvided bool) -} - -func MockCliContext( - stringFlags map[string]func() (value string, isProvided bool), - boolFlags map[string]func() (value bool, isProvided bool), - segments func() (value []string, isProvided bool), - args func() (value map[string]string, isProvided bool), -) *cliContextMock { - return &cliContextMock{ - stringFlags, boolFlags, segments, args, - } -} - -func (mock *cliContextMock) stringVal(val string) (value string, isProvided bool) { - retrieverFunc, available := mock.stringFlags[val] - - if !available { - return pilgrim.EmptyString, false - } - - return retrieverFunc() -} - -func (mock *cliContextMock) boolVal(val string) (value bool, isProvided bool) { - retrieverFunc, available := mock.boolFlags[val] - - if !available { - return false, false - } - - return retrieverFunc() -} - -func (mock *cliContextMock) Url() (value string, isProvided bool) { - return mock.stringVal(pilgrim.Flag_Url) -} - -func (mock *cliContextMock) Driver() (value pilgrim.DbDriver, isProvided bool) { - val, provided := mock.stringVal(pilgrim.Flag_Driver) - return pilgrim.DbDriver(val), provided -} - -func (mock *cliContextMock) Username() (value string, isProvided bool) { - return mock.stringVal(pilgrim.Flag_Username) -} - -func (mock *cliContextMock) Password() (value string, isProvided bool) { - return mock.stringVal(pilgrim.Flag_Password) -} - -func (mock *cliContextMock) Host() (value string, isProvided bool) { - return mock.stringVal(pilgrim.Flag_Host) -} - -func (mock *cliContextMock) Port() (value string, isProvided bool) { - return mock.stringVal(pilgrim.Flag_Port) -} - -func (mock *cliContextMock) Segments() (value []string, isProvided bool) { - return mock.segments() -} - -func (mock *cliContextMock) Args() (value map[string]string, isProvided bool) { - return mock.args() -} - -func (mock *cliContextMock) Directory() (value string, isProvided bool) { - return mock.stringVal(pilgrim.Flag_Directory) -} - -func (mock *cliContextMock) IsUp() (value bool, isProvided bool) { - return mock.boolVal(pilgrim.Flag_Up) -} - -func (mock *cliContextMock) IsDown() (value bool, isProvided bool) { - return mock.boolVal(pilgrim.Flag_Down) -} - -// Can be a script name, or "latest" -func (mock *cliContextMock) Script() (value string, isProvided bool) { - return mock.stringVal(pilgrim.Flag_Script) -} - -func (mock *cliContextMock) MigrationTable() (value string, isProvided bool) { - return mock.stringVal(pilgrim.Flag_Table) -} - -func (mock *cliContextMock) MigrationTableSchema() (value string, isProvided bool) { - return mock.stringVal(pilgrim.Flag_Schema) -} - -func (mock *cliContextMock) IsChecksumValidationEnabled() (value bool, isProvided bool) { - value, isProvided = mock.boolVal(pilgrim.Flag_DisableChecksumValidation) - return !value, isProvided -} - -func (mock *cliContextMock) IsStrictOrderingEnabled() (value bool, isProvided bool) { - return mock.boolVal(pilgrim.Flag_StrictOrdering) -} - -func (mock *cliContextMock) IsValidatingMigrationOrder() (value bool, isProvided bool) { - return mock.boolVal(pilgrim.Flag_ValidateMigrationOrder) -} - -func (mock *cliContextMock) IsValidatingLatest() (value bool, isProvided bool) { - return mock.boolVal(pilgrim.Flag_ValidateLatest) -} - -func (mock *cliContextMock) IsValidatingChecksums() (value bool, isProvided bool) { - return mock.boolVal(pilgrim.Flag_ValidateChecksums) -} - -func (mock *cliContextMock) ParseFlags() { - -} - -type envVarContextMock struct { - stringVars map[string]func() (value string, isProvided bool) - boolVars map[string]func() (value bool, isProvided bool) - segments func() (value []string, isProvided bool) - args func() (value map[string]string, isProvided bool) -} - -func MockEnvVarContext( - stringVars map[string]func() (value string, isProvided bool), - boolVars map[string]func() (value bool, isProvided bool), - segments func() (value []string, isProvided bool), - args func() (value map[string]string, isProvided bool), -) *envVarContextMock { - return &envVarContextMock{ - stringVars, boolVars, segments, args, - } -} - -func (mock *envVarContextMock) stringVal(val string) (value string, isProvided bool) { - retrieverFunc, available := mock.stringVars[val] - - if !available { - return pilgrim.EmptyString, false - } - - return retrieverFunc() -} - -func (mock *envVarContextMock) boolVal(val string) (value bool, isProvided bool) { - retrieverFunc, available := mock.boolVars[val] - - if !available { - return false, false - } - - return retrieverFunc() -} - -func (mock *envVarContextMock) Url() (value string, isDefined bool) { - return mock.stringVal(pilgrim.EnvVarKey_Url) -} - -func (mock *envVarContextMock) Driver() (value pilgrim.DbDriver, isDefined bool) { - val, provided := mock.stringVal(pilgrim.Flag_Driver) - return pilgrim.DbDriver(val), provided -} - -func (mock *envVarContextMock) Username() (value string, isDefined bool) { - return mock.stringVal(pilgrim.EnvVarKey_Username) -} - -func (mock *envVarContextMock) Password() (value string, isDefined bool) { - return mock.stringVal(pilgrim.EnvVarKey_Password) -} - -func (mock *envVarContextMock) Host() (value string, isDefined bool) { - return mock.stringVal(pilgrim.EnvVarKey_Host) -} - -func (mock *envVarContextMock) Port() (value string, isDefined bool) { - return mock.stringVal(pilgrim.EnvVarKey_Port) -} - -func (mock *envVarContextMock) Segments() (value []string, isDefined bool) { - return mock.segments() -} - -func (mock *envVarContextMock) Args() (value map[string]string, isDefined bool) { - return mock.args() -} - -func (mock *envVarContextMock) Directory() (value string, isDefined bool) { - return mock.stringVal(pilgrim.EnvVarKey_Directory) -} - -func (mock *envVarContextMock) MigrationTable() (value string, isDefined bool) { - return mock.stringVal(pilgrim.EnvVarKey_Table) -} - -func (mock *envVarContextMock) MigrationTableSchema() (value string, isDefined bool) { - return mock.stringVal(pilgrim.EnvVarKey_Schema) -}