Fix tests and generate mocks (#4384)

This commit is contained in:
Nikola Jokic
2026-02-24 13:36:01 +01:00
committed by GitHub
parent 9de09f56eb
commit c6e4c94a6a
20 changed files with 2360 additions and 809 deletions
+2 -2
View File
@@ -26,12 +26,12 @@ type App struct {
metrics metrics.ServerExporter
}
//go:generate mockery --name Listener --output ./mocks --outpkg mocks --case underscore
//go:generate mockery
type Listener interface {
Listen(ctx context.Context, handler listener.Handler) error
}
//go:generate mockery --name Worker --output ./mocks --outpkg mocks --case underscore
//go:generate mockery
type Worker interface {
HandleJobStarted(ctx context.Context, jobInfo *actions.JobStarted) error
HandleDesiredRunnerCount(ctx context.Context, count int, jobsCompleted int) (int, error)
+6 -6
View File
@@ -29,8 +29,8 @@ func TestApp_Run(t *testing.T) {
})
t.Run("ExitsOnListenerError", func(t *testing.T) {
listener := appmocks.NewListener(t)
worker := appmocks.NewWorker(t)
listener := appmocks.NewMockListener(t)
worker := appmocks.NewMockWorker(t)
listener.On("Listen", mock.Anything, mock.Anything).Return(errors.New("listener error")).Once()
@@ -44,8 +44,8 @@ func TestApp_Run(t *testing.T) {
})
t.Run("ExitsOnListenerNil", func(t *testing.T) {
listener := appmocks.NewListener(t)
worker := appmocks.NewWorker(t)
listener := appmocks.NewMockListener(t)
worker := appmocks.NewMockWorker(t)
listener.On("Listen", mock.Anything, mock.Anything).Return(nil).Once()
@@ -59,8 +59,8 @@ func TestApp_Run(t *testing.T) {
})
t.Run("CancelListenerOnMetricsServerError", func(t *testing.T) {
listener := appmocks.NewListener(t)
worker := appmocks.NewWorker(t)
listener := appmocks.NewMockListener(t)
worker := appmocks.NewMockWorker(t)
metrics := metricsMocks.NewServerPublisher(t)
ctx := context.Background()
+79 -26
View File
@@ -1,43 +1,96 @@
// Code generated by mockery v2.36.1. DO NOT EDIT.
// Code generated by mockery; DO NOT EDIT.
// github.com/vektra/mockery
// template: testify
package mocks
import (
context "context"
"context"
listener "github.com/actions/actions-runner-controller/cmd/ghalistener/listener"
"github.com/actions/actions-runner-controller/cmd/ghalistener/listener"
mock "github.com/stretchr/testify/mock"
)
// Listener is an autogenerated mock type for the Listener type
type Listener struct {
mock.Mock
}
// Listen provides a mock function with given fields: ctx, handler
func (_m *Listener) Listen(ctx context.Context, handler listener.Handler) error {
ret := _m.Called(ctx, handler)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, listener.Handler) error); ok {
r0 = rf(ctx, handler)
} else {
r0 = ret.Error(0)
}
return r0
}
// NewListener creates a new instance of Listener. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// NewMockListener creates a new instance of MockListener. 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 NewListener(t interface {
func NewMockListener(t interface {
mock.TestingT
Cleanup(func())
}) *Listener {
mock := &Listener{}
}) *MockListener {
mock := &MockListener{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
// MockListener is an autogenerated mock type for the Listener type
type MockListener struct {
mock.Mock
}
type MockListener_Expecter struct {
mock *mock.Mock
}
func (_m *MockListener) EXPECT() *MockListener_Expecter {
return &MockListener_Expecter{mock: &_m.Mock}
}
// Listen provides a mock function for the type MockListener
func (_mock *MockListener) Listen(ctx context.Context, handler listener.Handler) error {
ret := _mock.Called(ctx, handler)
if len(ret) == 0 {
panic("no return value specified for Listen")
}
var r0 error
if returnFunc, ok := ret.Get(0).(func(context.Context, listener.Handler) error); ok {
r0 = returnFunc(ctx, handler)
} else {
r0 = ret.Error(0)
}
return r0
}
// MockListener_Listen_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Listen'
type MockListener_Listen_Call struct {
*mock.Call
}
// Listen is a helper method to define mock.On call
// - ctx context.Context
// - handler listener.Handler
func (_e *MockListener_Expecter) Listen(ctx interface{}, handler interface{}) *MockListener_Listen_Call {
return &MockListener_Listen_Call{Call: _e.mock.On("Listen", ctx, handler)}
}
func (_c *MockListener_Listen_Call) Run(run func(ctx context.Context, handler listener.Handler)) *MockListener_Listen_Call {
_c.Call.Run(func(args mock.Arguments) {
var arg0 context.Context
if args[0] != nil {
arg0 = args[0].(context.Context)
}
var arg1 listener.Handler
if args[1] != nil {
arg1 = args[1].(listener.Handler)
}
run(
arg0,
arg1,
)
})
return _c
}
func (_c *MockListener_Listen_Call) Return(err error) *MockListener_Listen_Call {
_c.Call.Return(err)
return _c
}
func (_c *MockListener_Listen_Call) RunAndReturn(run func(ctx context.Context, handler listener.Handler) error) *MockListener_Listen_Call {
_c.Call.Return(run)
return _c
}
+151 -51
View File
@@ -1,68 +1,168 @@
// Code generated by mockery v2.36.1. DO NOT EDIT.
// Code generated by mockery; DO NOT EDIT.
// github.com/vektra/mockery
// template: testify
package mocks
import (
actions "github.com/actions/actions-runner-controller/github/actions"
context "context"
"context"
"github.com/actions/actions-runner-controller/github/actions"
mock "github.com/stretchr/testify/mock"
)
// Worker is an autogenerated mock type for the Worker type
type Worker struct {
mock.Mock
}
// HandleDesiredRunnerCount provides a mock function with given fields: ctx, count, acquireCount
func (_m *Worker) HandleDesiredRunnerCount(ctx context.Context, count int, acquireCount int) (int, error) {
ret := _m.Called(ctx, count, acquireCount)
var r0 int
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, int, int) (int, error)); ok {
return rf(ctx, count, acquireCount)
}
if rf, ok := ret.Get(0).(func(context.Context, int, int) int); ok {
r0 = rf(ctx, count, acquireCount)
} else {
r0 = ret.Get(0).(int)
}
if rf, ok := ret.Get(1).(func(context.Context, int, int) error); ok {
r1 = rf(ctx, count, acquireCount)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// HandleJobStarted provides a mock function with given fields: ctx, jobInfo
func (_m *Worker) HandleJobStarted(ctx context.Context, jobInfo *actions.JobStarted) error {
ret := _m.Called(ctx, jobInfo)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, *actions.JobStarted) error); ok {
r0 = rf(ctx, jobInfo)
} else {
r0 = ret.Error(0)
}
return r0
}
// NewWorker creates a new instance of Worker. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// NewMockWorker creates a new instance of MockWorker. 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 NewWorker(t interface {
func NewMockWorker(t interface {
mock.TestingT
Cleanup(func())
}) *Worker {
mock := &Worker{}
}) *MockWorker {
mock := &MockWorker{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
// MockWorker is an autogenerated mock type for the Worker type
type MockWorker struct {
mock.Mock
}
type MockWorker_Expecter struct {
mock *mock.Mock
}
func (_m *MockWorker) EXPECT() *MockWorker_Expecter {
return &MockWorker_Expecter{mock: &_m.Mock}
}
// HandleDesiredRunnerCount provides a mock function for the type MockWorker
func (_mock *MockWorker) HandleDesiredRunnerCount(ctx context.Context, count int, jobsCompleted int) (int, error) {
ret := _mock.Called(ctx, count, jobsCompleted)
if len(ret) == 0 {
panic("no return value specified for HandleDesiredRunnerCount")
}
var r0 int
var r1 error
if returnFunc, ok := ret.Get(0).(func(context.Context, int, int) (int, error)); ok {
return returnFunc(ctx, count, jobsCompleted)
}
if returnFunc, ok := ret.Get(0).(func(context.Context, int, int) int); ok {
r0 = returnFunc(ctx, count, jobsCompleted)
} else {
r0 = ret.Get(0).(int)
}
if returnFunc, ok := ret.Get(1).(func(context.Context, int, int) error); ok {
r1 = returnFunc(ctx, count, jobsCompleted)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockWorker_HandleDesiredRunnerCount_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HandleDesiredRunnerCount'
type MockWorker_HandleDesiredRunnerCount_Call struct {
*mock.Call
}
// HandleDesiredRunnerCount is a helper method to define mock.On call
// - ctx context.Context
// - count int
// - jobsCompleted int
func (_e *MockWorker_Expecter) HandleDesiredRunnerCount(ctx interface{}, count interface{}, jobsCompleted interface{}) *MockWorker_HandleDesiredRunnerCount_Call {
return &MockWorker_HandleDesiredRunnerCount_Call{Call: _e.mock.On("HandleDesiredRunnerCount", ctx, count, jobsCompleted)}
}
func (_c *MockWorker_HandleDesiredRunnerCount_Call) Run(run func(ctx context.Context, count int, jobsCompleted int)) *MockWorker_HandleDesiredRunnerCount_Call {
_c.Call.Run(func(args mock.Arguments) {
var arg0 context.Context
if args[0] != nil {
arg0 = args[0].(context.Context)
}
var arg1 int
if args[1] != nil {
arg1 = args[1].(int)
}
var arg2 int
if args[2] != nil {
arg2 = args[2].(int)
}
run(
arg0,
arg1,
arg2,
)
})
return _c
}
func (_c *MockWorker_HandleDesiredRunnerCount_Call) Return(n int, err error) *MockWorker_HandleDesiredRunnerCount_Call {
_c.Call.Return(n, err)
return _c
}
func (_c *MockWorker_HandleDesiredRunnerCount_Call) RunAndReturn(run func(ctx context.Context, count int, jobsCompleted int) (int, error)) *MockWorker_HandleDesiredRunnerCount_Call {
_c.Call.Return(run)
return _c
}
// HandleJobStarted provides a mock function for the type MockWorker
func (_mock *MockWorker) HandleJobStarted(ctx context.Context, jobInfo *actions.JobStarted) error {
ret := _mock.Called(ctx, jobInfo)
if len(ret) == 0 {
panic("no return value specified for HandleJobStarted")
}
var r0 error
if returnFunc, ok := ret.Get(0).(func(context.Context, *actions.JobStarted) error); ok {
r0 = returnFunc(ctx, jobInfo)
} else {
r0 = ret.Error(0)
}
return r0
}
// MockWorker_HandleJobStarted_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HandleJobStarted'
type MockWorker_HandleJobStarted_Call struct {
*mock.Call
}
// HandleJobStarted is a helper method to define mock.On call
// - ctx context.Context
// - jobInfo *actions.JobStarted
func (_e *MockWorker_Expecter) HandleJobStarted(ctx interface{}, jobInfo interface{}) *MockWorker_HandleJobStarted_Call {
return &MockWorker_HandleJobStarted_Call{Call: _e.mock.On("HandleJobStarted", ctx, jobInfo)}
}
func (_c *MockWorker_HandleJobStarted_Call) Run(run func(ctx context.Context, jobInfo *actions.JobStarted)) *MockWorker_HandleJobStarted_Call {
_c.Call.Run(func(args mock.Arguments) {
var arg0 context.Context
if args[0] != nil {
arg0 = args[0].(context.Context)
}
var arg1 *actions.JobStarted
if args[1] != nil {
arg1 = args[1].(*actions.JobStarted)
}
run(
arg0,
arg1,
)
})
return _c
}
func (_c *MockWorker_HandleJobStarted_Call) Return(err error) *MockWorker_HandleJobStarted_Call {
_c.Call.Return(err)
return _c
}
func (_c *MockWorker_HandleJobStarted_Call) RunAndReturn(run func(ctx context.Context, jobInfo *actions.JobStarted) error) *MockWorker_HandleJobStarted_Call {
_c.Call.Return(run)
return _c
}
+2 -2
View File
@@ -27,7 +27,7 @@ const (
messageTypeJobCompleted = "JobCompleted"
)
//go:generate mockery --name Client --output ./mocks --outpkg mocks --case underscore
//go:generate mockery
type Client interface {
GetAcquirableJobs(ctx context.Context, runnerScaleSetId int) (*actions.AcquirableJobList, error)
CreateMessageSession(ctx context.Context, runnerScaleSetId int, owner string) (*actions.RunnerScaleSetSession, error)
@@ -113,7 +113,7 @@ func New(config Config) (*Listener, error) {
return listener, nil
}
//go:generate mockery --name Handler --output ./mocks --outpkg mocks --case underscore
//go:generate mockery
type Handler interface {
HandleJobStarted(ctx context.Context, jobInfo *actions.JobStarted) error
HandleDesiredRunnerCount(ctx context.Context, count, jobsCompleted int) (int, error)
+3 -3
View File
@@ -20,7 +20,7 @@ func TestInitialMetrics(t *testing.T) {
t.Run("SetStaticMetrics", func(t *testing.T) {
t.Parallel()
metrics := metricsmocks.NewPublisher(t)
metrics := metricsmocks.NewMockPublisher(t)
minRunners := 5
maxRunners := 10
@@ -64,7 +64,7 @@ func TestInitialMetrics(t *testing.T) {
Statistics: sessionStatistics,
}
metrics := metricsmocks.NewPublisher(t)
metrics := metricsmocks.NewMockPublisher(t)
metrics.On("PublishStatic", mock.Anything, mock.Anything).Once()
metrics.On("PublishStatistics", sessionStatistics).Once()
metrics.On("PublishDesiredRunners", sessionStatistics.TotalAssignedJobs).
@@ -168,7 +168,7 @@ func TestHandleMessageMetrics(t *testing.T) {
desiredResult := 4
metrics := metricsmocks.NewPublisher(t)
metrics := metricsmocks.NewMockPublisher(t)
metrics.On("PublishStatic", 0, 0).Once()
metrics.On("PublishStatistics", msg.Statistics).Once()
metrics.On("PublishJobCompleted", jobsCompleted[0]).Once()
+2 -2
View File
@@ -100,7 +100,7 @@ func (e *exporter) startedJobLabels(msg *actions.JobStarted) prometheus.Labels {
return e.jobLabels(&msg.JobMessageBase)
}
//go:generate mockery --name Publisher --output ./mocks --outpkg mocks --case underscore
//go:generate mockery
type Publisher interface {
PublishStatic(min, max int)
PublishStatistics(stats *actions.RunnerScaleSetStatistic)
@@ -109,7 +109,7 @@ type Publisher interface {
PublishDesiredRunners(count int)
}
//go:generate mockery --name ServerPublisher --output ./mocks --outpkg mocks --case underscore
//go:generate mockery
type ServerExporter interface {
Publisher
ListenAndServe(ctx context.Context) error
+227 -37
View File
@@ -1,53 +1,243 @@
// Code generated by mockery v2.36.1. DO NOT EDIT.
// Code generated by mockery; DO NOT EDIT.
// github.com/vektra/mockery
// template: testify
package mocks
import (
actions "github.com/actions/actions-runner-controller/github/actions"
"github.com/actions/actions-runner-controller/github/actions"
mock "github.com/stretchr/testify/mock"
)
// Publisher is an autogenerated mock type for the Publisher type
type Publisher struct {
mock.Mock
}
// PublishDesiredRunners provides a mock function with given fields: count
func (_m *Publisher) PublishDesiredRunners(count int) {
_m.Called(count)
}
// PublishJobCompleted provides a mock function with given fields: msg
func (_m *Publisher) PublishJobCompleted(msg *actions.JobCompleted) {
_m.Called(msg)
}
// PublishJobStarted provides a mock function with given fields: msg
func (_m *Publisher) PublishJobStarted(msg *actions.JobStarted) {
_m.Called(msg)
}
// PublishStatic provides a mock function with given fields: min, max
func (_m *Publisher) PublishStatic(min int, max int) {
_m.Called(min, max)
}
// PublishStatistics provides a mock function with given fields: stats
func (_m *Publisher) PublishStatistics(stats *actions.RunnerScaleSetStatistic) {
_m.Called(stats)
}
// NewPublisher creates a new instance of Publisher. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// NewMockPublisher creates a new instance of MockPublisher. 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 NewPublisher(t interface {
func NewMockPublisher(t interface {
mock.TestingT
Cleanup(func())
}) *Publisher {
mock := &Publisher{}
}) *MockPublisher {
mock := &MockPublisher{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
// MockPublisher is an autogenerated mock type for the Publisher type
type MockPublisher struct {
mock.Mock
}
type MockPublisher_Expecter struct {
mock *mock.Mock
}
func (_m *MockPublisher) EXPECT() *MockPublisher_Expecter {
return &MockPublisher_Expecter{mock: &_m.Mock}
}
// PublishDesiredRunners provides a mock function for the type MockPublisher
func (_mock *MockPublisher) PublishDesiredRunners(count int) {
_mock.Called(count)
return
}
// MockPublisher_PublishDesiredRunners_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishDesiredRunners'
type MockPublisher_PublishDesiredRunners_Call struct {
*mock.Call
}
// PublishDesiredRunners is a helper method to define mock.On call
// - count int
func (_e *MockPublisher_Expecter) PublishDesiredRunners(count interface{}) *MockPublisher_PublishDesiredRunners_Call {
return &MockPublisher_PublishDesiredRunners_Call{Call: _e.mock.On("PublishDesiredRunners", count)}
}
func (_c *MockPublisher_PublishDesiredRunners_Call) Run(run func(count int)) *MockPublisher_PublishDesiredRunners_Call {
_c.Call.Run(func(args mock.Arguments) {
var arg0 int
if args[0] != nil {
arg0 = args[0].(int)
}
run(
arg0,
)
})
return _c
}
func (_c *MockPublisher_PublishDesiredRunners_Call) Return() *MockPublisher_PublishDesiredRunners_Call {
_c.Call.Return()
return _c
}
func (_c *MockPublisher_PublishDesiredRunners_Call) RunAndReturn(run func(count int)) *MockPublisher_PublishDesiredRunners_Call {
_c.Run(run)
return _c
}
// PublishJobCompleted provides a mock function for the type MockPublisher
func (_mock *MockPublisher) PublishJobCompleted(msg *actions.JobCompleted) {
_mock.Called(msg)
return
}
// MockPublisher_PublishJobCompleted_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishJobCompleted'
type MockPublisher_PublishJobCompleted_Call struct {
*mock.Call
}
// PublishJobCompleted is a helper method to define mock.On call
// - msg *actions.JobCompleted
func (_e *MockPublisher_Expecter) PublishJobCompleted(msg interface{}) *MockPublisher_PublishJobCompleted_Call {
return &MockPublisher_PublishJobCompleted_Call{Call: _e.mock.On("PublishJobCompleted", msg)}
}
func (_c *MockPublisher_PublishJobCompleted_Call) Run(run func(msg *actions.JobCompleted)) *MockPublisher_PublishJobCompleted_Call {
_c.Call.Run(func(args mock.Arguments) {
var arg0 *actions.JobCompleted
if args[0] != nil {
arg0 = args[0].(*actions.JobCompleted)
}
run(
arg0,
)
})
return _c
}
func (_c *MockPublisher_PublishJobCompleted_Call) Return() *MockPublisher_PublishJobCompleted_Call {
_c.Call.Return()
return _c
}
func (_c *MockPublisher_PublishJobCompleted_Call) RunAndReturn(run func(msg *actions.JobCompleted)) *MockPublisher_PublishJobCompleted_Call {
_c.Run(run)
return _c
}
// PublishJobStarted provides a mock function for the type MockPublisher
func (_mock *MockPublisher) PublishJobStarted(msg *actions.JobStarted) {
_mock.Called(msg)
return
}
// MockPublisher_PublishJobStarted_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishJobStarted'
type MockPublisher_PublishJobStarted_Call struct {
*mock.Call
}
// PublishJobStarted is a helper method to define mock.On call
// - msg *actions.JobStarted
func (_e *MockPublisher_Expecter) PublishJobStarted(msg interface{}) *MockPublisher_PublishJobStarted_Call {
return &MockPublisher_PublishJobStarted_Call{Call: _e.mock.On("PublishJobStarted", msg)}
}
func (_c *MockPublisher_PublishJobStarted_Call) Run(run func(msg *actions.JobStarted)) *MockPublisher_PublishJobStarted_Call {
_c.Call.Run(func(args mock.Arguments) {
var arg0 *actions.JobStarted
if args[0] != nil {
arg0 = args[0].(*actions.JobStarted)
}
run(
arg0,
)
})
return _c
}
func (_c *MockPublisher_PublishJobStarted_Call) Return() *MockPublisher_PublishJobStarted_Call {
_c.Call.Return()
return _c
}
func (_c *MockPublisher_PublishJobStarted_Call) RunAndReturn(run func(msg *actions.JobStarted)) *MockPublisher_PublishJobStarted_Call {
_c.Run(run)
return _c
}
// PublishStatic provides a mock function for the type MockPublisher
func (_mock *MockPublisher) PublishStatic(min int, max int) {
_mock.Called(min, max)
return
}
// MockPublisher_PublishStatic_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishStatic'
type MockPublisher_PublishStatic_Call struct {
*mock.Call
}
// PublishStatic is a helper method to define mock.On call
// - min int
// - max int
func (_e *MockPublisher_Expecter) PublishStatic(min interface{}, max interface{}) *MockPublisher_PublishStatic_Call {
return &MockPublisher_PublishStatic_Call{Call: _e.mock.On("PublishStatic", min, max)}
}
func (_c *MockPublisher_PublishStatic_Call) Run(run func(min int, max int)) *MockPublisher_PublishStatic_Call {
_c.Call.Run(func(args mock.Arguments) {
var arg0 int
if args[0] != nil {
arg0 = args[0].(int)
}
var arg1 int
if args[1] != nil {
arg1 = args[1].(int)
}
run(
arg0,
arg1,
)
})
return _c
}
func (_c *MockPublisher_PublishStatic_Call) Return() *MockPublisher_PublishStatic_Call {
_c.Call.Return()
return _c
}
func (_c *MockPublisher_PublishStatic_Call) RunAndReturn(run func(min int, max int)) *MockPublisher_PublishStatic_Call {
_c.Run(run)
return _c
}
// PublishStatistics provides a mock function for the type MockPublisher
func (_mock *MockPublisher) PublishStatistics(stats *actions.RunnerScaleSetStatistic) {
_mock.Called(stats)
return
}
// MockPublisher_PublishStatistics_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishStatistics'
type MockPublisher_PublishStatistics_Call struct {
*mock.Call
}
// PublishStatistics is a helper method to define mock.On call
// - stats *actions.RunnerScaleSetStatistic
func (_e *MockPublisher_Expecter) PublishStatistics(stats interface{}) *MockPublisher_PublishStatistics_Call {
return &MockPublisher_PublishStatistics_Call{Call: _e.mock.On("PublishStatistics", stats)}
}
func (_c *MockPublisher_PublishStatistics_Call) Run(run func(stats *actions.RunnerScaleSetStatistic)) *MockPublisher_PublishStatistics_Call {
_c.Call.Run(func(args mock.Arguments) {
var arg0 *actions.RunnerScaleSetStatistic
if args[0] != nil {
arg0 = args[0].(*actions.RunnerScaleSetStatistic)
}
run(
arg0,
)
})
return _c
}
func (_c *MockPublisher_PublishStatistics_Call) Return() *MockPublisher_PublishStatistics_Call {
_c.Call.Return()
return _c
}
func (_c *MockPublisher_PublishStatistics_Call) RunAndReturn(run func(stats *actions.RunnerScaleSetStatistic)) *MockPublisher_PublishStatistics_Call {
_c.Run(run)
return _c
}
+275 -48
View File
@@ -1,59 +1,16 @@
// Code generated by mockery v2.36.1. DO NOT EDIT.
// Code generated by mockery; DO NOT EDIT.
// github.com/vektra/mockery
// template: testify
package mocks
import (
context "context"
actions "github.com/actions/actions-runner-controller/github/actions"
"context"
"github.com/actions/actions-runner-controller/github/actions"
mock "github.com/stretchr/testify/mock"
)
// ServerPublisher is an autogenerated mock type for the ServerPublisher type
type ServerPublisher struct {
mock.Mock
}
// ListenAndServe provides a mock function with given fields: ctx
func (_m *ServerPublisher) ListenAndServe(ctx context.Context) error {
ret := _m.Called(ctx)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context) error); ok {
r0 = rf(ctx)
} else {
r0 = ret.Error(0)
}
return r0
}
// PublishDesiredRunners provides a mock function with given fields: count
func (_m *ServerPublisher) PublishDesiredRunners(count int) {
_m.Called(count)
}
// PublishJobCompleted provides a mock function with given fields: msg
func (_m *ServerPublisher) PublishJobCompleted(msg *actions.JobCompleted) {
_m.Called(msg)
}
// PublishJobStarted provides a mock function with given fields: msg
func (_m *ServerPublisher) PublishJobStarted(msg *actions.JobStarted) {
_m.Called(msg)
}
// PublishStatic provides a mock function with given fields: min, max
func (_m *ServerPublisher) PublishStatic(min int, max int) {
_m.Called(min, max)
}
// PublishStatistics provides a mock function with given fields: stats
func (_m *ServerPublisher) PublishStatistics(stats *actions.RunnerScaleSetStatistic) {
_m.Called(stats)
}
// NewServerPublisher creates a new instance of ServerPublisher. 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 NewServerPublisher(t interface {
@@ -67,3 +24,273 @@ func NewServerPublisher(t interface {
return mock
}
// ServerPublisher is an autogenerated mock type for the ServerExporter type
type ServerPublisher struct {
mock.Mock
}
type ServerPublisher_Expecter struct {
mock *mock.Mock
}
func (_m *ServerPublisher) EXPECT() *ServerPublisher_Expecter {
return &ServerPublisher_Expecter{mock: &_m.Mock}
}
// ListenAndServe provides a mock function for the type ServerPublisher
func (_mock *ServerPublisher) ListenAndServe(ctx context.Context) error {
ret := _mock.Called(ctx)
if len(ret) == 0 {
panic("no return value specified for ListenAndServe")
}
var r0 error
if returnFunc, ok := ret.Get(0).(func(context.Context) error); ok {
r0 = returnFunc(ctx)
} else {
r0 = ret.Error(0)
}
return r0
}
// ServerPublisher_ListenAndServe_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListenAndServe'
type ServerPublisher_ListenAndServe_Call struct {
*mock.Call
}
// ListenAndServe is a helper method to define mock.On call
// - ctx context.Context
func (_e *ServerPublisher_Expecter) ListenAndServe(ctx interface{}) *ServerPublisher_ListenAndServe_Call {
return &ServerPublisher_ListenAndServe_Call{Call: _e.mock.On("ListenAndServe", ctx)}
}
func (_c *ServerPublisher_ListenAndServe_Call) Run(run func(ctx context.Context)) *ServerPublisher_ListenAndServe_Call {
_c.Call.Run(func(args mock.Arguments) {
var arg0 context.Context
if args[0] != nil {
arg0 = args[0].(context.Context)
}
run(
arg0,
)
})
return _c
}
func (_c *ServerPublisher_ListenAndServe_Call) Return(err error) *ServerPublisher_ListenAndServe_Call {
_c.Call.Return(err)
return _c
}
func (_c *ServerPublisher_ListenAndServe_Call) RunAndReturn(run func(ctx context.Context) error) *ServerPublisher_ListenAndServe_Call {
_c.Call.Return(run)
return _c
}
// PublishDesiredRunners provides a mock function for the type ServerPublisher
func (_mock *ServerPublisher) PublishDesiredRunners(count int) {
_mock.Called(count)
return
}
// ServerPublisher_PublishDesiredRunners_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishDesiredRunners'
type ServerPublisher_PublishDesiredRunners_Call struct {
*mock.Call
}
// PublishDesiredRunners is a helper method to define mock.On call
// - count int
func (_e *ServerPublisher_Expecter) PublishDesiredRunners(count interface{}) *ServerPublisher_PublishDesiredRunners_Call {
return &ServerPublisher_PublishDesiredRunners_Call{Call: _e.mock.On("PublishDesiredRunners", count)}
}
func (_c *ServerPublisher_PublishDesiredRunners_Call) Run(run func(count int)) *ServerPublisher_PublishDesiredRunners_Call {
_c.Call.Run(func(args mock.Arguments) {
var arg0 int
if args[0] != nil {
arg0 = args[0].(int)
}
run(
arg0,
)
})
return _c
}
func (_c *ServerPublisher_PublishDesiredRunners_Call) Return() *ServerPublisher_PublishDesiredRunners_Call {
_c.Call.Return()
return _c
}
func (_c *ServerPublisher_PublishDesiredRunners_Call) RunAndReturn(run func(count int)) *ServerPublisher_PublishDesiredRunners_Call {
_c.Run(run)
return _c
}
// PublishJobCompleted provides a mock function for the type ServerPublisher
func (_mock *ServerPublisher) PublishJobCompleted(msg *actions.JobCompleted) {
_mock.Called(msg)
return
}
// ServerPublisher_PublishJobCompleted_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishJobCompleted'
type ServerPublisher_PublishJobCompleted_Call struct {
*mock.Call
}
// PublishJobCompleted is a helper method to define mock.On call
// - msg *actions.JobCompleted
func (_e *ServerPublisher_Expecter) PublishJobCompleted(msg interface{}) *ServerPublisher_PublishJobCompleted_Call {
return &ServerPublisher_PublishJobCompleted_Call{Call: _e.mock.On("PublishJobCompleted", msg)}
}
func (_c *ServerPublisher_PublishJobCompleted_Call) Run(run func(msg *actions.JobCompleted)) *ServerPublisher_PublishJobCompleted_Call {
_c.Call.Run(func(args mock.Arguments) {
var arg0 *actions.JobCompleted
if args[0] != nil {
arg0 = args[0].(*actions.JobCompleted)
}
run(
arg0,
)
})
return _c
}
func (_c *ServerPublisher_PublishJobCompleted_Call) Return() *ServerPublisher_PublishJobCompleted_Call {
_c.Call.Return()
return _c
}
func (_c *ServerPublisher_PublishJobCompleted_Call) RunAndReturn(run func(msg *actions.JobCompleted)) *ServerPublisher_PublishJobCompleted_Call {
_c.Run(run)
return _c
}
// PublishJobStarted provides a mock function for the type ServerPublisher
func (_mock *ServerPublisher) PublishJobStarted(msg *actions.JobStarted) {
_mock.Called(msg)
return
}
// ServerPublisher_PublishJobStarted_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishJobStarted'
type ServerPublisher_PublishJobStarted_Call struct {
*mock.Call
}
// PublishJobStarted is a helper method to define mock.On call
// - msg *actions.JobStarted
func (_e *ServerPublisher_Expecter) PublishJobStarted(msg interface{}) *ServerPublisher_PublishJobStarted_Call {
return &ServerPublisher_PublishJobStarted_Call{Call: _e.mock.On("PublishJobStarted", msg)}
}
func (_c *ServerPublisher_PublishJobStarted_Call) Run(run func(msg *actions.JobStarted)) *ServerPublisher_PublishJobStarted_Call {
_c.Call.Run(func(args mock.Arguments) {
var arg0 *actions.JobStarted
if args[0] != nil {
arg0 = args[0].(*actions.JobStarted)
}
run(
arg0,
)
})
return _c
}
func (_c *ServerPublisher_PublishJobStarted_Call) Return() *ServerPublisher_PublishJobStarted_Call {
_c.Call.Return()
return _c
}
func (_c *ServerPublisher_PublishJobStarted_Call) RunAndReturn(run func(msg *actions.JobStarted)) *ServerPublisher_PublishJobStarted_Call {
_c.Run(run)
return _c
}
// PublishStatic provides a mock function for the type ServerPublisher
func (_mock *ServerPublisher) PublishStatic(min int, max int) {
_mock.Called(min, max)
return
}
// ServerPublisher_PublishStatic_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishStatic'
type ServerPublisher_PublishStatic_Call struct {
*mock.Call
}
// PublishStatic is a helper method to define mock.On call
// - min int
// - max int
func (_e *ServerPublisher_Expecter) PublishStatic(min interface{}, max interface{}) *ServerPublisher_PublishStatic_Call {
return &ServerPublisher_PublishStatic_Call{Call: _e.mock.On("PublishStatic", min, max)}
}
func (_c *ServerPublisher_PublishStatic_Call) Run(run func(min int, max int)) *ServerPublisher_PublishStatic_Call {
_c.Call.Run(func(args mock.Arguments) {
var arg0 int
if args[0] != nil {
arg0 = args[0].(int)
}
var arg1 int
if args[1] != nil {
arg1 = args[1].(int)
}
run(
arg0,
arg1,
)
})
return _c
}
func (_c *ServerPublisher_PublishStatic_Call) Return() *ServerPublisher_PublishStatic_Call {
_c.Call.Return()
return _c
}
func (_c *ServerPublisher_PublishStatic_Call) RunAndReturn(run func(min int, max int)) *ServerPublisher_PublishStatic_Call {
_c.Run(run)
return _c
}
// PublishStatistics provides a mock function for the type ServerPublisher
func (_mock *ServerPublisher) PublishStatistics(stats *actions.RunnerScaleSetStatistic) {
_mock.Called(stats)
return
}
// ServerPublisher_PublishStatistics_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishStatistics'
type ServerPublisher_PublishStatistics_Call struct {
*mock.Call
}
// PublishStatistics is a helper method to define mock.On call
// - stats *actions.RunnerScaleSetStatistic
func (_e *ServerPublisher_Expecter) PublishStatistics(stats interface{}) *ServerPublisher_PublishStatistics_Call {
return &ServerPublisher_PublishStatistics_Call{Call: _e.mock.On("PublishStatistics", stats)}
}
func (_c *ServerPublisher_PublishStatistics_Call) Run(run func(stats *actions.RunnerScaleSetStatistic)) *ServerPublisher_PublishStatistics_Call {
_c.Call.Run(func(args mock.Arguments) {
var arg0 *actions.RunnerScaleSetStatistic
if args[0] != nil {
arg0 = args[0].(*actions.RunnerScaleSetStatistic)
}
run(
arg0,
)
})
return _c
}
func (_c *ServerPublisher_PublishStatistics_Call) Return() *ServerPublisher_PublishStatistics_Call {
_c.Call.Return()
return _c
}
func (_c *ServerPublisher_PublishStatistics_Call) RunAndReturn(run func(stats *actions.RunnerScaleSetStatistic)) *ServerPublisher_PublishStatistics_Call {
_c.Run(run)
return _c
}