From bfa86327cea433ea74012992c3f349816e2eb907 Mon Sep 17 00:00:00 2001 From: Mathieu Fenniak Date: Sun, 7 Sep 2025 13:52:31 -0600 Subject: [PATCH] test: add mocks for RunnerInterface & Poller --- internal/app/poll/mocks/Poller.go | 52 +++++++++++++++++++++++ internal/app/poll/poller.go | 1 + internal/app/run/mocks/RunnerInterface.go | 49 +++++++++++++++++++++ internal/app/run/runner.go | 1 + internal/pkg/client/mocks/Client.go | 2 +- 5 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 internal/app/poll/mocks/Poller.go create mode 100644 internal/app/run/mocks/RunnerInterface.go diff --git a/internal/app/poll/mocks/Poller.go b/internal/app/poll/mocks/Poller.go new file mode 100644 index 00000000..9d2b1e4d --- /dev/null +++ b/internal/app/poll/mocks/Poller.go @@ -0,0 +1,52 @@ +// Code generated by mockery v2.53.5. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" +) + +// Poller is an autogenerated mock type for the Poller type +type Poller struct { + mock.Mock +} + +// Poll provides a mock function with no fields +func (_m *Poller) Poll() { + _m.Called() +} + +// Shutdown provides a mock function with given fields: ctx +func (_m *Poller) Shutdown(ctx context.Context) error { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Shutdown") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(ctx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// NewPoller creates a new instance of Poller. 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 NewPoller(t interface { + mock.TestingT + Cleanup(func()) +}, +) *Poller { + mock := &Poller{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/app/poll/poller.go b/internal/app/poll/poller.go index 452f356d..7b954cb7 100644 --- a/internal/app/poll/poller.go +++ b/internal/app/poll/poller.go @@ -22,6 +22,7 @@ import ( const PollerID = "PollerID" +//go:generate mockery --name Poller type Poller interface { Poll() Shutdown(ctx context.Context) error diff --git a/internal/app/run/mocks/RunnerInterface.go b/internal/app/run/mocks/RunnerInterface.go new file mode 100644 index 00000000..16dbfecb --- /dev/null +++ b/internal/app/run/mocks/RunnerInterface.go @@ -0,0 +1,49 @@ +// Code generated by mockery v2.53.5. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + + runnerv1 "code.forgejo.org/forgejo/actions-proto/runner/v1" +) + +// RunnerInterface is an autogenerated mock type for the RunnerInterface type +type RunnerInterface struct { + mock.Mock +} + +// Run provides a mock function with given fields: ctx, task +func (_m *RunnerInterface) Run(ctx context.Context, task *runnerv1.Task) error { + ret := _m.Called(ctx, task) + + if len(ret) == 0 { + panic("no return value specified for Run") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *runnerv1.Task) error); ok { + r0 = rf(ctx, task) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// NewRunnerInterface creates a new instance of RunnerInterface. 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 NewRunnerInterface(t interface { + mock.TestingT + Cleanup(func()) +}, +) *RunnerInterface { + mock := &RunnerInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go index 98e1c524..3f2b0127 100644 --- a/internal/app/run/runner.go +++ b/internal/app/run/runner.go @@ -48,6 +48,7 @@ type Runner struct { runningTasks sync.Map } +//go:generate mockery --name RunnerInterface type RunnerInterface interface { Run(ctx context.Context, task *runnerv1.Task) error } diff --git a/internal/pkg/client/mocks/Client.go b/internal/pkg/client/mocks/Client.go index f2ea5fe2..3b3ab6cb 100644 --- a/internal/pkg/client/mocks/Client.go +++ b/internal/pkg/client/mocks/Client.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.53.4. DO NOT EDIT. +// Code generated by mockery v2.53.5. DO NOT EDIT. package mocks