start instance working good

This commit is contained in:
Alexis Couvreur
2024-11-17 12:32:13 -05:00
parent 4122109349
commit f822c28faa
13 changed files with 718 additions and 416 deletions

View File

@@ -1,33 +1,308 @@
// Code generated by mockery v2.47.0. DO NOT EDIT.
package mock
import "context"
import (
context "context"
// ProviderMock is a structure that allows to define the behavior of a Provider
type ProviderMock struct {
StartFunc func(ctx context.Context, name string, opts provider.StartOptions) error
StopFunc func(ctx context.Context, name string) error
StatusFunc func(ctx context.Context, name string) (bool, error)
EventsFunc func(ctx context.Context) (<-chan provider.Message, <-chan error)
SubscribeOnceFunc func(ctx context.Context, name string, action provider.EventAction, wait chan<- error)
DiscoverFunc func(ctx context.Context, opts provider.DiscoveryOptions) ([]provider.Discovered, error)
provider "github.com/sablierapp/sablier/pkg/provider"
mock "github.com/stretchr/testify/mock"
)
// MockProvider is an autogenerated mock type for the Provider type
type MockProvider struct {
mock.Mock
}
func (m *ProviderMock) Start(ctx context.Context, name string, opts provider.StartOptions) error {
return m.StartFunc(ctx, name, opts)
}
func (m *ProviderMock) Stop(ctx context.Context, name string) error {
return m.StopFunc(ctx, name)
}
func (m *ProviderMock) Status(ctx context.Context, name string) (bool, error) {
return m.StatusFunc(ctx, name)
}
func (m *ProviderMock) Events(ctx context.Context) (<-chan provider.Message, <-chan error) {
return m.EventsFunc(ctx)
}
func (m *ProviderMock) SubscribeOnce(ctx context.Context, name string, action provider.EventAction, wait chan<- error) {
m.SubscribeOnceFunc(ctx, name, action, wait)
type MockProvider_Expecter struct {
mock *mock.Mock
}
func (m *ProviderMock) Discover(ctx context.Context, opts provider.DiscoveryOptions) ([]provider.Discovered, error) {
return m.DiscoverFunc(ctx, opts)
func (_m *MockProvider) EXPECT() *MockProvider_Expecter {
return &MockProvider_Expecter{mock: &_m.Mock}
}
// Events provides a mock function with given fields: ctx
func (_m *MockProvider) Events(ctx context.Context) (<-chan provider.Message, <-chan error) {
ret := _m.Called(ctx)
if len(ret) == 0 {
panic("no return value specified for Events")
}
var r0 <-chan provider.Message
var r1 <-chan error
if rf, ok := ret.Get(0).(func(context.Context) (<-chan provider.Message, <-chan error)); ok {
return rf(ctx)
}
if rf, ok := ret.Get(0).(func(context.Context) <-chan provider.Message); ok {
r0 = rf(ctx)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(<-chan provider.Message)
}
}
if rf, ok := ret.Get(1).(func(context.Context) <-chan error); ok {
r1 = rf(ctx)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(<-chan error)
}
}
return r0, r1
}
// MockProvider_Events_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Events'
type MockProvider_Events_Call struct {
*mock.Call
}
// Events is a helper method to define mock.On call
// - ctx context.Context
func (_e *MockProvider_Expecter) Events(ctx interface{}) *MockProvider_Events_Call {
return &MockProvider_Events_Call{Call: _e.mock.On("Events", ctx)}
}
func (_c *MockProvider_Events_Call) Run(run func(ctx context.Context)) *MockProvider_Events_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context))
})
return _c
}
func (_c *MockProvider_Events_Call) Return(_a0 <-chan provider.Message, _a1 <-chan error) *MockProvider_Events_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockProvider_Events_Call) RunAndReturn(run func(context.Context) (<-chan provider.Message, <-chan error)) *MockProvider_Events_Call {
_c.Call.Return(run)
return _c
}
// List provides a mock function with given fields: ctx, name
func (_m *MockProvider) List(ctx context.Context, name string) ([]string, error) {
ret := _m.Called(ctx, name)
if len(ret) == 0 {
panic("no return value specified for List")
}
var r0 []string
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string) ([]string, error)); ok {
return rf(ctx, name)
}
if rf, ok := ret.Get(0).(func(context.Context, string) []string); ok {
r0 = rf(ctx, name)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]string)
}
}
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
r1 = rf(ctx, name)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockProvider_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List'
type MockProvider_List_Call struct {
*mock.Call
}
// List is a helper method to define mock.On call
// - ctx context.Context
// - name string
func (_e *MockProvider_Expecter) List(ctx interface{}, name interface{}) *MockProvider_List_Call {
return &MockProvider_List_Call{Call: _e.mock.On("List", ctx, name)}
}
func (_c *MockProvider_List_Call) Run(run func(ctx context.Context, name string)) *MockProvider_List_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(string))
})
return _c
}
func (_c *MockProvider_List_Call) Return(_a0 []string, _a1 error) *MockProvider_List_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockProvider_List_Call) RunAndReturn(run func(context.Context, string) ([]string, error)) *MockProvider_List_Call {
_c.Call.Return(run)
return _c
}
// Start provides a mock function with given fields: ctx, name, opts
func (_m *MockProvider) Start(ctx context.Context, name string, opts provider.StartOptions) error {
ret := _m.Called(ctx, name, opts)
if len(ret) == 0 {
panic("no return value specified for Start")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, string, provider.StartOptions) error); ok {
r0 = rf(ctx, name, opts)
} else {
r0 = ret.Error(0)
}
return r0
}
// MockProvider_Start_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Start'
type MockProvider_Start_Call struct {
*mock.Call
}
// Start is a helper method to define mock.On call
// - ctx context.Context
// - name string
// - opts provider.StartOptions
func (_e *MockProvider_Expecter) Start(ctx interface{}, name interface{}, opts interface{}) *MockProvider_Start_Call {
return &MockProvider_Start_Call{Call: _e.mock.On("Start", ctx, name, opts)}
}
func (_c *MockProvider_Start_Call) Run(run func(ctx context.Context, name string, opts provider.StartOptions)) *MockProvider_Start_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(string), args[2].(provider.StartOptions))
})
return _c
}
func (_c *MockProvider_Start_Call) Return(_a0 error) *MockProvider_Start_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockProvider_Start_Call) RunAndReturn(run func(context.Context, string, provider.StartOptions) error) *MockProvider_Start_Call {
_c.Call.Return(run)
return _c
}
// Status provides a mock function with given fields: ctx, name
func (_m *MockProvider) Status(ctx context.Context, name string) (bool, error) {
ret := _m.Called(ctx, name)
if len(ret) == 0 {
panic("no return value specified for Status")
}
var r0 bool
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string) (bool, error)); ok {
return rf(ctx, name)
}
if rf, ok := ret.Get(0).(func(context.Context, string) bool); ok {
r0 = rf(ctx, name)
} else {
r0 = ret.Get(0).(bool)
}
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
r1 = rf(ctx, name)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockProvider_Status_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Status'
type MockProvider_Status_Call struct {
*mock.Call
}
// Status is a helper method to define mock.On call
// - ctx context.Context
// - name string
func (_e *MockProvider_Expecter) Status(ctx interface{}, name interface{}) *MockProvider_Status_Call {
return &MockProvider_Status_Call{Call: _e.mock.On("Status", ctx, name)}
}
func (_c *MockProvider_Status_Call) Run(run func(ctx context.Context, name string)) *MockProvider_Status_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(string))
})
return _c
}
func (_c *MockProvider_Status_Call) Return(_a0 bool, _a1 error) *MockProvider_Status_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockProvider_Status_Call) RunAndReturn(run func(context.Context, string) (bool, error)) *MockProvider_Status_Call {
_c.Call.Return(run)
return _c
}
// Stop provides a mock function with given fields: ctx, name
func (_m *MockProvider) Stop(ctx context.Context, name string) error {
ret := _m.Called(ctx, name)
if len(ret) == 0 {
panic("no return value specified for Stop")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, string) error); ok {
r0 = rf(ctx, name)
} else {
r0 = ret.Error(0)
}
return r0
}
// MockProvider_Stop_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Stop'
type MockProvider_Stop_Call struct {
*mock.Call
}
// Stop is a helper method to define mock.On call
// - ctx context.Context
// - name string
func (_e *MockProvider_Expecter) Stop(ctx interface{}, name interface{}) *MockProvider_Stop_Call {
return &MockProvider_Stop_Call{Call: _e.mock.On("Stop", ctx, name)}
}
func (_c *MockProvider_Stop_Call) Run(run func(ctx context.Context, name string)) *MockProvider_Stop_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(string))
})
return _c
}
func (_c *MockProvider_Stop_Call) Return(_a0 error) *MockProvider_Stop_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockProvider_Stop_Call) RunAndReturn(run func(context.Context, string) error) *MockProvider_Stop_Call {
_c.Call.Return(run)
return _c
}
// NewMockProvider creates a new instance of MockProvider. 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 NewMockProvider(t interface {
mock.TestingT
Cleanup(func())
}) *MockProvider {
mock := &MockProvider{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@@ -1 +1,46 @@
package provider
import (
"context"
"time"
)
type EventAction string
const (
// EventActionCreate describes when a workload has been created
EventActionCreate EventAction = "create"
// EventActionRemove describes when a workload has been destroyed
EventActionRemove EventAction = "destroy"
// EventActionReady describes when a workload is ready to handle traffic
EventActionReady EventAction = "ready"
// EventActionStart describes when a workload is started but not necessarily ready
EventActionStart EventAction = "start"
// EventActionStop describes when a workload is stopped
EventActionStop EventAction = "stop"
)
type Message struct {
Name string
Group string
Action EventAction
}
type StartOptions struct {
DesiredReplicas uint32
ConsiderReadyAfter time.Duration
}
type Provider interface {
Start(ctx context.Context, name string, opts StartOptions) error
Stop(ctx context.Context, name string) error
Status(ctx context.Context, name string) (bool, error)
List(ctx context.Context, name string) ([]string, error)
Events(ctx context.Context) (<-chan Message, <-chan error)
}